How to use Exception Texts in SAP ABAP

  1. Create an Exception class. The class inherits the standard SAP Exception Class such as CX_STATIC_CHECK.
  2. Add the necessary attributes in the Attributes Tab of the Exception class. The Level is generally defined as Instance Attribute and its visibility is Public.
  3. Add the Exception ID in the Texts Tab of the Exception class. Mention the Exception Text in the Text column. The Attributes included in the Exception Text refers to the added attributes in the attributes tab.

What happens in the Background when Texts ID (Exception text ) is added ?

An attribute is automatically created of type ‘ SOTR_CONC’ which is a static constant with public visibility. It can be under the Attributes Tab of the Class Builder.

The exception texts are used in ABAP progam using the constructor of the exception class. The parameters such as textid are passed. The other parameters such as attributes and previous are passed only when it is needed. The attributes refers to the attributes in the Exception text.

How can you make yourself clear with this Exception Texts

  1. In the class Builder under Texts Tabreiter : It is mentioned as Exception text.
  2. In the class Builder under Attributes Tabreiter : It is mentioned as Attribute. Below are its properties

Attribute : Exception Id

Level : Constant

Visibility : Public

Associated Type : SOTR_CONC

Initial Value : It will hold a random value

3. In the constructor of the exception class : It is mentioned as textid.

RAISE EXCEPTION NEW zcx_exception_class ( textid = zcx_exception_class => exception_id ) .

How to use Attributes in Exception Texts

  1. In the attributes tab of the Class Builder. Add the below instance attribute of respective type.

Attribute1

2. Mention the attributes in the Exception texts. This is done under the Texts Tab.

Exception Id | Text

exception_id | An Exception was raised from the class &Attribute1&

3. In the constructor of the Exception class, mention the Attribute along with the textid

RAISE EXCEPTION NEW zcx_exception_class ( textid = zcx_exception_class => exception_id

Attribute1 = attribute1_value ).

How to use previous in the Exception class constructor

TRY.

lt_check = throw_exception _1 ( ) .

CATCH zcx_exception_1 INTO DATA ( lx_exception_1).

RAISE EXCEPTION NEW zcx_exception_2 ( text_id = zcx_exception_2 => exception_id

Attribute1 = attribute_value

previous = lx_exception_1 ).

ENDTRY.