Вы находитесь на странице: 1из 6

Messages in ABAP

Messages are usually used to tell the user what is going on. The following types of messages are available in
ABAP.
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.

Error

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


terminates.

Status

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

Error

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

Warning

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


terminates.

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.

The syntax for issuing a message is as follows.


MESSAGE <message> TYPE <message type>.

We can issue a status message as follows. Status message will be displayed in the status bar. After the
message is displayed the program continues after the MESSAGE statement.
MESSAGE 'This is a status message' TYPE 'S'.

Information message will be displayed in a dialog box. Once the user has confirmed the message, the program
continues immediately after the MESSAGE statement.
MESSAGE 'This is an information message' TYPE 'I'.

Error message in report programs will be displayed in the status bar and when the user press enter, the program
terminates.
MESSAGE 'This is an error message' TYPE 'E'.

Warning message behaves similar to error message in report programs.


Exit Message No message is displayed, and the program terminates with a short dump. Short dumps can be
viewed in t-code ST22.
MESSAGE 'This produces short dump' TYPE 'X'.

Termination 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.
MESSAGE 'This is termination message' TYPE 'A'.

Instead of hardcode the message text in the program we can maintain the message text in text symbols. In order
to maintain text symbols use the menu path Goto->Text Elements->Text Symbols in ABAP editor.

In the text symbols screen we can maintain the messages with a 3 character identifier.

Then use the following message statement.


MESSAGE text-001 TYPE 'I'.

SAP Message Class


We know that we can use MESSAGE statement to issue a message in ABAP. What if we want to issue the same
message in more than one program? Do we need to hard code the same message text or maintain the same text
symbols in all the programs? The answer is NO. Instead of maintaining the same message text in all the
programs maintain the message in a Message class and use it in all the programs.
What is a Message Class?
Message Class is a like a container which holds a number of different messages. Each message in the message
class is identified with unique message number. So when you call a message in a ABAP program, you need to
specify the message class and message number.
How to create a Message Class?
First go to t-code SE91 i.e. Message Maintenance, enter the name of the message class and click on create
button.

Maintain the required message texts with message numbers. Then save the entries and assign it to proper
development class and transport request. Once the message class is saved we can use it in our ABAP programs.

Messages can be issued as follows.


MESSAGE s000(ztest).

Output

In the above code, the message number, message class and message type are specified in the MESSAGE
statement. We can also specify the message class in the REPORT statement as shown below, so that we can
skip the message class in the MESSAGE statements of the program.
REPORT zmessages

MESSAGE-ID ztest
.

MESSAGE s000.

We can also maintain placeholders for variables in messages.

In the above message & is the placeholder. At runtime the placeholders (&) will be replaced by the variable
values specified in the MESSAGE statement.
REPORT zmessages MESSAGE-ID ztest.

MESSAGE s001
WITH XYZ 1000
.

Output

The values XYZ and 1000 replaces the placeholders in the actual message.

Вам также может понравиться