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.

  • You can specify a different message class in parentheses after the error number, for example MESSAGE I001(SU).
  • When executing the statement, the following system variables are set:* SY-MSGID (message class)
    * SY-MSGTY (message type)
    * SY-MSGNO (message number)

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

  • Cause: Message type unknown
    Runtime Error: MESSAGE_TYPE_UNKNOWN
  • Cause: Triggers termination with a short dump
    Runtime Error: MESSAGE_TYPE_X
Additional help

Messages

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

`postMessage` 方法可以用于在不同的窗口或 iframe 之间进行安全的跨域通信。它能够向指定窗口发送一个消息,并且在接收窗口中设置一个监听器来接收该消息。 `postMessage` 方法的基本语法如下: ```javascript otherWindow.postMessage(message, targetOrigin, [transfer]); ``` 其中,`otherWindow` 表示指定的窗口或 iframe,`message` 表示要发送的消息,`targetOrigin` 表示接收消息的窗口的源(如果不指定,表示不限制源),`transfer` 表示要传递的数据(可选)。 例如,下面的代码可以向指定的窗口发送一个消息: ```javascript var otherWindow = window.open('http://example.com/'); otherWindow.postMessage('Hello, world!', 'http://example.com'); ``` 在上面的代码中,我们首先使用 `window.open` 方法打开了一个新的窗口,并将其引用赋值给了 `otherWindow` 变量。然后,我们使用 `postMessage` 方法向该窗口发送了一个消息。由于指定的源为 `http://example.com`,因此只有来自 `http://example.com` 源的窗口才能接收到该消息。 接收窗口可以使用以下代码来监听消息: ```javascript window.addEventListener('message', function(event) { if (event.origin !== 'http://example.com') { return; } console.log(event.data); }); ``` 在上面的代码中,我们使用 `addEventListener` 方法向当前窗口添加了一个监听器,用于监听 `message` 事件。当接收到事件时,我们首先检查消息的源是否为 `http://example.com`,如果不是,则直接返回。否则,我们就可以使用 `event.data` 属性来获取消息内容,并进行相应的处理。 需要注意的是,`postMessage` 方法虽然可以进行跨域通信,但也存在一定的安全风险。因此,在使用时需要仔细考虑安全问题,并避免发生跨站点脚本(XSS)攻击等问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值