Message Types In ABAP

In total, ABAP has 6 types of messages.

TypeDescription
AAbend (abnormal end of task)Displays a message in a dialog pop-up window. The entire transaction is canceled after confirming the message.
EErrorDisplays an error message in the status line. After confirming the message, the current event block is aborted.
IInformationDisplays a message in a dialog pop-up window. After confirming the message, the report processing is resumed.
SSuccess / StatusDisplays a success message in the status line of the current report.
WWarningDisplays a warning message in the status line. After confirming the message, the report processing is resumed.
XExitTriggers a runtime error and creates a short dump.

DISPLAY LIKE Addition

As you can see from the previous table the message type can also influence the report execution after the message was confirmed. In case you want to take care of the error handling yourself or simply change the appearance of a message you can use the addition DISPLAY LIKE:

MESSAGE 'Message text to display' TYPE 'S' DISPLAY LIKE 'E'.

This example prints the message Message text to display in the status line with the red error icon. Since the type itself is S report execution continues normally.

Remember: The addition DISPLAY LIKE only changes the appearance, not the behavior of the message type.

Displaying Messages

Following some examples of how to output a message in ABAP.

MESSAGE 'Message text to display' TYPE 'I' DISPLAY LIKE 'E'.
MESSAGE 'Text.' TYPE 'I'.
 
MESSAGE 'Message text to display' TYPE 'S' DISPLAY LIKE 'E'.
MESSAGE 'Message text to display' TYPE 'S' DISPLAY LIKE 'W'.
MESSAGE 'Message text to display' TYPE 'S'.
 
MESSAGE i004(zmessageclass) TYPE 'I' WITH v1.
MESSAGE ID 'zmessageclass' TYPE 'I' NUMBER '004'.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 DISPLAY LIKE 'E'.

Saving Messages In A Variable

The below examples show how to create and store a message in a variable. This can be useful when working with system variables or a message class.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO DATA(message_str).

DATA(msg) = |{ sy-msgv1 } { sy-msgv2 } { sy-msgv3 } { sy-msgv4 }|.
WRITE: / msg.
 
DATA(msg) = ``.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO msg.
WRITE: / msg.