工作生活与爱好

工作中的记录; 生活中的记忆; 业余爱好的记载。

2007-01-15

 

ABAP:Message的使用

在SAP系统中,Message是提供给用户程序运行信息的一个重要手段。以下是SAP系统中的帮助。

MESSAGE

Variants:

1. MESSAGE xnnn.

2. MESSAGE ID id TYPE mtype NUMBER n.

3. MESSAGE xnnn(mid).

4. MESSAGE msg TYPE mtype.

Effect

Sends a message. Messages are stored in the table T100, are processed using transaction SE91 and can be created by forward navigation.

The ABAP runtime environment handles messages according to the type declared in the MESSAGE statement and the context in which the message was sent. The following message types exist:

A - Abend
: Transaction terminated
E - Error
: Error message
I - Info
: Information
S - Status
: Status message
W - Warning
: Correction possible
X - Exit
: Transaction terminated with short dump

Messages are mainly used to handle user input on screens. The following table shows the behavior of each message type in each context. An explanation of the numbers used is included at the end of the table:

A E I S W X
--------------------------------------------------------------
PAI Module 1 2 3 4 5 6
PAI Module for POH 1 7 3 4 7

6
PAI Module for POV 1 7 3 4 7

6
--------------------------------------------------------------
AT SELECTION-SCREEN ... 1 8 3 4 9 6
AT SELECTION-SCREEN for POH 1 7 3 4 7 6
AT SELECTION-SCREEN for POV 1 7 3 4 7 6
AT SELECTION-SCREEN ON EXIT 1 7 3 4 7 6
--------------------------------------------------------------
AT LINE-SELECTION 1 10 3 4 10 6
AT PFn 1 10 3 4 10 6
AT USER-COMMAND 1 10 3 4 10 6
--------------------------------------------------------------
INITIALIZATION 1 11 3 4 11 6
START-OF-SELECTION 1 11 3 4 11 6
GET 1 11 3 4 11 6
END-OF-SELECTION 1 11 3 4 11 6
--------------------------------------------------------------
TOP-OF-PAGE 1 11 3 4 11 6
END-OF-PAGE 1 11 3 4 11 6
TOP-OF-PAGE DURING ... 1 10 3 4 10 6
--------------------------------------------------------------
LOAD-OF-PROGRAM 1 1 4 4 4 6
--------------------------------------------------------------
PBO Module 1 1 4 4 4 6
AT SELECTION-SCREEN OUTPUT 1 1 4 4 4 6
--------------------------------------------------------------
Procedure: see

Messages
--------------------------------------------------------------

  1. The message appears in a dialog box and the program terminates. When the user has confirmed the message, control returns to the next- highest area. All the internal sessions are deleted from the stack.

  2. The message appears in the status line. Then PAI terminates and the system returns to the current screen. All the screen fields combined using FIELD or CHAIN are now ready for input. The user must enter new values. The system triggers the PAI event again, with the new values.

  3. The message appears in a dialog box. Once the user has confirmed the message, the program continues immediately after the MESSAGE statement.

  4. The message appears in the status line of the next screen. The program continues immediately after the message statement.

  5. The message appears in the status line. Then the system continues as in 2, except that the user can quit the message using ENTER without having to enter new values. The system continues handling the PAI event from immediately after the message statement.

  6. No message is displayed and a runtime error, MESSAGE_TYPE_X, is triggered. The short dump text contains the message identification.

  7. The program terminates with a runtime error DYNPRO_MSG_IN_HELP. While F1 and F4 are processed, the system cannot send error messages or warnings.

  8. The message appears in the status line. Then the system stops selection screen processing and returns to the selection screen itself. The screen fields specified in the additions to the AT SELECTION-SCREEN statement are now ready for input. The user must enter new values. The system then starts processing the selection screen again with the new values.

  9. The message appears in the status line. Then the system continues as in 8, except the the user can quit the message using ENTER, without having to enter new values. The system continues handling the PAI event from immediately after the message statement.

  10. The message appears in the status line and the processing block terminates. The list level is displayed as before.

  11. The message appears in the status line and the processing block terminates. The system then returns to the program call.

  12. For a demonstration of messages in different contexts, see Example Programs for Messages.


Variant 1

MESSAGE xnnn.


Extras:

1. ... WITH f1 ... f4

2. ... RAISING exception

3. ... INTO f

4. ... DISPLAY LIKE mtype

Effect

Outputs the message nnn from the message class i with the type x. You must specify the message class i using the MESSAGE-ID addition to the REPORT statement, PROGRAM, or another introductory program statement.

Example

MESSAGE I001.

Addition 1

