Skip to content

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

Exception Texts

Each exception is assigned a text that can be given parameters using attributes and that describes the exception situation. This text is displayed in the short dump of the runtime error if the exception is not handled. If the exception is handled in the program, the text can be read using the method GET_TEXT. If applicable, the long text can be read using the method GET_LONG_TEXT.

A global exception class has a predefined exception text that has the same name as the exception class. The predefined text can be edited in Class Builder on the Texts tab page and additional exception texts can be defined. The exception texts of an exception class can be created either by referencing messages from table T100 or as texts in OTR (Online Text Repository). See below for more information.

For each exception text, Class Builder creates a static constant in the public section of the exception class with the same name as the exception text. When the exception is raised, this can be passed to the parameter TEXTID of the instance constructor to determine the exception text. If the parameter is not passed, the predefined exception text with the same name as the exception class is used.

Other versions: 7.31 | 7.40 | 7.54

Programming Guideline

Create suitable exception texts in the exception class and only use these texts


Notes

  • The names of the exception texts defined on the Texts tab page of Class Builder are keys for the available texts of an exception class. This means that when an exception is raised, only the exception class constants of the same name should be passed to the TEXTID parameter to identify the exception text.

Messages as Exception Texts

If the exception class implements the interface IF_T100_MESSAGE, the short texts of messages in the database table T100 can be used as exception texts. On the Texts tab page of Class Builder, Message Text can be chosen to assign a message class and a message number to each exception text specified there; these assignments define the exception text. Furthermore, the placeholders "&1" to "&4" or "&" of the message can be assigned to public attributes of the exception class. When the exception is raised, the placeholders are replaced by the content of the attributes. These texts can be sent to the program user using the statement MESSAGE oref when the exception is handled.

In the public section of the exception class, each statically predefined exception text is represented by a 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 input parameter TEXTID of the instance constructor is of data type T100KEY of the interface IF_T100_MESSAGE, which references SCX_T100KEY. When an exception with this kind of exception text 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 of a message can be assigned values using the input parameters of the same name of the instance constructor.


Notes

  • Message texts from the database table T100 should only be used if the text is to be sent to the program user. This might be the case with application programs but should generally be avoided in system programs. One disadvantage of using message short texts is that they are limited to 73 characters.

  • When an exception class is created in Class Builder in which the interface IF_T100_MESSAGE is included, it is recommended that this is specified when creating the exception class by choosing With Message Class. This ensures that the constructor is generated immediately and as required. Otherwise, the constructor for exception texts is generated from OTR and must be generated again once it is included in the interface by choosing Utilities → Clean Up → Constructor in the menu.

  • 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. However, this is strongly discouraged because an exception should only be raised with specific texts when using the parameter TEXTID.

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.

Exception Texts from OTR

If the exception class does not implement the interface IF_T100_MESSAGE, texts stored in OTR (Online Text Repository) can be used. These texts can contain any number of placeholders. Each placeholder is represented by the name of an attribute from the exception class, which is enclosed by "&" characters. When the exception is raised, the placeholders are replaced by the content of the attributes.

Exception texts can be freely defined on the Texts tab page of Class Builder and are stored with a UUID in OTR when they are saved. The constants created for each exception text have the data type SOTR_CONC from ABAP Dictionary and contain this UUID.

The input parameter TEXTID of the instance constructor is also of data type SOTR_CONC. When an exception with these exception texts is raised, a UUID that identifies a text from OTR can be passed to the constructor. It is strongly recommended that only the constants that exist in the class for the predefined exception texts are passed. This selects a predefined text for the exception. The attributes assigned to the placeholders of the text can be assigned values using the input parameters of the same name of the instance constructor.


Notes

  • Texts from OTR should mainly be used in system programs where text is not to be sent to the program user.

  • From a technical perspective, any UUID that specifies any text from OTR can also be passed to the input parameter TEXTID of the instance constructor. However, this is strongly discouraged because an exception should only be raised with specific texts.