Messages - SAP ABAP


Messages

Message type

  • Messages allow you to communicate with users from your programs. They’re used mainly when the user has made an invalid entry on a screens or from different SAP objects (like programs, function modules, exits and enhancements).
  • The message text can be maintained locally in the program or globally using a message class.
  • Messages are raised in the program code via the MESSAGE statement.
  • There are different types of messages that can be displayed based on requirements.
    Note:
    Global message texts are stored in table T100 and can be configured using Transaction SE91.
    How many types of message types are there?
    There are 6 message types available as below:
    A - Used in the terminate the process when there is any error.
    E - Used to display an error dialog based on program context
    I - Used to display status information
    S -  To display the Success or Status message in Green color
    W - A warning message is prompted based on the program context.
    X - To Exit processes, no message is displayed, but the program terminates with short dump, normally used in runtime errors.

    How can we write/Maintain Messages?
1. Direct messages in program.
    Ex: MESSAGE 'The input was invalid' TYPE 'E'.
          MESSAGE 'Database update successful' TYPE 'I'.
2.Messages using Text Symbols
In every ABAP Object/Program level, we can maintain text in Text symbols like below:
Then Maintain the message in the text symbols as shown in below:


Then, By Using the text symbols We can write message in programs is as follows:
MESSAGE text-001 TYPE 'E'.
3.Messages Using Message Class

  • Text symbols maintained in the program are local, so they can only be reused within individual program.
  • Maintaining the same message texts in multiple programs can be eliminated by maintaining message texts globally, using a message class
  • When creating a new message class, it should be in a customer namespace, starting with Y or Z.
  • Global message texts are stored in table T100 and can be configured using transaction SE91. 

Steps to Create Global Message Class

1. Enter Message Class Name


2.Click on Create




3.Maintain Attributes: Here, you can enter Short Text.
Then Click on Messages TAB




4.Maintain the Global Messages here



Once you done with the maintenance of messages click on SAVE & CHECK.
Done with the creation of Messages.

Q: How to use global messages in ABAP coding?
     MESSAGE e000(ZMSG_CLASS).


Example Program using Messages:


REPORT zadd_message_in_abap.
*&-------------------------------------------------
*& Note: Various ways of using messages in Program
*&-------------------------------------------------
*&-------------------------------------------------
*& 1. Local Message-Hard coded Message
*&-------------------------------------------------

 MESSAGE 'No data found' TYPE 'I'.

*&-------------------------------------------------
*& 2. Local Message-using text symbols
*&-------------------------------------------------

*& GO TO-> TEXT ELEMENTS -> TEXT SYMBOLS->MAINTAIN MESSAGE
*& USE THAT NO IN MESSAGE

MESSAGE text-001 TYPE 'I'.

*&-------------------------------------------------
*& 3. Message using Global Messages
*& Message Class: ZTEST_MSG01, Created in SE91 and Used here
*&-------------------------------------------------
MESSAGE I000(ZTEST_MSG01).   " 000-> No data Found


Comments

Popular posts from this blog

SAP ABAP-Internal Table Operations and Example Program

HR ABAP Interview Questions and Answers

BDC (Batch Data Communication) - SAP ABAP