Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How can I catch the exception type c = type i?

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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.

5 REPLIES 5

Former Member
0 Kudos

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.

Former Member
0 Kudos

This message was moderated.

Former Member
0 Kudos

hi, thanks for ur ans.

can i handle the same using

try

catch ?

kind regards,

Faisal

0 Kudos

Yes you can, If you are using multiple catch statements then we can use with in try and endtry block

BMEIJS
Active Participant
0 Kudos

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.