‎2007 Sep 13 1:26 PM
‎2007 Sep 13 1:28 PM
Hi,
catch command we will use for handling the exceptions.
see this link for more help
http://help.sap.com/saphelp_nw04/helpdata/en/a9/b8eef8fe9411d4b2ee0050dadfb92b/content.htm
<b>example:</b>
parameters NUMBER type I.
data RESULT type P decimals 2.
data OREF type ref to CX_ROOT.
data TEXT type STRING.
start-of-selection.
write: / 'Testing division and Sqare root with', NUMBER.
uline.
try.
if ABS( NUMBER ) > 100.
raise exception type CX_DEMO_ABS_TOO_LARGE.
endif.
try.
RESULT = 1 / NUMBER.
write: / 'Result of division:', RESULT.
RESULT = SQRT( NUMBER ).
write: / 'Result of square root:', RESULT.
catch CX_SY_ZERODIVIDE into OREF.
TEXT = OREF->GET_TEXT( ).
cleanup.
clear RESULT.
endtry.
catch CX_SY_ARITHMETIC_ERROR into OREF.
TEXT = OREF->GET_TEXT( ).
catch CX_ROOT into OREF.
TEXT = OREF->GET_TEXT( ).
endtry.
if not TEXT is initial.
write / TEXT.
endif.
write: / 'Final result:', RESULT.
rgds,
bharat.
‎2007 Sep 13 1:32 PM
Hi
Catch commands are used to catch the errors.
Depending on whether your report has the flag "Unicode-enabled" set or not you will get a different result of the syntax check (SLIN) for statement
s_struc-t_table = itab1.
- Unicode-enabled = 'X': => syntax error if the structures do not match exactly
- Unicode-enabled = ' ': => perhaps no syntax error but system-exceptions due to type conversion errors possible
In the latter case you would use the following statement:
CATCH SYSTEM-EXCEPTIONS <type conversion error> = 1.
s_struc-t_table = itab1.
...
ENDCATCH.
However, please note that the CATCH SYSTEM-EXCEPTIONS is different from class-based exception handling because this statement does not return any error object.
Regards
Vasu