Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Program Flow Logic →  Exception Handling →  Class-Based Exceptions →  RAISE EXCEPTION →  RAISE EXCEPTION - message 

Converting a Classic Example to a Class-Based Exception

The example demonstrates the short form of the statement RAISE EXCEPTION with the addition MESSAGE.

Other versions: 7.31 | 7.40 | 7.54

Source Code

REPORT demo_raise_message_global_shrt.

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 USING MESSAGE.
        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

The example has exactly the same functionality as the executable example IF_T100_DYN_MSG in a global exception. Here, the addition USING MESSAGE is used, which explicitly passes the system fields sy-msgty, sy-msgid, sy-msgno, and sy-msgv1 to sy-msgv4 to the corresponding additions of the statement RAISE EXCEPTION.