I have some example code below:
DATA(t_strings) = VALUE char10_t( ( 'S1' ) ( 'S2' ) ( 'S3' ) ).
TYPES : BEGIN OF gty_ref,
string_ref TYPE REF TO data,
END OF gty_ref,
gty_t_ref TYPE STANDARD TABLE OF gty_ref.
DATA : t_string_ref1 TYPE gty_t_ref,
t_string_ref2 TYPE gty_t_ref.
t_string_ref1 = VALUE #( FOR entry IN t_strings ( string_ref = REF #( entry ) ) ).
LOOP AT t_strings ASSIGNING FIELD-SYMBOL(<entry>).
t_string_ref2 = VALUE #( BASE t_string_ref2 ( string_ref = REF #( <entry> ) ) ).
ENDLOOP.
I thought that using FOR
or using a loop would provide the same result. But this is what happens:
Can someone explain why T_STRING_REF1
only contains references to S3 as opposed to S1, S2 and S3 as I expected?