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

Checking if a value is supported for a given type

Former Member
0 Likes
500

Hello Experts,

I have a value of Type string. e.g. 2.3

I want to check if this value can be of type p in ABAP.

My idea is to move 2.3 to type p and catch an exception if 2.3 or any other value cannot be converted to p.

Can someone please give me an insight how to implement this?

Thanks,

Nitish.

1 ACCEPTED SOLUTION
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
466

Check this code snippet:

PARAMETERS: p_string TYPE string.

DATA: v_pack TYPE p DECIMALS 2.

DATA: error_ref TYPE REF TO cx_sy_conversion_no_number,
     err_text TYPE string.

TRY .
    MOVE p_string TO v_pack.
    WRITE v_pack.
  CATCH cx_sy_conversion_no_number INTO error_ref.
    err_text = error_ref->get_text( ).
    WRITE err_text.
ENDTRY.

BR,

Suhas

Hello Experts,

I have a value of Type string. e.g. 2.3

I want to check if this value can be of type p in ABAP.

My idea is to move 2.3 to type p and catch an exception if 2.3 or any other value cannot be converted to p.

Can someone please give me an insight how to implement this?

Thanks,

Nitish.

1 REPLY 1
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
467

Check this code snippet:

PARAMETERS: p_string TYPE string.

DATA: v_pack TYPE p DECIMALS 2.

DATA: error_ref TYPE REF TO cx_sy_conversion_no_number,
     err_text TYPE string.

TRY .
    MOVE p_string TO v_pack.
    WRITE v_pack.
  CATCH cx_sy_conversion_no_number INTO error_ref.
    err_text = error_ref->get_text( ).
    WRITE err_text.
ENDTRY.

BR,

Suhas