0% found this document useful (0 votes)
389 views4 pages

Exceptions in Oops Abap

This document outlines the steps for raising and catching exceptions in OOPS ABAP: 1. Create an exception class in SE24 and define exception IDs and texts. 2. Create a method class with importing and exporting parameters, select the exception class, and raise exceptions where needed. 3. Catch exceptions in a TRY-CATCH block, get the exception text using GET_TEXT, and display the message. Alternatively, exceptions can reference a message class created in SE91 for centralized exception texts. The exception class is configured to use the message class, and raising exceptions will retrieve texts from it.

Uploaded by

abhy17
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
389 views4 pages

Exceptions in Oops Abap

This document outlines the steps for raising and catching exceptions in OOPS ABAP: 1. Create an exception class in SE24 and define exception IDs and texts. 2. Create a method class with importing and exporting parameters, select the exception class, and raise exceptions where needed. 3. Catch exceptions in a TRY-CATCH block, get the exception text using GET_TEXT, and display the message. Alternatively, exceptions can reference a message class created in SE91 for centralized exception texts. The exception class is configured to use the message class, and raising exceptions will retrieve texts from it.

Uploaded by

abhy17
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

EXCEPTIONS IN OOPS ABAP

STEPS FOR RAISING AND CATCHING EXCEPTIONS STEP 1 : Create an exception class in SE24 . Go to SE24 . Give a name ZCX_EXCEPTION_CLASS . Create & save it . Go to TEXT TAB and define exception id and text .

EXCXEPTION No_kunnr Invalid_kunnr Invalid_kunnr2 please enter a customer number . This is invalid customer . & kunnr& is an invalid customer .

NOTE : For every EXCEPTION ID , an ATTRIBUTE will be created . STEP 2 : Create a normal class with a method . Create a method with name GET_CUST_DET with IMPORTING IM_KUNNR and EXPORTING EX_kna1 . Click on EXCEPTIONS BUTTON and Select EXCEPTION CLASS CHECKBOX . Now define an EXCEPTION CLASS which Created previously . Write the ABAP code and raise the Exception where ever necessary . IF IM_KUNNR IS INITIAL . RAISE EXCEPTION TYPE ZCX_EXCEPTION_CLASS . EXPORTING TEXTID = ZCX_EXCEPTION_CLASS=> NO_KUNNR . ELSE . SELECT abap code . . IF SY-SUBRC <>0 RAISE EXCEPTION TYPE ZCX_EXCEPTION_CLASS . EXPORTING TEXTID = ZCX_EXCEPTION_CLASS=> INVALID_KUNNR >

KUNNR = IM_KUNNR . ENDIF . ENDIF . STEP3 : CATCHING THE EXCETIONS . Exception should be handled using TRY ..CATCHEND TRY . If an Exception is Raised it is caught in the exception calss . So , for this class we should create an object . Once an object is created , call the method GET_TEXT which gives the TEXT of an EXCEPTION ID

CREATE AN ABAP PROGRAM AND CALL THE ABOVE METHOD . ABAP PROGRAM : DATA : OBJ TYPE REF TO ZCL-SAMPLE . DATA : OBJ_EXC TYPE REF TO ZCX_EXCEPTION_CLASS . DATA : V_MESSAGE TYPE STRING . TRY . CALL METHOD OBJ GET_CUST_DET . EXPORTING IM_KUNNR = P_KUNNR . IMPORTING EX_KNA1 = WA_KNA1 . CATCH ZCXEXCEPTION_CLASS INTO OBJ_EXC. CALL METHOD OBJ_EXC IF_MESSAGE ~GET_TEXT . RECEIVING RESULT = V_MESSAGE . MESSAGE ENDTRY . V_MESSAGE TYPE E .

EXCEPTION CLASS USING MESSAGE CLASS . STEP 1 : SE91 is TCODE for creating Message class . Define all the messages in this class . Message no 000 001 002 .. 999 . Click mon save . STEP 2 : Create an exception class . Give a name ZCX_EXCEPTION_CLASS . Select the Message Class CheckBox . Click on save . Click on TEXT TAB . Define the three exception i.e NO_KUNNR . INVALID_KUNNR INVALID_KUNNR2 with out any text because we want to get the text from Message Class(SE91) . Declare an Attribute KUNNR . Put the cursor on the first exception NO_KUNNR and click on MESSAGE_TEXT button . Provide Message Class name and Message Class number . Repeat the same for the second exception (INVALID_KUNNR) and third exception (INVALID_KUNNR2) . Click on the exception INVALID_KUNNR2 and click on Message TEXT button and provide message class number . Message short text INVALID_KUNNR NO_KUNNR & IS INAVLID KUNNR

Select attribute from the drop down i.e. KUNNR . Save & Activate . Now Raise the Message in the class methods and catch them in ABAP program .

You might also like