韦天飞韦天龙bl文:Message processing

来源:百度文库 编辑:九乡新闻网 时间:2024/04/29 01:15:34
  

Messages are single texts, stored in table T100, that you can maintain in Transaction SE91 or by forward navigation in the ABAP Workbench. T100 has the following structure:

  • Language key
  • Twenty-character message class
  • Message number
  • Message text (up to 72 characters)

Message classes assign messages to an application (maybe to a development class, for example), and the message numbers identify the individual messages within the message class. When you call a message in ABAP, you need to specify the message class and message number. The language key is supplied by the system according to the system language environment.

The MESSAGE Statement

The MESSAGE statement has three variants and several additions:

Using a Global Message Class

If the introductory statement of a program contains the addition

... MESSAGE-ID .

and a message class contained in table T100, you can use the MESSAGE statement as follows:

MESSAGE [WITH 1> ... 4>] [RAISING ].

where is the single-character message type and the three-digit message number. The system retrieves the corresponding message text from table T100 for the message class specified in the introductory statement, and displays it. The display depends on the message type and the context in which the message is sent.

Specifying the Message Statically

To specify the message class, message number, and message type statically, use the following form of the MESSAGE statement:

MESSAGE () [WITH ... ] [RAISING ].

This statement is like the first variant, but here you specify the message class within the statement. This specification overrides any message class that you may have specified at the beginning of the program.

Specifying the Message Dynamically

To specify the message class, message number, and message type dynamically, use the following form of the MESSAGE statement:

MESSAGE ID TYPE NUMBER [WITH ... ] [RAISING ].

where , , and are fields containing the message class, message number, and message type respectively. The system uses the field contents to read the appropriate message from table T100 and displays it according to the message context.

Filling Message Texts Dynamically

Message texts in table T100 can contain up to four ampersand characters as placeholders. You can replace these at runtime using the WITH addition in the MESSAGE statement:

MESSAGE ... WITH 1> ... 4>.

The contents of fields ... are then inserted sequentially into the message text in place of the placeholders.

Messages and Exceptions

Within function modules and methods, you can use the RAISING addition in the MESSAGE statement to trigger exception:

MESSAGE..... RAISING .

If the calling program does not handle the exception itself, the message is displayed, and the program continues processing in the manner appropriate to the message type and context. If the calling program handles the exception, the message is not displayed, but the exception is triggered. In this case, the message class, message number, message type, and any values of placeholders are placed in the system fields SY-MSGID, SY-MSGNO, SY-MSGTY, and SY-MSGV1 to SY-MSGV4 in the calling program.


Message processing depends on the message type specified in the MESSAGE statement, and the program context in which the statement occurs.

Message Types

A

Termination

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 menu.

E

Error

Depending on the program context, an error dialog appears or the program terminates.

I

Information

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

S

Status

The program continues normally after the MESSAGE statement, and the message is displayed in the status bar of the next screen.

W

Warning

Depending on the program context, an error dialog appears or the program terminates.

X

Exit

No message is displayed, and the program terminates with a short dump. Program terminations with a short dump normally only occur when a runtime error occurs. Message type X allows you to force a program termination. The short dump contains the message ID.

Contexts

Messages, especially those with type E or W, are processed according to the context in which they occur. The following sections summarize the most important context rules: