‎2007 Jul 16 7:06 AM
Dear Abapers,
I need some help in Try/End Try block. My requirement is that I need to check out of 3 FM's which exists in the system and depending on the FM which exists I need to set a particular flag and call that FM.
So can I try some algorithm like this.
TRY
CALL FM1
Catch
TRY CALL FM2
catch CALL FM 3
ENDTRY.
I need to know how to use multiple try...end try blocks...
Please let me know, it would be of great help.
Thanks & Warm Regards, Vinay
‎2007 Jul 16 7:12 AM
Hi,
Execute a select query on the table with List of FM's and then based on that call your FM.
You need to se TRY ENDTRY. Just check SY-SUBRC after the select query.
<b><b>DATA: WA_TFDIR TYPE TFDIR.
SELECT * FROM TFDIR INTO WA_TFDIR WHERE FUNCNAME = 'FM NAME1'.</b>
IF Sy-SUBRC = 0.
CALL FM.
ELSE.
SELECT * FROM TFDIR INTO WA_TFDIR WHERE FUNCNAME = 'FM NAME2'.
IF Sy-SUBRC = 0.
CALL FM.
ELSE.
SELECT * FROM TFDIR INTO WA_TFDIR WHERE FUNCNAME = 'FM NAME3'.
IF Sy-SUBRC = 0.
CALL FM.
ENDIF.
ENDIF.
ENDIF.</b>
Regards,
Sesh
‎2007 Jul 16 7:16 AM
‎2007 Jul 16 7:19 AM
just use the following code
try .
call fm1.
try .
call fm2.
try .
call fm3.
catch .
catch .
catch.
this what ua call nested try catch blocks. try it it will solvw the prob.
‎2007 Jul 16 7:23 AM
Hi,
*Syntax for TRY .. ENDTRY construct
TRY.
CALL METHOD o1->m1.
PERFORM f1.
CATCH cx_root. "Handler for all exceptions
" ABAP code(What to do when error occures)........
ENDTRY.
FORM f1 RAISING cx_my.
TRY.
IF ...... RAISE EXCEPTION TYPE cx_my2. ENDIF.
CALL METHOD o1->m3.
CATCH cx_my1 cx_my3 INTO ex.
RAISE EXCEPTION TYPE cx_my4.
CATCH cx_my4.
"Handler for exceptions of type cx_my4
" ABAP code(What to do when error occures)........
CLEANUP.
"Cleanup section, used to restore to a consistant state
" ABAP code........
ENDTRY.
ENDFORM.
Pls do reward points.
Regards,
Ameet