Wednesday, November 2, 2016

Using SAP messages with your ABAP programs

SAP messages are an essential part of any ABAP program and are used to display information to the user to let them know what's happening. 

The following ABAP code is the simplest way to implement a message into your report. 

    MESSAGE 'Display this message' TYPE 'E'. 

SAP Message Classes 
A better way to implement your messages would be to create and maintain them via a message class using transactions SE91 or SE80. This way you have a central store for all messages, which makes it easier to maintain them. This is especially true if your messages need to be translated into multiple languages. 

To do this you first need to create a message class which is a kind of container/wrapper where you store related messages together. Once this is done you can add as many message as you require into it. You also get the option to create additional long text, which offers the user additional information about the particular issue. See the following link for more information and details of how to create a message class

Once you have created your message you can use them within your ABAP code using the following syntax: 

    MESSAGE E001(MCLASS). 

MESSAGE = ABAP statement 
E = Type of message (can also be I,W,S,A,X) 
001 = Message number 
MCLASS = Message Class 

You can also add parameters to your messages using the "&" character. So for example you could create the following message 'Purchase order & has been deleted'. You can then pass a purchase order to the message when using it and it will replace the "&" with the purchase order you pass for example 

    MESSAGE E001(MCLASS) with ekko-ebeln. 

The result would display 
"Purchase order 1234 has been deleted"

Further information about message types 

I - Information messages
Information message are displayed in a popup window and only pause processing until you have clicked through the message. 

E - Error message 
An error message will be displayed in red along the footer of the SAP screen and stops processing going any further. 

W - Warning message 
A warning message behaves similar to and error message and is displayed along the footer of the SAP screen and stops processing going any further. 

S - Success/Status message 
A Success message is also displayed along the footer of the SAP screen but does not stop processing going any further and is simply displayed at the end in green. 

Termination messages:
The termination messages (message type A or X) leads to an implicit database rollback in current SAP LUW.

A - Termination/Abend
A termination message stops processing and causes a runtime error and short dump which is also viewable in tcode ST22.

X - Exit
An exit message stops processing and displays and exit button which exits session processing. Similar to typing /n into the SAP command box.


No comments:

Post a Comment

SAP giới thiệu mã hỗ trợ AI trong ngôn ngữ ABAP riêng của mình

SAP đã ra mắt một loạt tính năng mã hỗ trợ AI trong môi trường phát triển ứng dụng dựa trên đám mây của mình, đồng thời tham gia vào danh sá...