Skip to Content

Often a requirement can be covered creating a dynamic internal table. To learn more about this you can take a look at the following document:

Dynamic Internal Table iIlustrated with an example of creating the transpose of internal table

In this document I want to take this to a new level. Basically the requirement was to have an internal table which contains (different) dynamic tables.

The main issue with this is that a field-symbol cannot be added to an internal table as soon as it contains one of the following generic types (http://help.sap.com/abapdocu_70/de/ABENBUILT_IN_TYPES_GENERIC.htm)

Now, how to get around this restriction? First we need 2 data references:

DATA: BEGIN OF ls_tables,
   tabnam TYPE tdtabdef,
   itref TYPE REF TO data,
END OF ls_tables.
DATA: lt_tables LIKE TABLE OF ls_tables.


Basically here we will be storing the Table name (or any other unqiue identification) and the data reference of the content.


In a next step we need to define the field-symbol for our selection:

FIELD-SYMBOLS: <fs_table> TYPE ANY TABLE.


And this is all we need. Now you can go ahead and build your logic to retrive the relevant data you need. For the sake of this document see some sample code:

DO 2 TIMES.
   if syindex = 1.
     ls_tablestabnam = ‘S703’.
   else.
     ls_tablestabnam = ‘A587’.
   endif.

   CREATE DATA ls_tablesitref TYPE TABLE OF (ls_tablestabnam).
   ASSIGN ls_tablesitref->* TO <fs_table>.
   SELECT * FROM (ls_tablestabnam) INTO TABLE <fs_table>.

   APPEND ls_tables TO lt_tables.
ENDDO.


The important thing to make sure of is to always save the DATA reference into the internal table. To retrive back the data, simply reassign the DATA reference from the table to a field-symbol and you are good to go:

LOOP AT lt_tables INTO ls_tables.
   ASSIGN ls_tablesitref->* TO <fs_table>.

   “DO STUFF with <fs_table>.
ENDLOOP.


To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply