Application Development and Automation 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: 
Read only

Exception in Function Module

Former Member
0 Likes
653

Hi,

How to use exception in Function module ?

How Can I use the exception my program while calling the Function Module ?

Can anyone explain with example ?

Thanks

NK

3 REPLIES 3
Read only

Former Member
0 Likes
505

HI,

RAISE .

If the exception is listed in the calling program, the system returns control to it directly. If the exception is not listed, a runtime error occurs.

MESSAGE () RAISING .

If the exception is listed in the calling program, the statement has the same effect as RAISE . If it is not listed, the system sends message from message class with type , and no runtime error occurs.

Function modules differ from subroutines in that you must assume that they will be used by other programmers.

Please refer to the link below :

http://help.sap.com/saphelp_nw70/helpdata/en/9f/db98fc35c111d1829f0000e829fbfe/content.htm

Thanks,

Sriram Ponna.

Read only

Former Member
0 Likes
505

Declare your exception in the exceptions tab in FM

say (NOT_FOUND)

and in the coding in FM .. write

RAISE NOT_FOUND. <-- If NOT_FOUND is the exception declared ..

When U call the FM in your program ..

U'll get as

call function '<function module name>'

exporting ..

importing ..

EXCEPTIONS

NOT_FOUND = 1

OTHERS = 2

U can check with sy-subrc ... to know the exception

Read only

Former Member
0 Likes
505

HI,

if something happens in ur FM and u want it to be tracked in ur calling program, then u can use exception...............

If u r having(say) 3 exceptions in ur FM....

and in ur calling program its like below.

EXCEPTIONS
  exception1 = 1
  exception2 = 2
  exception3 = 3

then if the first exception is raised in ur FM,then sy-subrc value ll be 1( exception1 = 1 )....llly if the second exception is raised in ur FM,then sy-subrc value ll be 2( exception2 = 2 ).........

now u can use this sy-subrc values like below....

If sy-subrc = '1'.
message 'First exception is raised' type 'I'.
else.
message '2nd or 3rd exception is raised' type 'I'.
endif.

Cheers,

jose.