ABAP Keyword Documentation → ABAP − Reference → Text Repositories → Messages → System Interfaces for Messages → System Interface IF_T100_DYN_MSG for Messages
IF_T100_DYN_MSG in a Global Exception Class
This example demonstrates how a global exception class is associated with a message
Other versions:
7.31 | 7.40 | 7.54
Source Code
REPORT demo_raise_message_global.
CLASS msg_demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
PRIVATE SECTION.
CLASS-METHODS meth EXCEPTIONS exception.
ENDCLASS.
CLASS msg_demo IMPLEMENTATION.
METHOD main.
TRY.
meth( EXCEPTIONS exception = 4 ).
IF sy-subrc <> 0.
RAISE EXCEPTION TYPE cx_demo_dyn_t100
MESSAGE ID sy-msgid
TYPE sy-msgty
NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
CATCH cx_demo_dyn_t100 INTO DATA(oref).
cl_demo_output=>display(
|Caught exception:\n\n| &&
|"{ oref->get_text( ) }", Type { oref->msgty } | ).
MESSAGE oref TYPE 'I' DISPLAY LIKE oref->msgty.
ENDTRY.
ENDMETHOD.
METHOD meth.
MESSAGE e888(sabapdemos) WITH 'I' 'am' 'an' 'Exception!'
RAISING exception.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
msg_demo=>main( ).
Description
This example demonstrates the transformation of a non-class-based exception raised in a method using
MESSAGE RAISING
and, when
the method is called, handled using the addition EXCEPTIONS
to a class-based exception. This example works in the same way as the
executable example for the system interface
IF_T100_MESSAGE, but uses the class CX_DEMO_DYN_T100, which includes the system interface
IF_T100_DYN_MSG.
- In both cases,
sy-msgid
andsy-msgno
can be used after the additionMESSAGE
of the statementRAISE EXCEPTION
to associate the exception object with the message.
sy-msgv1
tosy-msgv4
can be specified afterWITH
and are assigned here to the interface attributes MSGV1 to MSGV4 automatically.
sy-msgty
can also be passed further here usingMESSAGE
.
Note
See also the executable example for
using a short form of statement RAISE EXCEPTION MESSAGE
.