Show TOC

Adding Code Templates to an ABAP Exception ClassLocate this document in the navigation structure

Context

In the source code editor of an ABAP exception class, you can add the code template textIdExceptionClass. This code template contains the constant definitions for assigning the message number and attributes of a message class that are to be displayed.

Procedure

  1. In the private section of the ABAP exception class, type textID and open the code completion window.
  2. Sample Code This code template is added:
    <example>The code template is added:<codeblock><codeph>CONSTANTS:
     BEGIN OF [Name of the exception class],
      msgid TYPE symsgid VALUE 'msgid',
      msgno TYPE symsgno VALUE 'msgno',
      attr1 TYPE scx_attrname VALUE 'attr1',
      attr2 TYPE scx_attrname VALUE 'attr2',
      attr3 TYPE scx_attrname VALUE 'attr3',
      attr4 TYPE scx_attrname VALUE 'attr4',
     END OF [Name of the exception class].
    </codeph>
    </codeblock></example>
    Add the textIdExceptionClass code template from the popup.
  3. In the framed entry fields of the code template, replace the following variables:
    1. Add the name of the message class in the msgid field.
    2. Add the message number in the msgno field.
    3. [Optional:] If the message contains attributes, add the value for the corresponding <emphasis>attr</emphasis> attribute that should be filled in the message.

Results

EXAMPLE

In the following example, you see the code snippet of an ABAP exception class referring to a message in the message class BC_DATAMODEL_SERVICE.

There is the exception class CX_MY_EXCEPTION_CLASS:

  1. The relevant message class has the ID BC_DATAMODEL_SERVICE.
  2. The message that should be displayed has the number 118 and contains the short text 'Number of booked places &1 exceeds flight capacity &2'.
  3. The containing variables &1 and &2 are replaced by the values of the attributes BOOKED_SEATS with the value '242 and SEATS with the value '200'.

As a result, the exception message is displayed as 'Number of booked places 242 exceeds flight capacity 200'.

Sample Code
CONSTANTS: 
  BEGIN OF CX_MY_EXCEPTION_CLASS, 
    msgid TYPE symsgid VALUE 'BC_DATAMODEL_SERVICE', 
    msgno TYPE symsgno VALUE '118', 
    attr1 TYPE scx_attrname VALUE 'BOOKED_SEATS', 
    attr2 TYPE scx_attrname VALUE 'SEATS', 
    attr3 TYPE scx_attrname VALUE '', 
    attr4 TYPE scx_attrname VALUE '', 
  END OF CX_MY_EXCEPTION_CLASS. 
      
DATA seats TYPE i READ-ONLY. 
DATA booked_seats TYPE i READ-ONLY.