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

Check variable fits other variable based on data element

TimVDB92
Participant
0 Likes
710

Hi,

I'm looking for a function module that checks if a variable fits in an other variable based on the data element and length.

For example:

Data: var1 type I.

Data: var2 type String.

--> False

Data: var3 type C length 5.

Data: var4 type C length 20.

--> False

Data: var3 type C length 5.

Data: var4 type C length 4.

--> True

Is there a function that checks if 2 variables fits?

Kind regards,

2 REPLIES 2
Read only

Former Member
0 Likes
650

Hi,

Check class cl_abap_typedescr=>describe_by_data(variable).

It should return the type and length, of your data. Then compare them.

Read only

Former Member
0 Likes
650

Hi Tim,

I would a write a small routine for this. I tested it and seems to be working fine.

Please have a look and let me know.

DATA : dref1 TYPE REF TO data,

        dref2 TYPE REF TO data.

DATA : lv_char_long1 TYPE char1024.

DATA : lv_char_long2 TYPE char1024.

DATA: var1 TYPE string.

DATA: var2 TYPE c LENGTH 5.

FIELD-SYMBOLS : <f1> TYPE any.

FIELD-SYMBOLS : <f2> TYPE any.

GET REFERENCE OF var1 INTO dref1.

ASSIGN dref1->* TO <f1>.

lv_char_long1 = <f1>.

IF lv_char_long1 IS INITIAL.

   CLEAR <f1> WITH '*'.

ENDIF.

GET REFERENCE OF var2 INTO dref2.

ASSIGN dref2->* TO <f2>.

lv_char_long2 = <f2>.

IF lv_char_long2 IS INITIAL.

   CLEAR <f2> WITH '*'.

ENDIF.

lv_char_long1 = <f1>.

lv_char_long2 = <f2>.

IF lv_char_long1 EQ lv_char_long2.

   WRITE 'Same'.

ELSE.

   WRITE : 'Different'.

ENDIF.


R