MESSAGE - message_options

Syntax

... { {[DISPLAY LIKE dtype] [RAISING exception]}
    | [INTO text] }

    [WITH dobj1 ... dobj4].

Extras:

1. ... DISPLAY LIKE dtype

2. ... RAISING exception

3. ... INTO text

4. ... WITH dobj1 ... dobj4

Effect

These additions change the type of display, raise a non-class-based exception in function modules or methods, assign the text of the message to a data object and replace the placeholders in short- and long-texts of messages.

Addition 1

... DISPLAY LIKE dtype

Effect

When you use this addition, the icon of the message type specified in dtype is displayed instead of the associated icon. A character-type data object is expected for dtype. This data object has to contain one of the values "A", "E", "I", "S" or "W" in upper-case letters.

The message short text is still displayed as a dialog window for messages that are displayed this way by default. Messages with the type "E" or "W" (except those for PBO and LOAD-OF-PROGRAM) are displayed as a dialog window if dtype contains "A" or "I". Messages with the type "S" are always displayed in the status bar, independently of dtype. The latter also applies to messages of the type "I" for PBO and LOAD-OF-PROGRAM. Messages of the type "X" always cause a runtime error.

Note

The usage of this addition does not influence the behavior determined by the message type, but only the type of display.

Addition 2

... RAISING exception

Effect

With this addition, the statement MESSAGE raises either a non-class-based exception exception, or sends a message. The addition only makes sense during the processing of methods and function modules, in which the non-class-based exception exception is defined. Furthermore, the addition must not be used in the same processing block as the statement RAISE EXCEPTION for raising class-based exceptions.

If the MESSAGE-statement is processed with the addition RAISING during processing of a method or a function module whose caller assigns a return value to the exception exception with the addition EXCEPTIONS of the statement CALL, it has the same effect as the statement RAISE. If no return value is assigned to the exception exception , then the addition RAISING is ignored and the message is processed according to its message type.

The system fields of the statement MESSAGE are populated in both cases and are available in the calling program after handling an exception raised with MESSAGE ...RAISING. This is especially true, when a function module was called through Remote Function Call (RFC).

Note

You can assign a return value to messages that are sent in function modules without the addition RAISING via the predefined exception error_message.

Example

At the first call of the method, an information message is sent, at the second call an exception is raised instead and is handled after the call via analysis of sy-subrc.

     CLASS c1 DEFINITION.
       PUBLIC SECTION.
         CLASS-METHODS m1 EXCEPTIONS exc1.
     ENDCLASS.
     CLASS c1 IMPLEMENTATION.
       METHOD m1.
         MESSAGE 'Message in a Method' TYPE 'I' RAISING exc1.
       ENDMETHOD.
     ENDCLASS.
     ...
       c1=>m1( ).
       c1=>m1( EXCEPTIONS exc1 = 4 ).
     IF sy-subrc = 4.
       ...
     ENDIF.


Addition 3

... INTO text

Effect

With this addition, you assign the short text of the message to the variable text. The message type does not matter. The program flow is not interrupted and there is no message processing taking place. For text, a character-type data object is expected.

The addition INTO cannot be specified at the output of a user-defined text.

Example

The short text of a message sent in a function module is stored in the data object mtext when handling the exception error_message with help of the respective system fields.

      DATA mtext TYPE string.
      CALL FUNCTION ... EXCEPTIONS error_message = 4.
      IF sy-subrc = 4.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                INTO mtext
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.


Addition 4

... WITH dobj1 ... dobj4

Effect

This addition replaces the placeholders "&1" to "&4" and "&" of the short text resp. "&V1&" to "&V4&" of the long text of the message with the first 50 characters of the content of the data objects dobj1, ..., dobj4. You can specify up to four character-type data objects. The position of a data object determines which placeholder will be replaced. The content of the first data object replaces the placeholders "&1", the first placeholder "&" and "&V1&", the second replaces "&2", the second "&" and "&V2&" etc. Furthermore, the content of the data objects dobj1, ..., dobj4 is assigned in sequence to the system fields sy-msgv1 to sy-msgv4.

If you specify fewer data objects than placeholders, then surplus placeholders are not displayed in the short text and the associated system fields sy-msgv1 to sy-msgv4 are initialized. If a specified data object cannot be assigned to a placeholder, it is ignored.

The addition WITH cannot be specified at the output of an user-defined text, or, resp., an object reference oref.

Note

If a short text contains placeholders of both forms "&i" and "&", then the content of a data object can replace both placeholders. The data object at the position i not only replaces "&i" but also the i-th placeholder at position "&". We recommend that you use only one of the two forms for placeholders in a short text. If a short text is to be translated into other languages, only the numbered placeholder "&i" is used, as the structure of the sentence may change.

Example

If the short text of the specified message in the table T100 contains the value "& & & &" , then the text "This is not America" is put out as information message. If the short text was defined as "&4 &1 &3 &2" , then the output is "America This not is".

MESSAGE i010 WITH 'This' 'is' 'not' 'America'.