Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Multiple Internal Tables created Dynamically

Former Member
0 Likes
2,656

Hi Everyone,

I realise there are plenty of threads on this topic but I cant find one specific to my scenario. The examples I've found are for one dynamic table or for multiple dynamic tables where the number of tables required is known. Maybe I'm overlooking something in the examples I have seen but I hope not.

My scenario is that I need to create multiple internal tables all of the same structure depending on the number of records that are in a table . Eg. itab_1 contains 10 records so I need 10 internal tables to be created dynamically. This could be any amount so I dont want to code like <fs_itab_1>, <fs_itab_2> etc becuase I could end up declaring very many of these.

Is there any way I can create tables dynamically depending on the number of records in a table without having to declare a field symbol for each one I want ?

I would appreciate any help or pointers on this ?

Thanks so much for you time and consideration.

Kind Regards

DK

Edited by: Damien Kesle on Jul 21, 2011 1:36 PM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,820

Hi,

Looks like quite interesting requirement.

But, what do you do with those may be X number of internal tables? How do you process them afterwards? You should think of these questions before you create those dynamic internal tables.

Anyways, I look at the requirement as one internal table(Complex type) which actually holds the internal tables. I will add those number of internal tables as rows to this complex internal tables. I mean use the definition of your dynamic internal table as a row of another internal table which holds multiple number of internal tables(as decided at the runtime)

Like if you are looking at <fs_int_1> as one internal table, I will say you have access the first row of complex internal table.

Hope this satisfies your requirement.

Regards,

Ravi

4 REPLIES 4
Read only

Former Member
0 Likes
1,821

Hi,

Looks like quite interesting requirement.

But, what do you do with those may be X number of internal tables? How do you process them afterwards? You should think of these questions before you create those dynamic internal tables.

Anyways, I look at the requirement as one internal table(Complex type) which actually holds the internal tables. I will add those number of internal tables as rows to this complex internal tables. I mean use the definition of your dynamic internal table as a row of another internal table which holds multiple number of internal tables(as decided at the runtime)

Like if you are looking at <fs_int_1> as one internal table, I will say you have access the first row of complex internal table.

Hope this satisfies your requirement.

Regards,

Ravi

Read only

Shahid
Product and Topic Expert
Product and Topic Expert
0 Likes
1,820

I think dynamically declaring the variables is not quite possible.

AnyhowInteresting question and intersting Approach from RAVI.

Read only

MarcinPciak
Active Contributor
0 Likes
1,820

Ravi explained how semantically this should more or less work, now the code;)


DATA it_dyn_tables TYPE TABLE OF REF TO data.
DATA wa_dyn_table  TYPE REF TO data.

DO 10 TIMES.  "any times you want
  CREATE DATA wa_dyn_table TYPE TABLE OF sflight.  "create dynamic table
  APPEND wa_dyn_table TO it_dyn_tables.  "and store it in table of references
ENDDO.

FIELD-SYMBOLS <dyn_table>  TYPE ANY TABLE.

LOOP AT it_dyn_tables INTO wa_dyn_table.
  ASSIGN wa_dyn_table->* TO <dyn_table>.
  "now do whatever you want with <dyn_table> which is one of your dynamic tables
ENDLOOP.

I used table of references as they can accept generic data objects. This can be either reference to data object, structure, or (as in this case) table.

Regards

Marcin

Read only

Former Member
0 Likes
1,820

Hi Guys,

Thank to you all for your responses. Apologies for my late reply as I was out for the last few days.

I have coded a soluton by basically declaring 50 interntal tables (gt_tab) and assiging the internal table name plus the counter (gt_tab1) to the field-symbols. I'm interested in changing this after seeing your suggestion RAVI. Thanks alot for the idea.

SSM - Yes, my initial approach was not correct for the way I had consider to do it. You do need to declare at least the table name this way and assign to field symbol as I mentioned above.

Marcin - Thanks for the coding to illustrate RAVI's suggestion.

Points Awarded - Thanks again for all your help guys.

Regards

DK