SAP EXCEPTION TEXTS T100



Get Example source ABAP code based on a different SAP table
  



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 to use the messages 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 the ABAP Dictionary. The individual components represent the message class, the message number, and the attributes assigned to the placeholders.
BEGIN_SECTION VERSION 5 OUT The maintenance of the exception texts depends on the tool:
Exception texts can be created on the Texts tab in the Class Builder in the 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. The Class Builder creates the associated constant structure in the public visibility section with the name of the exception text and generates a suitable instance constructor.
END_SECTION VERSION 5 OUT
In the ABAP Development Tools (ADT), exception texts are maintained in the source code. An exception class is defined by inheriting from one of the superclasses CX_STATIC_CHECK, CX_DYNAMIC_CHECK, or CX_NO_CHECK. Such classes implement 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, whose components 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 also refers to SCX_T100KEY. When an exception with messages as exception texts is raised, the constructor can be passed a structure with information about the message that is 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 that are assigned to the placeholders 1 to 4 or of a message can be supplied with 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.



Latest notes:

Exception texts that are linked to messages can be sent to the program user using the statement MESSAGE oref when the exception is handled.
The system interface IF_T100_DYN_MSG , which includes IF_T100_MESSAGE, can be used to link any message with an exception class. See Exception Classes for Messages.
The method GET_LATEST_T100_EXCEPTION in the class CL_MESSAGE_HELPER returns the last object in a chain of exception objects, which was created using 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.
A where-used list for a message contains its usage as an exception text in an exception class. But it does not contain the positions, where the specification of the message is passed in a structure of type SCX_T100KEY to the instance constructor of an exception class.
NON_V5_HINTS
When an exception class is created in the Class Builder and the interface IF_T100_DYN_MSG and hence IF_T100_MESSAGE is to be included in the class, it is recommended that this is specified 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 regenerated by choosing Utilities -> Clean Up -> Constructor after a subsequent inclusion of the interface.
ABAP_HINT_END

ABAP_EXAMPLES_ABEXA
See system interface IF_T100_MESSAGE in a global exception class.
See system interface IF_T100_DYN_MSG in a global exception class.
The exception classes of the package SABAP_DEMOS_CAR_RENTAL_EXCPTNS , which is part of a sample application created in the superpackage SABAP_DEMOS_CAR_RENTAL , use messages as exception texts. See CX_DEMO_CR_CAR_MODIFY, for example.
ABAP_EXAMPLE_END