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: 

which exception should i use in order to overcome short dump for my requirement?

arumallaanusha
Explorer

i would like to compare string or character field with 0

ex: data lv1 type string value 'hai'.

TRY.

IF lv1 > 0.

ENDIF.

catch cx_sy_arithmetic_error .

ENDTRY.

I tried different standard exception clases but i am unable to solve the isssue.

could any one help me to solve this error.

i attached the dump screenshot.

dump.png

thanks in advance

anusha

10 REPLIES 10

developerone
Contributor
0 Kudos

Have you tried CX_ROOT?

Sandra_Rossi
Active Contributor

If your short dump doesn't indicate the name of an exception class (usually CX_SY_* for basic errors), then there's no exception class you can handle. So, before comparing or assigning a string to a number, make sure the string contains only numeric characters (if lv1 CO '0123456789' for instance).

DoanManhQuynh
Active Contributor
0 Kudos

I think abap is not compare between string and number => there is no exception class handle it. if you want to compare like that, put 0 in '', it will compare string with string.

0 Kudos

how it will compare lv1 > '0'.

ex:

DATA: lv1 TYPE string VALUE 'hgfdvgs',
lv2 TYPE dec10.
TRY.
IF lv1 > '0'.
DATA(lv_result) = sqrt( lv1 ).
WRITE: 'squareroot of a number', lv_result.
ELSE.
WRITE:'Square root for negative value can not be obtained'..
ENDIF.
CATCH cx_sy_conversion_no_number INTO data(error_ref).
data(err_text) = error_ref->get_text( )..
WRITE:err_text.
ENDTRY.

0 Kudos

Anusha anusha as I said, "make sure the string contains only numeric characters (if lv1 CO '0123456789' for instance)."

Anusha anusha

You can read it in Comparition Rules in F1 Help:

If the comparison type is one of the character-like data types, the content is compared from left to right. Based on the internal binary representation in the code page used, the first differing character from the left determines which operand is greater.

You should also consider Sandra comment because naturally we dont compare text with number. what i suggested is to overcome your error only.

Comparing 2 numbers expressed as text data objects is usually the wrong way to do it, generally speaking. For instance '2' > '10' is true because it compares character by character from left to right, first '2' to '1' is true so it stops. '+5' > '0' is false for the same reason, because '+' (Unicode U+002B) is lower than '0' (Unicode U+0030).

Thanks Sandra Rossi

I know its the wrong way to compare text and number like that, already mentioned in above comment. the main answer is there is no exception class for that, the alternative is put 0 in quote (just for this specific case) and the recommend to do the compare is check the string have only number as your answer, thats what i mean 🙂

Tomas_Buryanek
Active Contributor

First try move string to numeric variable (conversion can be caught in cx_sy_arithmetic_error exception). And after that you can do comparison (num_variable > 0). Comparison dump can not be caught.

-- Tomas --

NTeunckens
Active Contributor

Either use the "MOVE" as suggested by tomas.buryanek#overview before the logical expression, as in the SAP-Help examples ...

Or just check whether your value actually "IS NUMERIC" before proceeding :

DATA lv1 TYPE string VALUE 'hai'.
TRY.
    IF cl_dba_format=>is_numeric( lv1 ).
      IF lv1 > 0.
      ENDIF.
    ELSE.
      WRITE 'Not numeric!'.
    ENDIF.
  CATCH cx_sy_arithmetic_error INTO DATA(excp).
    DATA(msgtxt) = excp->get_text( ).
    WRITE msgtxt.
ENDTRY.