Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

exception

Former Member
0 Kudos
116

can anybody tell about the exception handling in abap and its importance in case of function modules.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
71

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^

1 REPLY 1

Former Member
0 Kudos
72

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^