‎2008 Feb 27 11:16 AM
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
‎2008 Feb 27 11:21 AM
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.
‎2008 Feb 27 11:21 AM
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
‎2008 Feb 27 11:27 AM
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 = 3then 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.