ABAP Keyword Documentation → ABAP - Reference → Program Flow → Exception Handling → Exceptions Before Class-Based Exceptions → Non-Class-Based Exceptions
MESSAGE - RAISING
Other versions: 7.31 | 7.40 | 7.54
Syntax
MESSAGE { msg |
text } RAISING exception [WITH dobj1 ... dobj4].
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, the addition must not be used in the same
processing block as the statement RAISE EXCEPTION
for raising class-based exceptions.
-
If the
MESSAGE
-statement is processed with the additionRAISING
during processing of a method or a function module whose caller assigns a return value to the exceptionexception
with the additionEXCEPTIONS
of the statementCALL
, it has the same effect as the statementRAISE
. -
If no return value is assigned to the exception
exception
, the addition RAISING is ignored and the message is sent using the statementMESSAGE
and processed in accordance with its message type.
The system fields of the statement MESSAGE
are populated in both cases and
are available in the calling program after handling an exception raised with MESSAGE ...RAISING
. This is especially true if a function module was called through Remote Function Call
(RFC).
Notes
-
The statement
MESSAGE ... RAISING
is primarily a statement for raising exceptions and not for sending messages. An exception of this type should always be handled like an exception raised usingRAISE
, since the behavior of the message depends strongly on the context and is usually unpredictable when the function module is created. -
Using
MESSAGE ... RAISING
in cases in which non class-based exceptions must still be used is preferable to using theRAISE
statement, because it offers the option of providing additional text information with an exception. -
A return value can be assigned to messages that are sent in function modules without the addition
RAISING by using the predefined exception
error_message
. -
Messages sent as messages when a function module is called and not caught (despite
RAISING
) are processed as witherror_message
. -
If a procedure is exited by raising an exception, the content of the formal parameter for which the
pass by value is defined is not assigned to the respective actual parameters.
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.