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 CATCH CX_SY_CONVERSION_NO_NUMBER

Former Member
0 Likes
9,753

Hi,

i try this simple code and get allways a short dump with CONVT_NO_NUMBER.


DATA: WA_CHAR TYPE CHAR128 VALUE 'TEST'.
*
IF WA_CHAR = 0. WRITE: 'is 0'. ENDIF.

Then i try it with CATCH and get still the short dump.


DATA: WA_CHAR TYPE CHAR128 VALUE 'TEST'.
*
TRY.
    IF WA_CHAR = 0. WRITE: 'is 0'. ENDIF.
  CATCH CX_SY_CONVERSION_NO_NUMBER.
    WRITE: / 'ERROR'.
ENDTRY.

Has anyone an idea with mistake i do.

thanks.

Regards, Dieter

Hi,

i try this simple code and get allways a short dump with CONVT_NO_NUMBER.


DATA: WA_CHAR TYPE CHAR128 VALUE 'TEST'.
*
IF WA_CHAR = 0. WRITE: 'is 0'. ENDIF.

Then i try it with CATCH and get still the short dump.


DATA: WA_CHAR TYPE CHAR128 VALUE 'TEST'.
*
TRY.
    IF WA_CHAR = 0. WRITE: 'is 0'. ENDIF.
  CATCH CX_SY_CONVERSION_NO_NUMBER.
    WRITE: / 'ERROR'.
ENDTRY.

Has anyone an idea with mistake i do.

thanks.

Regards, Dieter

7 REPLIES 7
Read only

Former Member
0 Likes
4,384

Hi,

You have defined char type, you should always use character literals in comparision.

IF ld_char = '0'.

....

ENDIF.

Regards

Praveen

Read only

0 Likes
4,384

Dieter is wondering why he cannot catch the exception, not how to properly convert between types (which would be too basic and get locked...)

Thomas

Read only

ThomasZloch
Active Contributor
4,384

The way you're doing the conversion implicitely ("IF WA_CHAR = 0"), the exception is not assigned to a class and cannot be caught with TRY / CATCH / ENDTRY.

If you declare a number field and move the content from the character to the number field, then class CX_SY_CONVERSION_NO_NUMBER will be assigned. Compare the headings of the respective short dumps.

Thomas

Read only

Former Member
0 Likes
4,384

Hi,

If you want to avoid the dump write as :

IF WA_CHAR = '0'.

WRITE: 'is 0'.

ENDIF.

Regards,

Srini.

Read only

0 Likes
4,384

Hi,

thanks, but i will not avoid it by changing the statement.

I will catch this exception (as Thomas allready says).

Regards, Dieter

Read only

Former Member
0 Likes
4,384

Run the following code


DATA: WA_CHAR TYPE CHAR128 VALUE 'TEST'.
data oref TYPE REF TO cx_root.


TRY.
 RAISE EXCEPTION TYPE cx_sy_conversion_no_number.
    IF WA_CHAR = 0.
    RAISE EXCEPTION TYPE cx_sy_conversion_no_number.
    WRITE: 'is 0'.
    ENDIF.
  CATCH CX_SY_CONVERSION_NO_NUMBER into oref.
    WRITE: / 'ERROR'.
    CATCH cx_root into oref.
    CLEANUP.
    clear wa_char.
ENDTRY.

Read only

4,384

Hi Krupaji,

can you please explain your code for the dummy?

As I understand, the first thing you do after TRY .. CATCH block is opened with

TRY

RAISE EXCEPTION TYPE cx_sy_conversion_no_number.

This will transfer directly to the CATCH block, the lines

IF WA_CHAR = 0.
    RAISE EXCEPTION TYPE cx_sy_conversion_no_number.
    WRITE: 'is 0'.
    ENDIF.

Are never processed. Processing continues with

CATCH CX_SY_CONVERSION_NO_NUMBER into oref.
    WRITE: / 'ERROR'.

regardsless of WA_CHAR value

CATCH cx_root into oref.

is not reached from anywhere

CLEANUP.
    clear wa_char.

will work as designed: Clear WA_CHAR regardsless of value.

The reason for the uncatchable exception is in the kernel architecture: If you compare a text value with a numeric dataobject, the text value is converted implicitly to a number allowing all kind of comparisons like GT, GE, EQ, NE, LT, LE.

This implicit conversion can not be caught, even CX_ROOT will not catch it.

This is also new to me: I thought I could catch just everything with CX_ROOT.

Regards,

Clemens

ENDTRY.