Message Classes in SAP : A guide

Message class can be used to store all the messages involved in any report/program, function module and so on. This will avoid hardcoding and gives more flexibility in case of any change.This small guide will introduce you to message classes with a easy to do steps.

First create a message class using transaction SE91.
SE91: Maintain Message class
SE91: Maintain Message class


Write all the messages in it.
Messages in message class
Messages in message class
Now to use this in any report there are 2 ways:
REPORT  ZAU_ASSIGNMAT MESSAGE-ID ZAU_MSGS.

Messages can be called using Pattern button

Pattern option in ABAP
Pattern option in ABAP
Type message class name in ID, Cat means type of message (error, info, success etc ). Lastly number specifies the message number in that class.

Parameters can also be transferred from reports to message class.

Just use & for each parameter in message text in message class and pass values by using 'WITH'.

Ex: This Material does not belong to plant & & in message class

In report use WITH,

MESSAGE e002 WITH p_werks p_matnr.
& will be replaced by the values passed by using 'with ' suffix in order.