... WITH f1 ... f4

Effect

Inserts the contents of a field fi in the message instead of in the placeholder &i. If unnumbered variables (&) are used in a message text, these are replaced consecutively by the fields f1 to f4.
To aid compilation, only numbered variables (&1 to &4) are to be used in future if several fields are involved.
If a "&" is supposed to appear in the message at runtime, you must enter &&.
In the long text of a message, the symbol &Vi& is replaced by the field contents of fi.
After WITH, you can specify 1 to 4 fields.

Note

You can output up to 50 characters per field. If the field contains more characters, these are ignored.

Example

MESSAGE E0004 WITH 'Hugo'.

Note

When executing the statement, the contents of the fields f1 to f4 are assigned to the system fields SY-MSGV1, SY-MSGV2, SY-MSGV3 and SY-MSGV4.

Addition 2

... RAISING exception

Effect

Only possible within a function module or a method (see FUNCTION, METHOD):
Triggers the exception exception.
If the program calling the function module or method handles the exception itself, control returns immediately to that program (see CALL FUNCTION and CALL METHOD). Only then are the current values passed from the procedure to the EXPORTING-, CHANGING- (und RETURNING) parameters of the function module or method, if they are specified as pass-by- reference. However, the calling program can refer to the system field values (see above).

If the calling program does not handle the exception itself, the message is output (see RAISE).
You cannot use this addition in conjunction with the ... INTO cf addition.

Note

If, during a Remote Function Call, an error occurs in the target system, details of the error message are passed back to the calling system in the following system fields: SY-MSGNO, SY-MSGID, SY-MSGTY, SY-MSGV1, SY-MSGV2, SY-MSGV3, and SY-MSGV4. These fields are initialized before every RFC. If a short dump or a type X message occurs, the short text of the dump is transferred to the caller, and the contents of SY-MSGID, SY-MSGTY, SY-MSGNO, and SY-MSGV1 assigned by the system.

In RFC-enabled function modules, no ABAP statements are allowed that would end the RFC connection (for example, either LEAVE or SUBMIT without the AND RETURN addition).

Example
MESSAGE E001 RAISING NOT_FOUND.

Addition 3

... INTO f

Effect

Instead of displaying the message, the system places the message text in the field f. The message type is not evaluated.

You cannot use this addition in conjunction with the ...RAISING exception or the DISPLAY LIKE mtype addition. The system sets the following system variables: SY-MSGID (message class), SY-MSGTY (message type), SY-MSGNO (message number) and SY-MSGV1, SY-MSGV2, SY-MSGV3, SY-MSGV4 (parameters).

Example

DATA msgtext(72).

...

MESSAGE E004 WITH 'Hugo' INTO msgtext.

Addition 4

... DISPLAY LIKE mtype

Effect

The message display uses the icon of the message type mtype but the message is handled according to its actual type.

Note

This addition cannot be used in conjunction with the addition ... INTO.

Example

MESSAGE I004 DISPLAY LIKE 'E'.

Variant 2

MESSAGE ID id TYPE mtype NUMBER n.


Extras:

1. ... WITH f1 ... f4

2. ... RAISING exception

3. ... INTO f

4. ... DISPLAY LIKE mtype

Effect

The message components are set dynamically:

ID
Message class
TYPE
Message type
NUMBER
Message number

The addition MESSAGE-ID of the introductory program statement is not required or is overridden.

Addition 1

... WITH f1 ... f4

Addition 2

... RAISING exception

Addition 3

... INTO f

Addition 4

... DISPLAY LIKE mtype

Effect

As in variant 1.

Example

MESSAGE ID 'SU' TYPE 'E' NUMBER '004' WITH 'Hugo'.

Outputs the message with the number 004 and MESSAGE-ID SU (see above) as an E (Error) message and replaces the first variable (&) with 'Hugo'.

Example

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

Constructs the message dynamically from the contents of the system fields SY-MSGID, SY-MSGTY, SY-MSGNR , SY-MSGV1 ,SY-MSGV2,SY-MSGV3,and SY-MSGV4. These may, for example, be set by an exception after CALL FUNCTION or CALL TRANSACTION ... USING.

Variant 3

MESSAGE xnnn(mid).


Extras:

1. ... WITH f1 ... f4

2. ... RAISING exception

3. ... INTO f

4. ... DISPLAY LIKE mtype

Effect

As in variant 1. The message class is determined by specifying mid. The addition MESSAGE-ID of the introductory program statement is not required or is overridden.

Addition 1

... WITH f1 ... f4

Addition 2

... RAISING exception

Addition 3

... INTO f

Addition 4

... DISPLAY LIKE mtype

