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 Local Exception Class

This example demonstrates how a local exception class is associated with a message

Other versions: 7.31 | 7.40 | 7.54

Source Code

REPORT demo_raise_message.

CLASS cx_dyn_t100 DEFINITION INHERITING FROM cx_dynamic_check.
  PUBLIC SECTION.
    INTERFACES if_t100_dyn_msg.
    ALIASES msgty FOR if_t100_dyn_msg~msgty.
ENDCLASS.

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

CLASS msg_demo IMPLEMENTATION.
  METHOD main.
    TRY.
        meth( ).
      CATCH cx_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.
    RAISE EXCEPTION TYPE cx_dyn_t100
          MESSAGE e888(sabapdemos) WITH 'I' 'am' 'an' 'Exception!'.
  ENDMETHOD.
ENDCLASS.

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

Description

This example applies the executable example for the interface IF_T100_MESSAGE to the interface IF_T100_DYN_MSG directly. The local class cx_dyn_t100 includes the interface IF_T100_DYN_MSG and the addition MESSAGE of the statement RAISE EXCEPTION is used to raise the exception in the method meth.

Unlike when using IF_T100_MESSAGE, no separate attributes for the placeholders of the message and no implementation of the instance constructor are required in cx_dyn_t100. Furthermore, the message type is passed in an attribute of the exception object when IF_T100_DYN_MSG is used. An alias name is used here.