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: 

accessing field symbol that is defined runtime

Former Member
0 Kudos
Hello experts,

I am currently working on a dynamic report for which i have to write some dynamic queries and i am stuck at a place. Please, it would be great if anyone can suggest me s way out. Bellow i have tried to explain what i am doing and where i am stuck. Thanks.

Defining 2 field symbol

<o_fs> TYPE table, <owa_fs> type any.

Dynamically creating a internal table for <o_fs>

 CALL METHOD cl_alv_table_create=>create_dynamic_table
 EXPORTING
 it_fieldcatalog = it_cat
 IMPORTING
 ep_table = d_ref2.
 ASSIGN d_ref2->* TO <o_fs>.

then i fill data in the <o_fs>

After that i want to add a value to one of the field of <o_fs>

LOOP AT <O_FS> ASSIGNING <OWA_FS>.
 *<owa_fs>-columnname = 'value to be added'.
 IF SY-TABIX = INDEX.
 MODIFY (p_vtab) From <OWA_FS>.
 COMMIT WORK.
 ENDIF.

the line which is marked * is giving me an compile time error that "The data object "<OWA_FS>" has no structure and therefore no component called 'COLUMNNAME'. called 'COLUMNNAME'" )

1 ACCEPTED SOLUTION

fabianlupa
Contributor

You cannot statically access components of a generic type (as they are only known at runtime). This should work:

FIELD-SYMBOLS: <lv_comp> TYPE csequence.

ASSIGN COMPONENT 'COLUMNNAME' OF STRUCTURE <owa_fs> TO <lv_comp>.
IF <lv_comp> IS ASSIGNED.
  <lv_comp> = 'value to be added'.
ENDIF.
UNASSIGN <lv_comp>.
2 REPLIES 2

fabianlupa
Contributor

You cannot statically access components of a generic type (as they are only known at runtime). This should work:

FIELD-SYMBOLS: <lv_comp> TYPE csequence.

ASSIGN COMPONENT 'COLUMNNAME' OF STRUCTURE <owa_fs> TO <lv_comp>.
IF <lv_comp> IS ASSIGNED.
  <lv_comp> = 'value to be added'.
ENDIF.
UNASSIGN <lv_comp>.

matt
Active Contributor

Don't use create_dynamic_table. Use RTTS instead. Search this site for some excellent blogs on how to use it.