To issue a message or warning or error or any kind of information in ABAP, either we have to hard code that message or maintain it in text symbols. What if the same message is required somewhere else like in any other program or class, again hard coding it or maintaining in text symbol would be recurring and inefficient procedure.
Instead of doing this, we can collect all the messages at one place and use it multiple times and at multiple places, that one place is nothing but a message class. Any message can be identified with a unique number assigned to it. To use a message from message class in any ABAP program or in any class, we only need to specify the message class, message number and message type.
Message Class is like a container which contains all messages in it. All the messages from different message classes are stored in database table T100.
Message Class Creation
A message class can be created in two ways:
- Through transaction code SE91.
- Syntax of calling these messages from message class in ABAP Programs:
MESSAGE <type of message><message number>(message class name) WITH <parameter>.
Example 1 : MESSAGE I000(ZTEST_CLASS). “Information Message
Example 2 : MESSAGE E0001(ZTEST_CLASS) WITH 0001. “Error Message
Note: In figure 2, message text at 001 position is having ‘&’. With this operator we can pass text/literals whatever we want to display. So, for example 2 message will get displayed as:
‘The value 0001 is invalid’.
- Through report.
Syntax : REPORT <Report Name> message-id <Message Class>
“Double click on message class name to create a message class.
A single message can be used multiple times at multiple places, we don’t need to hard code same message or maintain the same text symbols in different programs.