ABAP - Keyword Documentation →  ABAP - Programming Language →  Program Flow Logic →  Exception Handling →  Class-Based Exceptions →  RAISE EXCEPTION → 

RAISE EXCEPTION, message

Short Reference

Syntax

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


Variants:

1. ... MESSAGE msg ...

2. ... USING MESSAGE ...

Effect

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.

Variant 1

... MESSAGE msg ...


Effect

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 contents. The exception class of the raised exception must implement one of the system interfaces for messages:

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.

Hints

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:

Hints

Example

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.

TRY.
    RAISE EXCEPTION TYPE cx_demo_dyn_t100
      MESSAGE ID 'SABAPDEMOS'
      TYPE 'I'
      NUMBER '888'
      WITH 'Message'.
  CATCH cx_demo_dyn_t100 INTO DATA(oref).
    cl_demo_output=>display( oref->get_text( ) &&
                             `, ` && oref->msgty ).
ENDTRY.

Executable Examples

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:

Hints

Executable Example

System Interface IF_T100_MESSAGE for Exception with Message

Variant 2

... USING MESSAGE ...


Effect

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.

Hint

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.

Example

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.

MESSAGE ID 'SABAPDEMOS' TYPE 'S'
        NUMBER '888'
        WITH 'Message'.
TRY.
    RAISE EXCEPTION TYPE cx_demo_dyn_t100 USING MESSAGE.
  CATCH cx_demo_dyn_t100 INTO DATA(oref).
    cl_demo_output=>display( oref->get_text( ) &&
                             `, ` && oref->msgty ).
ENDTRY.

Executable Examples



Continue
Example Converting a Classic Example to a Class-Based Exception
Example Converting the Exception error_message to a Class-Based Exception