Skip to Content
author's profile photo Former Member
Former Member

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

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Nov 01, 2008 at 08: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.
    
    

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 01, 2008 at 08:47 AM

    This message was moderated.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 01, 2008 at 09:53 AM

    hi, thanks for ur ans.

    can i handle the same using

    try

    catch ?

    kind regards,

    Faisal

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 01, 2008 at 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.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.