ARTICLE
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 GET_TEXT method. If
applicable, the long text can be read using the GET_LONG_TEXT
method.
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 the
OTR (Online Text Repository). See below for more information.
For each exception text, Class Builder creates a static constant in the
exception class with the same name as the exception text. When the
exception is raised, this can be passed to the TEXTID parameter
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.
ABAP_PGL Create suitable exception
texts in the exception class and only use these texts
Note
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 in order to determine the exception text.
Messages as Exception Texts
If the exception class implements the IF_T100_MESSAGE interface,
the short texts of messages in the
T100 database table can be used as exception texts. On the
Texts tab page of Class Builder, you can choose Message Text
to assign a message class and a
message number to each exception text
specified there; these assignments define the exception text. In
addition, placeholders "<(> <)>1" to "<(> <)>4" or "<(> <)>" of the
message can be assigned to attributes of the exception class. If 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
MESSAGE oref statement when the exception
is handled.
The constants created for each exception text have the structured data
type SCX_T100KEY from ABAP
Dictionary. The individual components are assigned the message class,
message number, and attributes assigned to the placeholders as defined
on the Texts tab page.
The TEXTID input parameter of the instance constructor is of data
type T100KEY of the IF_T100_MESSAGE interface, 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. We
strongly recommend that you only pass the constants that exist in the
class for the predefined exception texts, with a predefined text for the
exception being selected. 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 you create an exception class into which the IF_T100_MESSAGE
interface is to be integrated, we recommend that you specify this 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 the
OTR and must be generated again once it is integrated into 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 TEXTID input parameter of the instance constructor.
However, we strongly recommend against this because an exception should
only be raised with specific texts.
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 the OTR
If the exception class does not implement the IF_T100_MESSAGE
interface, texts stored in the 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. If 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 the 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 TEXTID input parameter 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 the OTR can
be passed to the constructor. We strongly recommend that you only pass
the constants that exist in the class for the predefined exception
texts, with a predefined text for the exception being selected. 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 the 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 the OTR can also be passed to the TEXTID input
parameter of the instance constructor. However, we strongly recommend
against this because an exception should only be raised with specific
texts.
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved