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: 

Assigning components in generic fields

Former Member
0 Kudos

Hi Experts,

I have an itab whose structure is containing some keys and a generic field which contains another structure.

For example: key1 key2 key3 DATA

...

Generic field(structure) "DATA" always contains a Field called "ROOT_KEY" and some others.

First I assigned the generic field to the field symbol <lf_data>, this works!

But the second assignment, where I want to move the value of root_key in <lf_key> doesn't work, I'll get dump with "field symbol lf_key is not assigned"


LOOP AT lt_data ASSIGNING <lf_any>.

    ASSIGN COMPONENT 'DATA' OF STRUCTURE <lf_any> TO <lf_data>.

    ASSIGN COMPONENT 'ROOT_KEY' OF STRUCTURE <lf_data> TO <lf_key>.

...

ls_test-rootkey = <lf_key> " <-- error "not assigned"

ENDLOOP

is this completely wrong? How can I access my root_key within my loop?

Thanks and Regards,

Daniel

Edited by: Daniel Mler on Aug 4, 2008 4:01 PM

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

It is working for me, can you post all of the relevant coding?

REPORT  zrich_0001.

TYPES: BEGIN OF t_root,
        root_key TYPE string,
        some_data TYPE string,
       END OF t_root.

TYPES: BEGIN OF t_data,
         data TYPE t_root,
         another_data TYPE string,
       END OF t_data.

DATA: lt_data TYPE TABLE OF t_data.
DATA: ls_data LIKE LINE OF lt_data.
FIELD-SYMBOLS <lf_any> TYPE ANY.
FIELD-SYMBOLS <lf_data> TYPE ANY.
FIELD-SYMBOLS <lf_key> TYPE ANY.

ls_data-data-root_key = 'Root String'.
ls_data-data-some_data = 'SomeData String'.
ls_data-another_data = 'AnotherData String'.
APPEND ls_data TO lt_data.

LOOP AT lt_data ASSIGNING <lf_any>.

  ASSIGN COMPONENT 'DATA' OF STRUCTURE <lf_any> TO <lf_data>.
  ASSIGN COMPONENT 'ROOT_KEY' OF STRUCTURE <lf_data> TO <lf_key>.
  WRITE:/ <lf_key>.

ENDLOOP.

Regards,

Rich Heilman

2 REPLIES 2

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

It is working for me, can you post all of the relevant coding?

REPORT  zrich_0001.

TYPES: BEGIN OF t_root,
        root_key TYPE string,
        some_data TYPE string,
       END OF t_root.

TYPES: BEGIN OF t_data,
         data TYPE t_root,
         another_data TYPE string,
       END OF t_data.

DATA: lt_data TYPE TABLE OF t_data.
DATA: ls_data LIKE LINE OF lt_data.
FIELD-SYMBOLS <lf_any> TYPE ANY.
FIELD-SYMBOLS <lf_data> TYPE ANY.
FIELD-SYMBOLS <lf_key> TYPE ANY.

ls_data-data-root_key = 'Root String'.
ls_data-data-some_data = 'SomeData String'.
ls_data-another_data = 'AnotherData String'.
APPEND ls_data TO lt_data.

LOOP AT lt_data ASSIGNING <lf_any>.

  ASSIGN COMPONENT 'DATA' OF STRUCTURE <lf_any> TO <lf_data>.
  ASSIGN COMPONENT 'ROOT_KEY' OF STRUCTURE <lf_data> TO <lf_key>.
  WRITE:/ <lf_key>.

ENDLOOP.

Regards,

Rich Heilman

Former Member
0 Kudos

Hi,

It should work check with the fields name and dclarations,

Find the sample code below

DATA: it_final TYPE STANDARD TABLE OF p0001.

DATA: wa_final TYPE p0001.

FIELD-SYMBOLS: <wa_p0001> TYPE p0001,

<wa_p0001_persg> TYPE persg.

DATA: gd_persg TYPE persg.

SELECT * FROM pa0001 INTO TABLE it_final WHERE begda GE '01012008'.

LOOP AT it_final ASSIGNING <wa_p0001>.

ASSIGN COMPONENT 'PERSG' OF STRUCTURE <wa_p0001> TO <wa_p0001_persg>.

gd_persg = <wa_p0001_persg>.

ENDLOOP.