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 in 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_message_oref_global.

CLASS msg_demo DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS main.
  PRIVATE SECTION.
    CLASS-METHODS meth
      RAISING cx_demo_t100.
ENDCLASS.

CLASS msg_demo IMPLEMENTATION.
  METHOD main.
    TRY.
        meth( ).
      CATCH cx_demo_t100 INTO DATA(oref).
        cl_demo_output=>display( oref->get_text( ) ).
        MESSAGE oref TYPE 'I' DISPLAY LIKE 'E'.
    ENDTRY.
  ENDMETHOD.
  METHOD meth.
    RAISE EXCEPTION TYPE cx_demo_t100
      EXPORTING
        textid = cx_demo_t100=>demo
        text1  = 'I'
        text2  = 'am'
        text3  = 'an'
        text4  = 'Exception!'.
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  msg_demo=>main( ).

Description

This executable example works in the same way as the example in System Interface IF_T100_MESSAGE in a Local Exception Class. Here, however, the interface IF_T100_MESSAGE is included in the global exception class CX_DEMO_T100. The association with a message class was made at the same time as the class was created. This dictates that the exception class is generated in such a way that it supports messages as exception texts, rather than merely including the interface IF_T100_MESSAGE.

On the tab Texts in Class Builder, the message 888 from the message class SABAPDEMOS is assigned to the exception text DEMO of the exception class under Message Text. The placeholders of the message are associated with the attributes TEXT1 to TEXT4. The source text of the public section of the class implements this assignment using the structured constant DEMO with the type SCX_T100KEY. The constructor has an input parameter TEXTID that can be passed the constant DEMO and the input parameters TEXT1 to TEXT4 used to fill the attributes with the same names.

A structure passed to the input parameter TEXTID when an exception from this class is raised is assigned to the structure T100KEY of the interface IF_T100_MESSAGE. This uses the corresponding message as an exception text. It is recommended that only the predefined constants of the class are passed, as shown here.

See also the executable examples listed below.