Skip to Content
avatar image
-2
Former Member

accessing field symbol that is defined runtime

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'" )

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Jul 01, 2017 at 05:14 PM

    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>.
    Add comment
    10|10000 characters needed characters exceeded

  • Jul 02, 2017 at 12:50 PM

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

    Add comment
    10|10000 characters needed characters exceeded