Effect

As in variant 1.

Example

MESSAGE X004(SU) WITH 'Hugo'.

Variant 4

MESSAGE msg TYPE mtype.


Extras:

1. ... RAISING exception
2. ... DISPLAY LIKE mtype

Effect

With this variant, the message can be passed directly in the form of a character-like field. The message type is specified using the required TYPE addition.

Addition 1

... RAISING exception

Addition 2

... DISPLAY LIKE mtype

Effect

As in variant 1.

Example

MESSAGE 'File not found.' TYPE 'E'.

The text 'File not found.' is output as the error message.

Exceptions

Non-Catchable Exceptions

Additional help

Messages


使用心得:
Message 显示给用户的字符串长度有限制,将很长的显示信息分配给Message的多个参数来显示出来,如果采用字符串连接后给第一个参数显示可能出现丢失显示信息。

 

ABAP:向自建表写入数据时,需要注意的问题

在某个创建的自建表中,某个字段的数据元素为SAKNR(总账科目号),类型为CHAR(10),但是导入的数据的长度只有CHAR(6),比数据库字段要短,如果直接导入,不进行任何处理,会出现什么潜在的问题呢?

首先导入数据肯定不会出现错误,但是在使用中,我需要从表SKAT中查找总账科目的描述,但是无论如何都不能通过程序查找到描述信息,直接从表SKAT中却能找到相应总账科目的描述,这是为什么呢?

通过分析,发现SKAT中保存的科目长度全部为10位,不足的长度,前面都用“0”补齐,而我导入到自建表中的科目中数据却只有6位长度,后面用空格补齐,那么原因就找到了,我们在导入数据时,有些字段不能直接写入数据库,需要进行一定的处理。

那么如何进行处理呢,不能简单的想当然,在任何不足的长度前都用0补齐,对于不同的数据元素和域,它们处理的方式不一致,需要使用SAP系统提供的系统函数来进行处理。

在检查表SKAT的SAKNR字段的数据元素SAKNR,到域SAKNR,在Definition标签,Output Characteristics属性中,有一个Convers.routine为ALPHA,继续察看,可以看到系统提供的几个Function,如下

CONVERSION_EXIT_ALPHA_INPUT 对话退出ALPHA,外部->内部
CONVERSION_EXIT_ALPHA_OUTPUT 对话退出ALPHA,内部->外部

函数调用非常简单,如下

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = IG_UPLOAD-HKONT_NIS
IMPORTING
OUTPUT = WA_ZDFLNIS-HKONT_NIS
.
一般来说,需要进行补齐处理的有:科目,物料编码等各种编码,各种凭证编号,如物料凭证等。


 

ABAP:SMARTFORMS 之一:数据从程序中传送到Form中

SMARTFORMS和SAPSCRIPT FORM都是SAP中设计打印报表的工具,但是SAPScript需要手工一条一条的根据坐标和长、高画表格线,这样极为不方便,而SmartForms 有一个GUI来直接画界面,因此,总的来说,使用SmartForms来设计报表打印要简单很多。而且SAPSrcipt在不同的Client中需要传 输,测试起来也不方便。传输SAPScript的事务代码为:SCC1,对应程序名为 RSTXSCRP

事务代码:SMARTFORMS

在SAP的ABAP编程中,一般开发过程都是在Report程 序中取出所有需要的数据,将数据进行相应的处理以后保存到输出内表中,再打印内表中的数据,但是SmartForms是一个独立的外部Function Module,对于程序内部定义的内表数据不能直接传递,需要定义外部的数据结构Structure或者使用标准的表结构,如果程序变更,需要传递的数据 发生变化,那么该Sturcture也需要修改,这是SmartForms中不方便的地方。

当然我们也可以在SmartForms内部写取数据的逻辑,但是在SmartForms中编程总不是很方便,而且有时我们的数据需要首先以List 或者ALV List的方式显示,然后再打印,所以在smartforms中书写取数据逻辑只能对一些要求非常简单的场合适用。

我们决定还是在Report程序中进行取数逻辑,然后想办法将数据传递到SMARTFORMS中。我们知道在SAP中可以将一个对象Export到 内存或者数据库中,我们就可以根据一个类似于句柄的字符串再次取出该数据,传送一个字符串到SmartForms中是没有任何问题的,所以我们只需要 Export内表到内存或者数据库中,将句柄传递到SmartForms中,在SmartForms中首先定义完全相同类型的内表,再将数据Impor到 内表中即可完全恢复数据,这样就完成的数据的传递工作。

以下是Import和Export的Include程序:

