SAP Virtual/Onsite Trainings

Document Categories:

What's New?

Contribute?

Sample Specs

What's Hot?

Web Dynpro for ABAP Tutorials 


Join the Mailing List
Enter name and email address below:
Name:
Email:
Subscribe  Unsubscribe 

Exception Classes in Object Oriented Programming

...Previous

Step 6:

To Insert Exception Texts from Message Classes Choose “Texts” tab in the class builder.

Then Place the cursor on the default Exception ID “ZCX_EXCEP_CLS” and then click on the 

Step 7:

Popup will be displayed.  Enter Message Class “ZEXC_MSG” and Message Number “000”.

Step 8:

If you want parameterized Exception Texts, assign the attributes of an Exception Class to the placeholders that exist in attributes tab of exception class.

Placeholders (‘&’) created here can be dynamically be populated when runtime exceptions are created using ABAP values via exception class attributes.

Here I assigned MSGV1, MSGV2, MSGV3 and MSGV4 to the placeholders.

Click on button.

Step 9:

The values of the attributes belonging to exception will be linked to a text from message class.

‘&’ will be replaced with corresponding values of attributes (i.e. MSGV1, MSGV2, MSGV3 and MSGV4) defined in parameterized exceptions in STEP 7.

Save and active the Exception class

Note:  Exception texts are generally language-specific and have to be translated.

Step 10:

Calling Exception Class inside the program to handle exceptions

Ex:

DATA: ex_ref TYPE REF TO cx_root.
DATA: message_text TYPE string.

TRY.
    RAISE EXCEPTION TYPE zcx_excep_cls
                EXPORTING msgv1 = 'For'
                                      msgv2 = 'Handling'
                                      msgv3 = 'Exceptions '
                                      msgv4 = 'In Program '.

  CATCH zcx_excep_cls INTO ex_ref.
    message_text = ex_ref->get_text( ).
    WRITE message_text.
ENDTRY.

Output:

‘&’ will be replaced with the texts assigned to attributes (MSGV1, MSGV2, MSGV3 and MSGV4) of exception class.

Step 11:

While creating Exception class, uncheck the “With Message Class” check box, if you want to create new exceptions texts.

The texts will be created and stored in the text management OTR. It is not possible to use both text variants in an exception class.

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image