11-01-2008 8:17 AM
How can I catch the exception and display the error message when I assign the u2018ABC123u2019 value to an int data type.
Code is as follow.
REPORT zfsl_sum_functions.
DATA: cin(50),
cout(50),
iin TYPE i,
iout TYPE i,
etext TYPE string.
cin = '123ABC'. " how can i catch this
iout = cin.
WRITE: iout.
11-01-2008 8:45 AM
You can try this
REPORT zfsl_sum_functions.
DATA: cin(50),
cout(50),
iin TYPE i,
iout TYPE i,
etext TYPE string.
cin = '123ABC'..
* CONVERSION_ERRORS contains CONVT_NO_NUMBER ***
CATCH SYSTEM-EXCEPTIONS CONVERSION_ERRORS = 1.
iin = cin.
ENDCATCH.
IF SY-SUBRC = 1.
write:/ 'error-> unable to interpret cin as integer'.
else.
write:/ iin.
ENDIF.
11-01-2008 8:45 AM
You can try this
REPORT zfsl_sum_functions.
DATA: cin(50),
cout(50),
iin TYPE i,
iout TYPE i,
etext TYPE string.
cin = '123ABC'..
* CONVERSION_ERRORS contains CONVT_NO_NUMBER ***
CATCH SYSTEM-EXCEPTIONS CONVERSION_ERRORS = 1.
iin = cin.
ENDCATCH.
IF SY-SUBRC = 1.
write:/ 'error-> unable to interpret cin as integer'.
else.
write:/ iin.
ENDIF.
11-01-2008 8:47 AM
11-01-2008 9:53 AM
hi, thanks for ur ans.
can i handle the same using
try
catch ?
kind regards,
Faisal
11-01-2008 11:00 AM
Yes you can, If you are using multiple catch statements then we can use with in try and endtry block
11-01-2008 11:19 AM
The CATCH-ENDCATCH statement is obsolete as of release was620. You should use TRY. CATCH. ENDCATCH.
The exception that will be raise is CX_SY_CONVERSION_NO_NUMBER, so you have to catch that exception or a super class of this exception class.
REPORT zfsl_sum_functions.
DATA: cin(50),
cout(50),
iin TYPE i,
iout TYPE i,
etext TYPE string.
DATA: rf_cx_error TYPE REF TO CX_SY_CONVERSION_NO_NUMBER,
errortxt TYPE string.
TRY.
cin = '123ABC'. " how can i catch this
iout = cin.
WRITE: iout.
CATCH CX_SY_CONVERSION_NO_NUMBER INTO rf_cx_error.
errortxt = rf_cx_error->get_text( ).
WRITE errortxt.
ENDTRY.