Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Text Repositories →  Messages →  System Interfaces for Messages →  System Interface IF_T100_MESSAGE for Messages 

IF_T100_MESSAGE for Exception with Message

This example demonstrates the MESSAGE addition when an exception is raised using IF_T100_MESSAGE.

Other versions: 7.31 | 7.40 | 7.54

Source Code

REPORT demo_raise_message_reuse_attr.

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_t100
            MESSAGE ID sy-msgid
                    NUMBER sy-msgno
            EXPORTING text1 = conv #( sy-msgv1 )
                      text2 = conv #( sy-msgv2 )
                      text3 = conv #( sy-msgv3 )
                      text4 = conv #( sy-msgv4 ).
        ENDIF.
      CATCH cx_demo_t100 INTO DATA(oref).
        cl_demo_output=>display(
          |Caught exception:\n\n| &&
          |"{ oref->get_text( ) }"| ).
        MESSAGE oref TYPE 'I' DISPLAY LIKE 'E'.
    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. It uses the exception CX_DEMO_T100 from the executable example for the system interface IF_T100_MESSAGE in a global exception class, which includes only the interface IF_T100_MESSAGE and not IF_T100_DYN_MSG.

The properties of the message sent using MESSAGE RAISING are available in the system fields sy-msgty, sy-msgid, sy-msgno, and sy-msgv1 to sy-msgv4 after the exception is caught.

  • sy-msgid and sy-msgno are used after the addition MESSAGE of the statement RAISE EXCEPTION to associate the exception object with the message.
  • sy-msgv1 to sy-msgv4 are assigned to the input parameters of the instance constructor, which themselves are assigned to the identically named attributes.
  • sy-msgty cannot be passed further in this case.

The executable example for the system interface IF_T100_DYN_MSG in a global exception demonstrates how all properties of the message can be specified after the addition MESSAGE.