Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
DominikKraemer
Active Participant

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 sy-index = 1.
     ls_tables-tabnam = 'S703'.
   else.
     ls_tables-tabnam = 'A587'.
   endif.

   CREATE DATA ls_tables-itref TYPE TABLE OF (ls_tables-tabnam).
   ASSIGN ls_tables-itref->* TO <fs_table>.
   SELECT * FROM (ls_tables-tabnam) 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_tables-itref->* TO <fs_table>.

   "DO STUFF with <fs_table>.
ENDLOOP.


1 Comment
kumar_sp
Explorer
0 Kudos

Nice Block..

Regards,

kumar