What is Message?
Messages are used to describe what is happening in the program execution to the programmer or user. Messages represents with a three-digit number. Messages range starts from 000 to 999.
Message Types –
Messages are basically six types. Those are –
A | Abend | The message appears in a separate dialog box and the program execution get terminated. When the user has confirmed the message, control returns to the next-highest area menu. |
E | Error | An error dialog appears or the program terminates depending on the program condition. |
I | Information | The message appears in a separate dialog box. Once the user has confirmed the message, the program execution continues from the next statement coded immediately after the MESSAGE statement. |
S | Success | The total program execution continues normally and the message is displayed in the status bar of the screen. |
W | Warning | An error message is displayed in the status bar of the screen and the program execution terminates. |
X | Exit or Abort | No message is displayed. The program terminates with a short dump. Program terminations with a short dump normally only occur when a runtime error occurs. |
Message Usage –
Messages can be added to the program mostly in two ways. Those are –
- Coding directly in the program
- By using the message class.
Coding directly in the program –
Coding the message directly in the program is a very simple process. No definition was required before coding the message in the program.
Syntax –
MESSAGE {message-name} TYPE {message-type}.
- Message – 80 characters user defined message.
- Message-type – Specifies the message type.
Now, let us see how different message types coded one by one with seperate examples.
Example –
Display abend message.
Code –
*&---------------------------------------------------------------------*
*& Report Z_MESSAGE
*&---------------------------------------------------------------------*
*& Written by TutorialsCampus
*&---------------------------------------------------------------------*
REPORT Z_MESSAGE.
* Displaying Abend Message of type A
MESSAGE 'This is a Abend message' TYPE 'A'.
Output –
Explaining Example –
In the above example, each and every statement is preceeded with a comment to explain about the statement. Go through them to get clear understanding of example code.
MESSAGE ‘This is a Abend message’ TYPE ‘A’. – Opens a popup and displays ‘This is a Abend message’ on the popup.
Example –
Display error message.
Code –
*&---------------------------------------------------------------------*
*& Report Z_MESSAGE
*&---------------------------------------------------------------------*
*& Written by TutorialsCampus
*&---------------------------------------------------------------------*
REPORT Z_MESSAGE.
* Displaying error Message of type E
MESSAGE 'This is a Error message' TYPE 'E'.
Output –
Explaining Example –
In the above example, each and every statement is preceeded with a comment to explain about the statement. Go through them to get clear understanding of example code.
MESSAGE ‘This is a Error message’ TYPE ‘E’. – Displays ‘This is a Error message’ on the output page status bar.
Example –
Display Informational message.
Code –
*&---------------------------------------------------------------------*
*& Report Z_MESSAGE
*&---------------------------------------------------------------------*
*& Written by TutorialsCampus
*&---------------------------------------------------------------------*
REPORT Z_MESSAGE.
* Displaying Informational Message of type I
MESSAGE 'This is a Informational message' TYPE 'I'.
Output –
Explaining Example –
In the above example, each and every statement is preceeded with a comment to explain about the statement. Go through them to get clear understanding of example code.
MESSAGE ‘This is a Informational message’ TYPE ‘I’. – Opens a popup and displays ‘This is a Informatonal message’ on the popup.
Example –
Display success message.
Code –
*&---------------------------------------------------------------------*
*& Report Z_MESSAGE
*&---------------------------------------------------------------------*
*& Written by TutorialsCampus
*&---------------------------------------------------------------------*
REPORT Z_MESSAGE.
* Displaying Success Message of type S
MESSAGE 'This is a Success message' TYPE 'S'.
Output –
Explaining Example –
In the above example, each and every statement is preceeded with a comment to explain about the statement. Go through them to get clear understanding of example code.
MESSAGE ‘This is a Success message’ TYPE ‘S’. – Displays ‘This is a Success message’ on the output page status bar.
Example –
Display warning message.
Code –
*&---------------------------------------------------------------------*
*& Report Z_MESSAGE
*&---------------------------------------------------------------------*
*& Written by TutorialsCampus
*&---------------------------------------------------------------------*
REPORT Z_MESSAGE.
* Displaying Warning Message of type W
MESSAGE 'This is a Warning message' TYPE 'W'.
Output –
Explaining Example –
In the above example, each and every statement is preceeded with a comment to explain about the statement. Go through them to get clear understanding of example code.
MESSAGE ‘This is a Warning message’ TYPE ‘W’. – Displays ‘This is a Warning message’ on the output page status bar.
Example –
Display exit message.
Code –
*&---------------------------------------------------------------------*
*& Report Z_MESSAGE
*&---------------------------------------------------------------------*
*& Written by TutorialsCampus
*&---------------------------------------------------------------------*
REPORT Z_MESSAGE.
* Displaying Exit Message of type X
MESSAGE 'This is a Exit message' TYPE 'X'.
Output –
Explaining Example –
In the above example, each and every statement is preceeded with a comment to explain about the statement. Go through them to get clear understanding of example code.
MESSAGE ‘This is a Exit message’ TYPE ‘X’. – Displays ‘This is a Exit message’ on the output exit page.
Using the message class –
In this scenario, messages gets displayed from the message class that is defined by using MESSAGE-ID along with the REPORT command. Message number is a three-character code that can define a set of 1000 messages and those are accessed when MESSAGE command executed in the program.
Messages number ranges from 000 to 999 (i.e. 1000 messages). Each message associated with message number and the message length can be upto 80 characters.
When a message number used in the program, the corresponding message retrived from the message class and gets displayed.
Syntax –
MESSAGE {message-name} WITH field1 ... field4.
This addition replaces the placeholders “&1” to “&4” and “&” of the short text or “&V1&” to “&V4&” of the long text of of the operands field1, …, field4. Up to four operands field1 through field4 can be specified.
Messages are not always static and some part of the message can be filled with a dynamic or runtime text.
While creating a custom message, Amber sign (&) symbol used in the place of dynamic or runtime text.
The MESSAGE…WITH statement used to pass the dynamic or runtime text during the program execution.
Example –
Create a message class with a template message and pass the runtime text to complete the message.
First we need to create the message class with MESSAGE-ID by coding in the program.
Step-1: Code MESSAGE-ID along with REPORT shown like below. ZMG_CUSTMESG is the new message class.
Step-2: Double click on the message class name (ZMG_CUSTMESG) to create it. The Create Object diaglog gets opened.
Step-3: Click on “YES” to create new. It directs to Message Maintenance screen.
Step-4: Once the required information updated, move to “Messages” tab or Save button. Below screen gets appear.
Step-5: Select the desired package and click on “Local Object” button or “Save“. The Messages tab gets opened like below.
Step-6: Create the messages that required and click on “Save” button to save. Now newly created message class gets saved and it routes to ABAP Editor to continue the program coding.
The text in the MESSAGE statement replaces ‘&‘ and displays the message.
Step-7: Open ABAP editor and complete the coding in the program.
The message defined for the message number 000 is ‘This is a & Message’. We are passing custom text(‘Informational’) in MESSAGE….WITH statement. So the ‘&’ replaces with ‘Informational’ and displays the message as ‘This is a Informational message’. As it is an message type ‘I’, it displays in separate dialog box.
Step-8: Execute the program to display the output.
Finally, the custom message displayed with dynamic or runtime text ‘Informational’. The output ‘This is Informational Message’ gets displayed on the seperate informational dialog box.