- Step1 : What is message class in SAP ABAP ?
- Step2 : Creating message class in SAP
- Step3 : Using message class in ABAP programs
Step1:What is message class in SAP ABAP ? medium Top^
Message Class is nothing but a container of messages, the main purpose of this message class is re-usability and readability. A message class can be reused in multiple programs and Function modules.The Message Class can be created in two ways.
- Direct way using T-code SE91.
- Through Program.
You know all the message texts under message classes are stored in T100 table, each message in message class has a number and value.
We can able to pass parameters to message class to raise parameters along with messages.
Syntax1 : Syntax1: MESSAGE <MESSAGE TYPE><MESSAGE NUMBER> (<MESSAGE CLASS NAME>). Syntax2 : Step1 : REPORT <REPORT NAME> MESSAGE-ID <MESSAGE CLASS NAME> ."add message is at the report header (1st line) Step2 : MESSAGE <MESSAGE TYPE><MESSAGE NUMBER> . "directly specify messages
The below is the syntax for raising messages with parameters.
MESSAGE <MESSAGE TYPE><MESSAGE NUMBER> WITH <PARAMETER> "Parameter must be defined in message class
By using message class we can raise following messages.
Message Type | Effect | Description |
---|---|---|
A |
Termination Message |
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 Message |
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 Message |
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. |
Step2:Creating message class in SAP Medium Top^
The message class can be created in two ways,
- Using SE91 (message maintenance ) t-code.
- Using SE38 program.
Creating message class using SE38 program.
REPORT <REPORT NAME> message-id <MESSAGE CLASS> . "Double click on message class click create
REPORT ZSAPN_MESSAGE_CLASS message-id ZSAPN_MESSAGE . "double click on ZSAPN_MESSAGE and click create
Creating message class using SE91.
Go to SE91 and give message class as ZSAPN_MESSAGE and click create.
Select messages tab, save it in a package (local object for test) and start adding messages.
Step3:Using message class in ABAP programs Medium Top^
There are two ways of using message classes in ABAP programs.
- Defining message class for a report.
- Using messages of a message class directly from message class.
For using message class by defining at report level, we have to define a message class by using below code (example).
REPORT ZSAPN_MESSAGE_CLASS message-id ZSAPN_MESSAGE . "report message-id message class
MESSAGE S001. "Raise message here S = Success message type and 001 = message no in ZSAPN_MESSAGE message class
The below is the code for using message class directly by using message number and message class name at message level.
MESSAGE s000(ZSAPN_MESSAGE). " here ZSAPN_MESSAGE is the message class name
Example(SE38 program)
REPORT ZSAPN_MESSAGE_CLASS . MESSAGE s000(ZSAPN_MESSAGE). OR REPORT ZSAPN_MESSAGE_CLASS MESSAGE-ID ZSAPN_MESSAGE. MESSAGE S000.
By using the above code we can raise success message like below.
Example with parameters
we use &
to specify parameters in message of a message class.
REPORT ZSAPN_MESSAGE_CLASS. MESSAGE S001(ZSAPN_MESSAGE) WITH '002' '003' . OR REPORT ZSAPN_MESSAGE_CLASS MESSAGE-ID ZSAPN_MESSAGE. MESSAGE S001 with '002' '003'.
By using the above code we can raise success message with parameters like below.
good explanation..keep on provide the other topics...change the tcode se93...using se91 we can create the message class.