AS ABAP Release 758, ©Copyright 2024 SAP SE. All rights reserved.
ABAP - Keyword Documentation → ABAP - Programming Language → Program Flow Logic → Exception Handling → Exceptions Before Class-Based Exceptions → Non-Class-Based Exceptions →
MESSAGE, RAISING
Syntax
MESSAGE { msg |
text } [DISPLAY LIKE dtype] [WITH dobj1... dobj4]
RAISING exception.
Effect
The statement MESSAGE with the addition RAISING raises a non-class-based exception exception and only sends a message if the exception is not handled. The semantics of msg, text, and WITH is the same as in the statement MESSAGE without the addition RAISING.
This addition only makes sense during the processing of methods and function modules in which the non-class-based exception exception is defined. Furthermore, it cannot be used in the same processing block as the statement RAISE EXCEPTION or the addition THROW in a conditional expression to raise class-based exceptions.
The system fields of the statement MESSAGE are filled in both cases and are available in the calling program after an exception raised using MESSAGE ...RAISING is handled. This applies in particular if a function module was called using Remote Function Call (RFC).
Hints
Example
When the message is called for the first time, an information message is sent. The second time, an exception is raised instead, which is handled by sy-subrc.
CLASS c1 DEFINITION.
PUBLIC SECTION.
CLASS-METHODS m1 EXCEPTIONS exc1.
ENDCLASS.
CLASS c1 IMPLEMENTATION.
METHOD m1.
MESSAGE 'Message in a Method' TYPE 'I' RAISING exc1.
ENDMETHOD.
ENDCLASS.
...
c1=>m1( ).
c1=>m1( EXCEPTIONS exc1 = 4 ).
IF sy-subrc = 4.
...
ENDIF.