Using Message Class in SAP ABAP

Author | Last Updated| | 27 Comments | F Share

Learn how to use message class in SAP ABAP programs, Function Modules and other ABAP programing areas.

+ -

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.

  1. Direct way using T-code SE91.
  2. 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,

  1. Using SE91 (message maintenance ) t-code.
  2. 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.

Creating message class in SAP

Select messages tab, save it in a package (local object for test) and start adding messages.

Message class in SAP ABAP

 

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.

message classes in SAP ABAP

Example with parameters

we use &to specify parameters in message of a message class.

Message class using parame in SAP ABAPters

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.

Message class with parameters in SAP

Tutorial Comments

Total Comments: Add your Comment
04 Feb 2014

good explanation..keep on provide the other topics...change the tcode se93...using se91 we can create the message class.

12 May 2014

nice explanation..It will really helpful for beginners in sap

15 May 2014

there is no message type called STATUS message it should be SUCCESS Message. Otherwise the document looks good.

24 Jun 2014

Very good explanation. it is help full to abap beginners

07 Jul 2014

thanx sir ....its very useful.....

22 Aug 2014

much clear and it is self explanatory to understand for a fresher to understand

22 Aug 2014

much clear and it is self explanatory to understand for a fresher to understand

03 Sep 2014

no doubt sir..this is the best side i have ever seen on sap........but sir if we wants to do some project work on sap project in that case can u suggest us any site or something so that we can make ourself prepare for future knowledge.............. sincerely varun

21 Sep 2014

TCode to create message class is SE91 not SE93 (SE93 is used to create Transaction Code).

08 Oct 2014

excellent this post is very help full to beginners

08 Oct 2014

excellent this post is very help full to beginners

29 Oct 2014

Thank you for sharing the knowledge, I've observed SE93 TCode for message class maintenance SE91 - Message Maintenance: Initial Screen. SE93 - Maintain Transaction.

29 Oct 2014

Thank you for sharing the knowledge, I've observed SE93 TCode for message class maintenance SE91 - Message Maintenance: Initial Screen. SE93 - Maintain Transaction.

23 Jun 2015

great example in this case. But I think should add another example or more example

25 Jun 2015

Thank you . Very clear explanation and helpful.

25 Jun 2015

Thank you . Very clear explanation and helpful.

12 Aug 2015

yeah this site is so useful for the SAP consultant. Great job !

10 Sep 2015

i like it this topic its very helpful . thank you for share:)

08 Feb 2016

Nice Concepts ..................................................................................... gooooooooooooooooooooooooooood

10 Feb 2016

by giving a small comments i cant judge it . this is a best site which i never seen ever before... very useful. And if u add a real time scenarios its will be helpfull.

04 Mar 2016

Tutorials in SAPNUTS are really helpful. For live examples if possible would be more better.

23 May 2016

Really Good Stuff to learn in SAPNUTS

03 Aug 2016

Good, very nice. please continue your job.

03 Nov 2016

Excellent!!!!!Well demonstrated. Very helpful !!!!!

05 Dec 2016

very nice topic it was grooming towards sap abap beginners.

12 Apr 2017

Nice Article for beginners and good screens

06 Oct 2017

How can we handle this with message handler?

Leave a Comment

Enter Comment Text