*&---------------------------------------------------------------------*
*& 包括 ZINC_SF_HELPER *
*&---------------------------------------------------------------------*

TYPES buffer_id(
80) TYPE c.
DATA wa_indx TYPE indx.

DEFINE savebuffer.
perform save_to_buffer using
&1 &2.
END-OF-DEFINITION.

DEFINE clearbuffer.
perform clear_buffer using
&1.
END-OF-DEFINITION.
*&--------------------------------------------------------------------*
*& Form Get_Unique_Id
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->ID text
*---------------------------------------------------------------------*
*FORM get_unique_id USING typeid TYPE c CHANGING id TYPE c.
* DATA: m_buff(32) TYPE c.
* CALL FUNCTION 'TH_GET_SESSION_ID'
* IMPORTING
* session_id = m_buff
** ID_LEN =
* .
* CONCATENATE sy-repid '_' m_buff typeid INTO id.
*ENDFORM. "Get_Unique_Id


*&--------------------------------------------------------------------*
*& Form Save_To_Buffer
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->T text
* -->BUFF_ID text
*---------------------------------------------------------------------*
FORM save_to_buffer USING t TYPE table typeid TYPE c .
wa_indx
-aedat = sy-datum.
wa_indx
-usera = sy-uname.
wa_indx
-pgmid = sy-repid.
* PERFORM get_unique_id USING buff_id CHANGING buff_id.
EXPORT t
TO DATABASE indx(hk) ID typeid from wa_indx.
ENDFORM.
"Save_To_Buffer

*&--------------------------------------------------------------------*
*& Form Clear_Buffer
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->BUFF_ID text
*---------------------------------------------------------------------*
FORM clear_buffer USING buffid TYPE c.
DELETE FROM DATABASE indx(hk) ID buffid.
ENDFORM.
"Clear_Buffer

form Restor_buffer using typeid type c changing t type table.
import t from database indx(hk) id typeid.
endform.


下面是调用示例:

form frm_print_data .

DATA: headername(
18) TYPE c.
DATA: itemsname(
18) TYPE c.
" 在句柄中加上服务器当前时间作为句柄名称,防止多人同时使用该程序,导致句柄名称相同
CONCATENATE
'ZSPMMF1002HD' SY-UZEIT INTO headername .
CONCATENATE 'ZSPMMF1002IT' SY-UZEIT INTO itemsname.

savebuffer ig_output_h[] headername. "ig_output_h是保存输出表单表头数据的内表
savebuffer ig_output_d[] itemsname. "ig_output_d是保存输出数据明细的内表,与表头数据有关联字段

DATA: wl_fmname TYPE rs38l_fnam.
* 通过SmartForms的名称取得编译以后的对应的Function Module的名称
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = 'ZSPMMF1007X' "SmartForms的名称
* VARIANT = ' '
* DIRECT_CALL = ' '
IMPORTING
fm_name = wl_fmname
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

CALL FUNCTION wl_fmname
EXPORTING
* ARCHIVE_INDEX =
* ARCHIVE_INDEX_TAB =
* ARCHIVE_PARAMETERS =
* CONTROL_PARAMETERS =
* MAIL_APPL_OBJ =
* MAIL_RECIPIENT =
* MAIL_SENDER =
* OUTPUT_OPTIONS =
* USER_SETTINGS = 'X'
ptr_header = headername
ptr_items
= itemsname
* IMPORTING
* DOCUMENT_OUTPUT_INFO =
* JOB_OUTPUT_INFO =
* JOB_OUTPUT_OPTIONS =
EXCEPTIONS
FORMATTING_ERROR
= 1
INTERNAL_ERROR
= 2
SEND_ERROR
= 3
USER_CANCELED
= 4
OTHERS
= 5
.
IF sy-subrc <> 0.
MESSAGE ID SY
-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

clearbuffer headername. "调用完毕以后,删除数据
clearbuffer itemsname.

endform.
" frm_print_data

将数据Export到内存可以取得较好的效率,但是一般SAP的应用服务器都会使用群集,因此我们Export数据到数据库中会保险一些。

在系列文章之二,说明SmartForms的设计。


Archives

1990年1月15日   2007年1月14日   2007年1月15日   2007年1月16日   2007年1月17日   2007年1月18日   2007年1月19日   2007年1月20日   2007年1月22日   2007年1月23日   2007年1月24日   2007年1月25日   2007年1月26日   2007年1月27日   2007年1月29日   2007年1月30日   2007年1月31日   2007年2月1日   2007年2月2日   2007年2月3日   2007年3月13日   2007年5月15日   2007年5月16日   2007年6月2日  

This page is powered by Blogger. Isn't yours?