Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Program Flow Logic →  Exception Handling →  Class-Based Exceptions →  Exception Classes →  Exception Texts 

Messages as Exception Texts

The exception texts of an exception class are usually defined by referencing messages from the table T100. The exception class must implement the interface IF_T100_MESSAGE before the messages can be used as exception texts. Exception texts are assigned to messages using constant structures in the public visibility section of the exception class. Each statically predefined exception text has an identically named constant with the structured data type SCX_T100KEY from ABAP Dictionary. The individual components represent the message class, the message number, and the attributes assigned to the placeholders. The way the exception texts are edited depends on the tool in question:

  • Exception texts can be created on the Texts tab in Class Builder in ABAP Workbench and then assigned a message class and message number by selecting a message text. Furthermore, the placeholders "&1" to "&4" or "&" of the message can be assigned to public attributes of the exception class. Class Builder creates the associated constant structure in the public visibility section with the name of the exception text and generates a matching instance constructor.
  • In the ABAP Development Tools (ADT), exception texts can be edited in source code editors. An exception class is defined by the fact that it inherits from one of the superclasses CX_STATIC_CHECK, CX_DYNAMIC_CHECK, or CX_NO_CHECK. Classes of this type include the interface IF_T100_MESSAGE by default and the constructor is generated accordingly. The code template textIdExceptionClass can be used to create a constant structure in the visibility section for each exception text. The components of this structure define the properties of the message.

The input parameter TEXTID of the instance constructor of the exception class has the same data type as the attribute T100KEY of the interface IF_T100_MESSAGE, which references SCX_T100KEY. When an exception with messages as exception texts is raised, the constructor can be passed a structure with information about the message to be used as the exception text. It is strongly recommended that only the constants that exist in the class for the predefined exception texts are passed to TEXTID. This selects a predefined text for the exception. The attributes assigned to the placeholders "&1" to "&4" or "&" of a message can be assigned values using the input parameters of the same name of the instance constructor. The placeholders are replaced by the content of the assigned attributes when the exception is raised.

Other versions: 7.31 | 7.40 | 7.54


Notes

  • Exception texts associated with messages can be sent to the program user using the statement MESSAGE oref when the exception is handled.

  • When an exception class is created in Class Builder and the interface IF_T100_DYN_MSG (and hence IF_T100_MESSAGE) is included in the class, it is advisable to specify this when creating the exception class by setting the appropriate flag. This ensures that the constructor is generated immediately and as required. Otherwise, the constructor for internal exception texts is generated and must be generated again once it is included in the interface by choosing Utilities → Clean Up → Constructor in the menu.

  • The method GET_LATEST_T100_EXCEPTION in the class CL_MESSAGE_HELPER is used to return the last object in a chain of exception objects (created using the attribute PREVIOUS) that has an exception text defined by a message.

  • From a technical perspective, any structure of type SCX_T100KEY whose components specify any message of table T100 can be passed to the input parameter TEXTID of the instance constructor. This is strongly discouraged, however, because an exception should only be raised with specific texts when using the parameter TEXTID.

Executable Examples

  • The exception classes of the package SABAP_DEMOS_CAR_RENTAL_EXCPTNS, which is part of an example application created in the superpackage SABAP_DEMOS_CAR_RENTAL, use messages as exception texts. See CX_DEMO_CR_CAR_MODIFY, for example.