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: 

Checking if a value is supported for a given type

Former Member
0 Kudos

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

SuhaSaha
Advisor
Advisor
0 Kudos

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

1 REPLY 1

SuhaSaha
Advisor
Advisor
0 Kudos

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