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 data conversion

Former Member
0 Likes
417

Hi experts,

I'm facing a problem with the following code:



FIELD-SYMBOLS: <fs_vl1> TYPE ANY,
               <fs_vl2> TYPE ANY,
               <fs_aux_type> TYPE ANY.

DATA:  lv_type_char(50) TYPE c VALUE '1023',
       lv_type_char2(50) TYPE c VALUE '1022',
       lv_ref TYPE REF TO data,
       lv_ref2 TYPE REF TO data.


ASSIGN 'NETWR_AK' TO <fs_aux_type>.

CREATE DATA lv_ref TYPE (<fs_aux_type>).
CREATE DATA lv_ref2 TYPE (<fs_aux_type>).

ASSIGN lv_type_char TO <fs_vl1>.
GET REFERENCE OF <fs_vl1> INTO lv_ref.

ASSIGN lv_type_char2 TO <fs_vl2>.
GET REFERENCE OF <fs_vl2> INTO lv_ref2.

IF lv_ref2 > lv_ref.
  WRITE: 'Ok'.
ENDIF.

The variables lv_ref and lv_ref2 are created correctly with type 'NETWR_AK', but when I use the

command GET REFERENCE, these variables are converted to 'Char' type.

And with 'Char' type, the 'IF' statement does not work.

My doubt is, how can I populate the variables lv_ref and lv_ref2 without change their types?

Can anyone help me?

Thanks and regards!

Fabio

2 REPLIES 2
Read only

alok_patra
Product and Topic Expert
Product and Topic Expert
0 Likes
389

Hi,

use casting operator while assigning the character type data to field symbols.

ASSIGN XXX TO <XXX> CASTING TYPE/LIKE XXX

thanks,

Alok

Read only

MarcinPciak
Active Contributor
0 Likes
389

All you need is


DATA:  lv_type_char(50) TYPE c VALUE '1023',
       lv_type_char2(50) TYPE c VALUE '1022',
       lv_ref TYPE REF TO data,
       lv_ref2 TYPE REF TO data.

FIELD-SYMBOLS: <fs1>, <fs2>.

GET REFERENCE OF lv_type_char INTO lv_ref.
GET REFERENCE OF lv_type_char2 INTO lv_ref2.
ASSIGN lv_ref->* TO <fs1>.
ASSIGN lv_ref2->* TO <fs2>.

IF <fs1> > <fs2>.
  WRITE: / <fs1>, ' is greater than ', <fs2>.
ELSE.
  WRITE: / <fs1>, ' is less than ', <fs2>.
ENDIF.

Regards

Marcin