top of page

TIP: Dynamic tables using Field Symbols

If you are not sure as to the structure of the table prior to executing a program then you need to define the table dynamically - Here's how you do it...

types : begin of itab,

vbeln type vbrk-vbeln,

end of itab.

data : itab type standard table of itab.


data : wa type itab.

data : obj1 type ref to data,

obj2 type ref to data.


field-symbols : <fs_table> type any table,

<fs_line> type any,

<fs_field> type any.


* Example internal table

wa-vbeln = '123'.

append wa to itab.


*Create a DATA object like ITAB.

create data obj1 like itab.


* Assign the structure of ITAB to the field-symbol <FS_TABLE>.

* <FS_TABLE> now has a table structure

assign obj1->* to <fs_table>.


if <fs_table> is assigned.

* assign the values if ITAB to the field symbol <FS_TABLE>

<fs_table> = itab[].


* in order to read the contents of the table, we need a work area.

* So we create a data object which has the same structure as line of

* ITAB and then assign it to <FS_LINE>.

create data obj2 like line of <fs_table>.

assign obj2->* to <fs_line>.


loop at <fs_table> assigning <fs_line>.

* in order to access the individual fields of the work area we will

* have to use the Assign Component statement.

* This component can be either named if we know the fieldname or we

* can give the column position


assign component 'VBELN' of structure <fs_line> to <fs_field>.

* or ASSIGN COMPONENT 1 OF STRUCTURE <fs_line> TO <fs_field>.


if <fs_field> is assigned.

write <fs_field>.

endif.


endloop.


endif.

84 views0 comments
bottom of page