2007 Dec 05 1:15 PM
can anybody tell about the exception handling in abap and its importance in case of function modules.
2007 Dec 05 1:19 PM
hi
good
Check this:
... EXCEPTIONS except1 = rc1 ...exceptn = rcn
Effect
EXCEPTIONS lists the exceptions to be handled by the calling program itself. At the end of the exception list, you can use OTHERS to refer to all the remaining exceptions.
If one of the listed exceptions occurs, SY-SUBRC is set to the appropriate value rc (a numeric literal!) and control passes back to the calling program. By specifying a return code, you can divided the exceptions into classes. With the second form, without "=rc", SY-SUBRC is set to a value other than 0 if an exception occurs.
If the function module triggers an exception (with the statements RAISE and MESSAGE ... RAISING) and the exception is not to be handled by the calling program itself,
RAISE terminates the program with a runtime error;
MESSAGE ... RAISING outputs the message.
Note
The following EXCEPTIONS are predefined by the system and have a special meaning:
OTHERS: Covers all user-defined exceptions in the called function module.
ERROR_MESSAGE: This exception instructs the system to ignore S messages, I messages and W messages until return from the function module (although they still appear in the log during background processing). When an E message or an A message occurs, the called function module terminates, as if the exception ERROR_MESSAGE has been triggered.
Example
DATA: WA_SFLIGHT TYPE SFLIGHT,
P_LOSS LIKE SFLIGHT-PAYMENTSUM,
P_REVENUE LIKE SFLIGHT-PRICE,
P_CARRID LIKE SFLIGHT-CARRID.
...
SELECT * FROM SFLIGHT INTO WA_SFLIGHT WHERE CARRID = P_CARRID ... .
CALL FUNCTION 'CALCULATE_REVENUE_LOSS'
EXPORTING
PAYMENTSUM = WA_SFLIGHT-PAYMENTSUM
SEATSOCC = WA_SFLIGHT-SEATSOCC
PRICE = WA_SFLIGHT-PRICE
IMPORTING
LOSS = P_LOSS
REVENUE = P_REVENUE
EXCEPTIONS
OTHERS = 1.
...
ENDSELECT.
...
Example
TABLES SFLIGHT.
DATA: ITAB TYPE STANDARD TABLE OF BCAXX WITH
NON-UNIQUE DEFAULT KEY INITIAL SIZE 10.
P_YEAR ... .
CALL FUNCTION 'FILL_SEATTAB'
EXPORTING
YEAR = P_YEAR
TABLES
SEATTAB = ITAB
EXCEPTIONS
NO_ENTRY = 1
OTHERS = 2.
CASE SY-SUBRC.
WHEN 1. ...
WHEN 2. ...
ENDCASE.
thanks
mrutyun^
2007 Dec 05 1:19 PM
hi
good
Check this:
... EXCEPTIONS except1 = rc1 ...exceptn = rcn
Effect
EXCEPTIONS lists the exceptions to be handled by the calling program itself. At the end of the exception list, you can use OTHERS to refer to all the remaining exceptions.
If one of the listed exceptions occurs, SY-SUBRC is set to the appropriate value rc (a numeric literal!) and control passes back to the calling program. By specifying a return code, you can divided the exceptions into classes. With the second form, without "=rc", SY-SUBRC is set to a value other than 0 if an exception occurs.
If the function module triggers an exception (with the statements RAISE and MESSAGE ... RAISING) and the exception is not to be handled by the calling program itself,
RAISE terminates the program with a runtime error;
MESSAGE ... RAISING outputs the message.
Note
The following EXCEPTIONS are predefined by the system and have a special meaning:
OTHERS: Covers all user-defined exceptions in the called function module.
ERROR_MESSAGE: This exception instructs the system to ignore S messages, I messages and W messages until return from the function module (although they still appear in the log during background processing). When an E message or an A message occurs, the called function module terminates, as if the exception ERROR_MESSAGE has been triggered.
Example
DATA: WA_SFLIGHT TYPE SFLIGHT,
P_LOSS LIKE SFLIGHT-PAYMENTSUM,
P_REVENUE LIKE SFLIGHT-PRICE,
P_CARRID LIKE SFLIGHT-CARRID.
...
SELECT * FROM SFLIGHT INTO WA_SFLIGHT WHERE CARRID = P_CARRID ... .
CALL FUNCTION 'CALCULATE_REVENUE_LOSS'
EXPORTING
PAYMENTSUM = WA_SFLIGHT-PAYMENTSUM
SEATSOCC = WA_SFLIGHT-SEATSOCC
PRICE = WA_SFLIGHT-PRICE
IMPORTING
LOSS = P_LOSS
REVENUE = P_REVENUE
EXCEPTIONS
OTHERS = 1.
...
ENDSELECT.
...
Example
TABLES SFLIGHT.
DATA: ITAB TYPE STANDARD TABLE OF BCAXX WITH
NON-UNIQUE DEFAULT KEY INITIAL SIZE 10.
P_YEAR ... .
CALL FUNCTION 'FILL_SEATTAB'
EXPORTING
YEAR = P_YEAR
TABLES
SEATTAB = ITAB
EXCEPTIONS
NO_ENTRY = 1
OTHERS = 2.
CASE SY-SUBRC.
WHEN 1. ...
WHEN 2. ...
ENDCASE.
thanks
mrutyun^