Skip to content

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 and sy-msgno can be used after the addition MESSAGE of the statement RAISE EXCEPTION to associate the exception object with the message.
  • sy-msgv1 to sy-msgv4 can be specified after WITH and are assigned here to the interface attributes MSGV1 to MSGV4 automatically.
  • sy-msgty can also be passed further here using MESSAGE.


Note

See also the executable example for using a short form of statement RAISE EXCEPTION MESSAGE.