Skip to Content
-2

accessing field symbol that is defined runtime

Jul 01, 2017 at 04:56 PM

89

avatar image
Former Member
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'" )

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Fabian Lupa Jul 01, 2017 at 05:14 PM
3

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>.
Share
10 |10000 characters needed characters left characters exceeded
Matthew Billingham
Jul 02, 2017 at 12:50 PM
3

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

Share
10 |10000 characters needed characters left characters exceeded