Application Development and Automation 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: 
Read only

problem with TRY......ENDTRY

Former Member
0 Likes
1,758

REPORT.

DATA:

w_char(4) TYPE c VALUE '9,00',

w_num(4) TYPE n,

w_int TYPE i VALUE 10,

oref TYPE REF TO cx_root,

text TYPE string.

TRY.

IF w_int > w_char.

ENDIF.

CATCH cx_sy_conversion_no_number INTO oref.

text = oref->get_text( ).

CATCH cx_root into oref.

CLEANUP.

CLEAR w_int.

ENDTRY.

*CATCH SYSTEM-EXCEPTIONS convt_no_number = 1.

  • IF w_int > w_char.

  • ENDIF.

*ENDCATCH.

*IF sy-subrc EQ 1.

  • WRITE:w_int.

*ENDIF.

WRITE:/ w_int,

/ text.

Inspite of catching the exceptions the code goes for a dump, any help will be highly appreciated.

1 ACCEPTED SOLUTION
Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
1,473

HI,

Make the value as '9.00' instead of '9,00'.

Since its a run time exception and the exception raised is not a CLass based exception you are not able to handle it.

Regards,

Sesh

8 REPLIES 8
Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
1,474

HI,

Make the value as '9.00' instead of '9,00'.

Since its a run time exception and the exception raised is not a CLass based exception you are not able to handle it.

Regards,

Sesh

Read only

0 Likes
1,473

Sai,

The code snippet below works fine however !?

REPORT.

DATA:

w_char(4) TYPE c VALUE '9,00',

w_num(4) TYPE n,

w_int TYPE i VALUE 10,

oref TYPE REF TO cx_root,

text TYPE string.

TRY.

<b>w_int = w_char.</b>

CATCH cx_sy_conversion_no_number INTO oref.

text = oref->get_text( ).

CATCH cx_root into oref.

CLEANUP.

CLEAR w_int.

ENDTRY.

WRITE:/ w_int,

/ text.

Read only

0 Likes
1,473

Hi,

Here you are just trying to assign a worng value to the INT type.

SO this is just giving an error that this assignment is not possible and conversion is not possible and a class based exception is raised and your handled it.

Where as in the previous case you were trying to check a logical condition, in the case of logical condition before you check the condition one of the operands will be converted to the other's type. So this conversion which was done by Runtime internally was rasining an exception which we cannot handle.

So in your case you are your self trying to CONVERT, in the previous case the SYSTEM is trying to convert it , so the source of exception is different in both the cases so if the source of exception is you it will let you handle it else it has to dump.

Hope my explaination is good enough to satisfy you

Regards,

Sesh

.

Read only

0 Likes
1,473

Thank you Sai, ur explanation is good enough, so can I conclude there is no solution(exception handling) to my problem?

Read only

Former Member
0 Likes
1,473

I had changed your logic .... please use the below one it was working fine ..

  REPORT  ZTSTEWR.
PARAMETERS number TYPE i.
DATA: result TYPE p LENGTH 8 DECIMALS 2,
      oref   TYPE REF TO cx_root,
      text   TYPE string.

TRY.
    IF ABS( number ) > 100.
      RAISE EXCEPTION TYPE cx_demo_abs_too_large.
    ENDIF.
    PERFORM calculation USING    number
                      CHANGING result
                               text.
  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.

FORM calculation USING    p_number LIKE number
                 CHANGING p_result LIKE result
                          p_text   LIKE text
                          RAISING  cx_sy_arithmetic_error.

  DATA l_oref TYPE REF TO cx_root.

  TRY.
      p_result =   p_number.
*      WRITE: / 'Result of division:', p_result.
*      p_result = SQRT( p_number ).
    CATCH cx_sy_zerodivide INTO l_oref.
      p_text = l_oref->get_text( ).
    CLEANUP.
      CLEAR p_result.
  ENDTRY.

ENDFORM.

reward points if it is usefull .....

Girish

Read only

0 Likes
1,473

Girish,

I've tried the code below but in vain, I had a good look at the link below

http://help.sap.com/saphelp_nw04/helpdata/en/a9/b8eef8fe9411d4b2ee0050dadfb92b/content.htm,

tried several options, nothing seem to work.

REPORT z_test1.

DATA:

w_char(4) TYPE c VALUE '9,00',

w_num(4) TYPE n,

w_int TYPE i VALUE 10,

oref TYPE REF TO cx_root,

text TYPE string.

TRY.

IF w_int > w_char.

RAISE EXCEPTION TYPE cx_sy_conversion_no_number.

ENDIF.

CATCH cx_sy_conversion_no_number INTO oref.

text = oref->get_text( ).

CATCH cx_root into oref.

CLEANUP.

CLEAR w_int.

ENDTRY.

Read only

0 Likes
1,473

hi,

u r comparing a string to a number. so u might get short dump there. so there r 2 options

1. declare that no as a numeric[ allws only character strings] and compare

2. or make that character string as a number and compare to number parameter.

if useful reward some points.

with regards,

Suresh.A

Read only

0 Likes
1,473

Hi Suresh,

both the options mentioned are not possible in my case as i'm using this code in user-exit MV45AFZB to compare the value of xkomv-kbetr with a value from variant variable table (TVARVC-LOW).

any inputs will be highly appreciated

Message was edited by:

Rajesh