Downtime Announcement: Please note the SAP Community Wiki will be unavailable due to a system upgrade on Thursday, September 24th between 6 and 7 AM CEST
Skip to end of metadata
Go to start of metadata
REPORT ztestank.
* This code will basically show you how to make use of field-symbols
* for dynamic tables and fields.*Sometimes there is a necessity that we are not aware of the table structure
*before hand and therefore we do not know how to handle such tables.
*This example makes use of field-symbols to achieve the same.
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.
* I have my internal table as ITAB.
wa-vbeln = '123'.
APPEND wa TO itab.
*I am creating a DATA object which will be like ITAB.
CREATE DATA obj1 LIKE itab.
* This would now assign the stucture of ITAB to the field-symbols <FS_TABLE>
* So now <FS_TABLE> has a stucture and it is a table.
ASSIGN obj1->* TO <fs_table>.
IF <fs_table> IS ASSIGNED.
* This would assign the values if ITAB to the field symbols <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 thn assign it to <FS_LINE>.
* So now <FS_LINE> becomes a work area having a structure like ITAB
  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 Conmponent 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.