SAP RAISE EXCEPTION MESSAGE ABAP Statements



Get Example source ABAP code based on a different SAP table
  


• MESSAGE RAISE EXCEPTION
• ID RAISE EXCEPTION MESSAGE
• TYPE RAISE EXCEPTION MESSAGE
• NUMBER RAISE EXCEPTION MESSAGE
• WITH RAISE EXCEPTION MESSAGE
• USING RAISE EXCEPTION MESSAGE
• ID THROW MESSAGE
• TYPE THROW MESSAGE
• NUMBER THROW MESSAGE
• WITH THROW MESSAGE
• USING THROW MESSAGE

RAISE EXCEPTION, message
Short Reference

ABAP_SYNTAX
... ${ MESSAGE tn(id)
$| ${ ID mid TYPE mtype NUMBER num $}
$[WITH dobj1 ... dobj4$] $}
$| ${ USING MESSAGE $} ...

ABAP_VARIANTS:
1 ... MESSAGE msg ...
2 ... USING MESSAGE ...

What does it do?
The addition MESSAGE of the statement RAISE EXCEPTION and of the addition THROW in a conditional expression passes the specification of a message to the exception object.

ABAP_VARIANT_1 ... MESSAGE msg ...

What does it do?
The addition tn(id) or ID mid TYPE mtype NUMBER num is used to specify the message type, the message class, and the message number of a message msg for the table T100, statically or dynamically like in the statement MESSAGE. Also like in MESSAGE, the optional addition WITH can be used to provide the placeholders of a message with content. The exception class of the raised exception must implement one of the system interfaces for messages:
ITOC
The addition MESSAGE fills the attributes of these interfaces with values. This assignment takes place after the instance constructor is executed. This overwrites any values that were assigned to these attributes when the exception object was constructed.
The attributes of the system interfaces are used to link the exception object to the message specified after MESSAGE. Using an object reference, the object can be used directly in the variant MESSAGE oref of the MESSAGE statement and the message texts can be read using the interface methods.
If the addition MESSAGE is used, the input parameter TEXTID of the constructor of the exception class must not be filled. This parameter is only intended for specifying a predefined exception text.



Latest notes:

The addition MESSAGE cannot be specified after the variant RAISE EXCEPTION oref.
The position behind MESSAGE is contained in the where-used list for the message specified.
See also Exception Classes for Messages.
NON_V5_HINTS
ABAP_HINT_END

Using IF_T100_DYN_MSG
The full functionality of the addition MESSAGE is available only if the system interface IF_T100_DYN_MSG is implemented in the used exception class. This interface includes the system interface IF_T100_MESSAGE requested by the syntax check. If an exception class is used with the system interface IF_T100_DYN_MSG, the addition MESSAGE fills its attributes as follows after the instance constructor is executed:
The message type specified after MESSAGE is assigned to the attribute MSGTY of the interface IF_T100_DYN_MSG.
The components of the structured attribute T100KEY of the component interface IF_T100_MESSAGE are filled as follows:
MSGID is assigned the message class specified after MESSAGE .
MSGNO is assigned the message number specified after MESSAGE .
ATTR1 to ATTR4 are assigned the names IF_T100_DYN_MSG~MSGV1 to IF_T100_DYN_MSG~MSGV4 of the interface attributes for the placeholders of the message. If the addition WITH is not specified, ATTR1 to ATTR4 remain initial.
The attributes MSGV1 to MSGV4 of the interface IF_T100_DYN_MSG are assigned the texts specified using WITH.



Latest notes:

If IF_T100_DYN_MSG is used, the addition MESSAGE assigns the correct values to all required attributes of the exception class to link them to the message. More specifically, the attributes for the placeholders of the message are mapped to the structure T100KEY of the interface IF_T100_MESSAGE automatically.
In exception classes with the interface IF_T100_DYN_MSG, MESSAGE used together with the EXPORTING addition can produce unexpected results in the placeholder texts if the addition WITH is not specified. Implicit assignments of the input parameters specified after EXPORTING to the components ATTR1 to ATTR4 are intended for exception classes with the interface IF_T100_MESSAGE where WITH cannot be specified. Implicit assignments of the names of the input parameters or of initial values can be prevented by specifying WITH with a dummy value space.
NON_V5_HINTS
For the latter, see the executable example.
ABAP_HINT_END

