sapdev logo background
sapdev logo sapdev logo
Comments

ABAP MESSAGE MSG Statement syntax, information and example SAP source code



Return to Statement index



MESSAGE - msg

Short Reference

ABAP Syntax ... { tn }
| { tn(id) }
| { ID mid TYPE mtype NUMBER num }
| { oref TYPE mtype } ... .

ABAP_ALTERNATIVES:
1 ... tn ...
2 ... tn(id) ...
3 ... ID mid TYPE mtype NUMBER num ...
4 ... oref TYPE mtype ...

What does it do? msg specifies a message
from the database table T100 either by specifying id and n directly or by using the content of the data objects mid and num for the message class and the message number. Alternatively, an object reference variable oref is specified whose
dynamic type implements the interface IF_T100_MESSAGE . One of the possible message types "A", "E", "I", "S", "W", or "X" must be specified, either by specifying t directly or as content of the data object mtype . This controls the behavior of the message.
If the specified message is not found for the logon language of the current user, a search is made in the secondary language (profile parameter zcsa/second_language ) and then in English. If it is still not found, the specified message type, message class, and message number are used as short text in uppercase letters and separated by a colon ":".
The system fields of the statement MESSAGE are always supplied with the specified values.
Latest notes: The maximum length of a message is 269 and is determined from the short text of the message in the database table T100 (with a maximum of 73 characters) including up to four single-character placeholders
. These placeholders can be replaced by strings with a maximum of 50 characters using the addition WITH
).

ABAP_ALTERNATIVE_1 ... tn ...

What does it do? t and n are used to specify the single-character message type and the three-digit message number directly in a row (static short form). The message class must be specified with the addition MESSAGE-ID in the statement that introduces the program.
Example ABAP Coding Displays the short text of the message with the number 014 from the message class SABAPDOCU as an information message .
REPORT rep MESSAGE-ID sabapdemos.
...
MESSAGE i014.

ABAP_ALTERNATIVE_2 ... tn(id) ...

What does it do? The same applies to t and n as to the static short form. In the static long form, the message class is specified directly in parentheses using id .
Latest notes: Specifying the message class explicitly overrides the addition MESSAGE-ID of the statement that introduces the program.
Specifying the message class in parentheses does not signify here that the content of id is used. In fact, the message class is used that has the name that was specified directly with id .
Example ABAP Coding As in the example for alternative 1, with the message class specified explicitly.
REPORT ...
...
MESSAGE i014(sabapdemos).

ABAP_ALTERNATIVE_3 ... ID mid TYPE mtype NUMBER num ...

What does it do? The message class, the message type, and the message number are specified as content of the data objects mid ,
mtype , and num (dynamic form). mid and mtype expect character-like data objects that must contain the message class or the message type in uppercase letters. Invalid message types raise a non-handleable exception. num expects a data object of the type n and length 3.
Latest notes: Specifying the message class explicitly overrides the addition MESSAGE-ID of the statement that introduces the program.
Example ABAP Coding As in the example for alternative 2, with the message and the message type specified dynamically.
DATA: mid TYPE sy-msgid VALUE 'SABAPDEMOS',
mtype TYPE sy-msgty VALUE 'I',
num TYPE sy-msgno VALUE '014'.

MESSAGE ID mid TYPE mtype NUMBER num.

ABAP_ALTERNATIVE_4 ... oref TYPE mtype ...

What does it do? For oref , an object reference variable can be specified which, when the statement MESSAGE is executed, points to an object whose class implements the system interface
IF_T100_MESSAGE . This in turn contains the component interface
IF_MESSAGE . mtype expects a character-like data object containing the message type in uppercase letters. oref is a functional operand position .
The statement MESSAGE analyzes the components of the structured attribute T100KEY of the interface
IF_T100_MESSAGE in the referenced object. The message class is taken from the component MSGID and the message number from the component MSGNO . If the components ATTR1 through ATTR4
contain the names of other attributes of the object, the placeholders "<(> <)>1" through "<(> <)>4" and "<(> <)>" of the short text or "<(> <)>V1<(> <)>" through "<(> <)>V4<(> <)>" of the long text of the message are replaced by the content of these attributes according to the rules of usage given by the additions WITH in message_options . If one of these components does not contain an attribute name, the character "<(> <)>" is added to the content at the beginning and end, thus replacing the placeholder.
Latest notes: In this variant, the additions WITH and INTO
in message_options are not allowed.
If field symbols or formal parameters of the generic type any or data are specified for oref , then the syntactically identical variant MESSAGE text is used.
This variant is mainly intended to be used with exception objects . If a global exception class implements the interface IF_T100_MESSAGE , then the components of the structure T100KEY are filled in accordance with the definition of the associated exception text when such an exception is raised in the interface method GET_TEXT (which is implemented in the superclass
CX_ROOT ). In local exception classes, the components must fill themselves. To do this, do not redefine the interface method
GET_TEXT , but use the instance constructor instead.
For compatibility reasons, this variant can still be used for classes that only implement the interface IF_MESSAGE . In this case, the interface methods GET_TEXT and GET_LONGTEXT are called automatically in the referenced object and their return value is used as the short text or long text of the message. In this case, the system fields sy-msgid and sy-msgno are not filled specifically. The root class of all exception classes
, CX_ROOT , implements the interface IF_MESSAGE . In exception classes that do not implement the interface
IF_T100_MESSAGE , the interface methods GET_TEXT and
GET_LONGTEXT get the exception texts of exception objects stored in OTR ( Online Text Repository ), which then can be issued by using the variant of the MESSAGE statement as a message.

Example ABAP Coding See Sending a Message Using an Interface Reference Variable .
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved




MESSAGE
MESSAGE_OPTIONS




comments powered by Disqus