‎2010 Mar 15 12:04 PM
Hi,
I'm performing a LOOP at table. ENDLOOP. Within the loop I have a TRY. ENDTRY. CATCH. This is so I can perform a arithmatic statement and catch any errors. The problem is, if an error occurs it exits the LOOP. I don't want to exit the entire LOOP statement. I just want to continue on with the next record in my internal table. But instead, the loop is exited.
Any ideas?
Example code:
LOOP AT t_pcts ASSIGNING <wa_pcts>.
TRY.
<wa_pcts>-percent = <wa_pcts>-expprod / <wa_pcts>-actprod.
CATCH cx_root INTO oref.
text = oref->get_text( ).
ENDTRY.
ENDLOOP.
‎2010 Mar 15 12:41 PM
Hi,
check if your program is activated. TRY CATCH in LOOP works fine.
For my program:
DATA gt_vbrp TYPE TABLE OF vbrp WITH HEADER LINE.
APPEND INITIAL LINE TO gt_vbrp.
APPEND INITIAL LINE TO gt_vbrp.
APPEND INITIAL LINE TO gt_vbrp.
LOOP AT gt_vbrp.
TRY.
gt_vbrp-fkimg = 100 / gt_vbrp-fkimg.
CATCH cx_root.
WRITE: / 'Exception'.
ENDTRY.
WRITE: / sy-tabix.
ENDLOOP.
I get correct result:
Exception
1
Exception
2
Exception
3
Program does not interrupt the loop.
Regards,
--
Przemysław
‎2010 Mar 15 12:41 PM
Hi,
check if your program is activated. TRY CATCH in LOOP works fine.
For my program:
DATA gt_vbrp TYPE TABLE OF vbrp WITH HEADER LINE.
APPEND INITIAL LINE TO gt_vbrp.
APPEND INITIAL LINE TO gt_vbrp.
APPEND INITIAL LINE TO gt_vbrp.
LOOP AT gt_vbrp.
TRY.
gt_vbrp-fkimg = 100 / gt_vbrp-fkimg.
CATCH cx_root.
WRITE: / 'Exception'.
ENDTRY.
WRITE: / sy-tabix.
ENDLOOP.
I get correct result:
Exception
1
Exception
2
Exception
3
Program does not interrupt the loop.
Regards,
--
Przemysław
‎2010 Mar 15 12:45 PM
You can also use 'CONTINUE' after the CATCH statement I discovered.
‎2010 Mar 15 12:46 PM
Hi,
CONTINUE after CATCH is unnecessary - program is processing next row automatically.
Regards,
--
Przemysław