ABAP_EXAMPLE_VX5
Raising of the exception CX_DEMO_DYN_T100 that implements the interface IF_T100_DYN_MSG. The addition MESSAGE is used to pass the properties of a message that determines the exception text.
ABEXA 00511
ABAP_EXAMPLE_END

ABAP_EXAMPLES_ABEXA
System Interface IF_T100_DYN_MSG in a Local Exception Class
System Interface IF_T100_DYN_MSG in a Global Exception Class
System Interface IF_T100_DYN_MSG for Exception error_message
ABAP_EXAMPLE_END

Using IF_T100_MESSAGE
If only the system interface IF_T100_MESSAGE is implemented, the addition WITH must not be used and only a restricted set of functions is available. When an exception class is used that implements only the system interface IF_T100_MESSAGE, the addition MESSAGE fills its attributes as follows after the instance constructor is executed:
The specification of a message type has no effect.
The components of the structured attribute T100KEY of the component interface IF_T100_MESSAGE are filled as follows:
MSGID is assigned the message class specified after MESSAGE .
MSGNO is assigned the message number specified after MESSAGE .
ATTR1 to ATTR4 are assigned the names of the first four input parameters of the instance constructors specified after EXPORTING that can be converted to a character-like target field, in the specified order. Components that cannot be assigned input parameters are initialized.



Latest notes:

It is recommended that the system interface IF_T100_DYN_MSG is used for exceptions raised using the addition MESSAGE.
The use of the addition MESSAGE for an exception class with IF_T100_MESSAGE is intended for cases where existing exception classes that cannot be switched to IF_T100_DYN_MSG must be used.
The addition MESSAGE is suitable for existing exception classes with IF_T100_MESSAGE that already have a generic exception text without semantic meaning. Previously, structures of the type SCX_T100KEY, filled in the program, had to be passed to such exceptions.
The use of the addition MESSAGE is not recommended for an exception class with IF_T100_MESSAGE whose exception texts all have a fixed semantic meaning.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_ABEXA
System Interface IF_T100_MESSAGE for Exception with Message
ABAP_EXAMPLE_END

ABAP_VARIANT_2 ... USING MESSAGE ...

What does it do?
This variant is a short form of the preceding variant of the MESSAGE addition. It can be used if the exception class of the raised exception implements the system interface IF_T100_DYN_MSG, and has the following effect: ... MESSAGE ID sy-msgid
TYPE sy-msgty
NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 ...
The addition USING MESSAGE implicitly passes the specification of the message that is stored during the execution of the statement in the system fields sy-msgid, sy-msgty sy-msgno, and sy-msgv1 to sy-msgv4 to the exception class.



Latest notes:

The short form is particularly suitable for converting classic exceptions that were raised in function modules or methods with the statement MESSAGE RAISING, or messages that were caught with error_message, into class-based exceptions.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX
Raising of the exception CX_DEMO_DYN_T100 that implements the interface IF_T100_DYN_MSG. The addition USING MESSAGE implicitly passes the properties of a status message that was previously output with the statement MESSAGE.
ABEXA 00512
ABAP_EXAMPLE_END

ABAP_EXAMPLE_V5
Raising of the exception CX_DEMO_DYN_T100 that implements the interface IF_T100_DYN_MSG. The addition USING MESSAGE implicitly passes the properties of a status message that was previously output with the statement MESSAGE. In the restricted language scope, the message needs to be written in a string msg.
ABEXA 01688
ABAP_EXAMPLE_END

ABAP_EXAMPLES_ABEXA
Converting a Classic Example to a Class-Based Exception
Converting the Exception error_message to a Class-Based Exception
ABAP_EXAMPLE_END

Return to menu