10-02-2007 12:28 PM
Hello.
Here is the problem:
Function_1 calls Function_2 without providing exceptions in the call. Function_2 raises an exception (message e(xxx) raising yyy) and because it isnt handled by function_1 a nasty error message is displayed.
Question - how to catch that error message when calling function_1?
Even more - I am not sure wether other errors that arent treated in the code may pop up during the function module execution. It there a proof way to catch all of them?
I was considering TRY/CATCH but Im not sure about the exact usage of this block in this particular case.
Thanks for your help.
10-02-2007 12:50 PM
TRY/CATCH it's not applicable in case of Function Module, to use TRY you need class-based exceptions.
Use only CATCH:
CATCH.
CALL FUNCTION "Function_1".
IF sy-subrc NE 0.
do_something.
ENDIF.
ENDCATCH.
However, you can add the "EXCEPTIONS" statement to the first CALL FUNCTION, catching a particular value of sy-subrc, like this:
EXCEPTIONS others = 20.
Then, check subrc:
CATCH.
CALL FUNCTION "Function_1"
EXCEPTIONS others = 20.
IF sy-subrc = 20.
do_something.
ENDIF.
ENDCATCH.
Hope this helps,
R.
10-02-2007 12:50 PM
TRY/CATCH it's not applicable in case of Function Module, to use TRY you need class-based exceptions.
Use only CATCH:
CATCH.
CALL FUNCTION "Function_1".
IF sy-subrc NE 0.
do_something.
ENDIF.
ENDCATCH.
However, you can add the "EXCEPTIONS" statement to the first CALL FUNCTION, catching a particular value of sy-subrc, like this:
EXCEPTIONS others = 20.
Then, check subrc:
CATCH.
CALL FUNCTION "Function_1"
EXCEPTIONS others = 20.
IF sy-subrc = 20.
do_something.
ENDIF.
ENDCATCH.
Hope this helps,
R.
10-02-2007 12:57 PM
hi
good
you cant use the try/catch i would suggest you to better use the statement like
if SY-SUBRC EQ 0.
MESSGE MESSID NO.
ENDIF.
In this way you can display your own message if there is any problem while function_1 calls the function_2.
thanks
mrutyun^
10-02-2007 1:11 PM
Hmm...
I see a problem with EXCEPTIONS.
First - Function_1 doesn't have any exceptions in the interface even though function_2 does.
Secondly - as soon as function_2 issues error message everything is stopped and I am not getting back to initial program to process the sy-subcr.
Or am i missing something?
10-02-2007 1:11 PM
Welcome to SDN.
You won't be able to handle the exception raised by Function_2 unless you can change Function_1. Function_1 needs to map all of the potential exceptions raised by Function_2 to return codes and map them to its own exceptions, which you can then map and handle when you call Function_1.
The exception can only be handled by the direct calling code, in this case Function_1.
Regards,
Nick
10-02-2007 1:58 PM
10-02-2007 2:54 PM
Hmmm
Looks like I have the answer.
Just call function_1 with "error_message" EXCEPTION even if FM itself doesn't have any exceptions in the interface.
CALL FUNCTION 'FUNCTION_1'
EXCEPTIONS
error_message = 01.
function_1 will return subrc=1 and relevant message data if function_2 raises any exception
Message was edited by:
Jurijs Tolokoncevs
10-02-2007 3:04 PM
Well done, it's even there in the ABAP help if you look really hard.
Proves (as if proof were needed) that I don't know as much as I think I do
Regards,
Nick