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

How to declare Internal Table dynamically

Former Member
0 Likes
5,002

Dear ABAP Gurus,

Good day.

I have a requirement for declaring 'N' number of Internals tables which would be a parameter for the Users to Enter.

For instance:

if the Input by User : 02.

I need to declare two internal tables like it_tab1 and it_tab2 with same table type .

in case Input by User : 04.

I need to declare four internal tables like it_tab1,it_tab2,it_tab3 and it_tab4 with same table type.

Please Guide me how do i Approach it.

Thanking You

Amsaraju

1 ACCEPTED SOLUTION
Read only

sascha_reissig
Participant
0 Likes
3,975

Hi Gaya,

even if I am not sure if I understood your requirement may be this helps:

In the above mentioned example you create 4 tables and store the result in lt_tables as reference.

I just used the INDEX as "user value" as example. Now you can create N-Tables with data.

With this coding it is possible to get the data back for further processing:

loop at lt_tables into ls_tables.
     ASSIGN ls_tables-table_ref->* to <ft_table>.

     " do want you want
     " ....
   endloop.

Hope this helps!

Regards, Sascha

8 REPLIES 8
Read only

venkat_aileni
Contributor
0 Likes
3,975

Check below link:

http://scn.sap.com/docs/DOC-42525

-Venkat

Read only

Former Member
0 Likes
3,975

Hi Gaja,

You can use deep structure for this purpose. Create a type in your program as deep structure and declare an internal table within this deep structure. Now depending on the user input, you can append records to your deep structure.

In this case you won't have 'N' number of internal tables, but one single internal table in which each records hold a table i.e each records can hold multiple records. You can access each table through index then. I hope it is clear to you.

Thanks,

Ajay Bose

Read only

Former Member
0 Likes
3,975

Hi,

you can use the below code to create internal table dynamically.

data : BEGIN OF st,

          name TYPE char10,

          table TYPE TABLE OF sflight,

        END OF st.

data: lt_itab LIKE TABLE OF st,

       ls_itab like st,

       lt_tab TYPE TABLE OF sflight.

DO 4 TIMES.

ls_itab-name = sy-tabix.

ls_itab-table = lt_tab.

APPEND ls_itab to lt_itab.

ENDDO.

Then each line item will contain internal table

Thanks and Regards,

Ragavendra

Read only

0 Likes
3,975

Try this

<link farms removed>

Message was edited by: Suhas Saha

Read only

former_member188282
Active Participant
0 Likes
3,975

Hi,

Refer the below link

http://scn.sap.com/docs/DOC-42525

Regards,

Rajesh

Read only

GirieshM
Active Contributor
0 Likes
3,975

Hi Gaja,

I dont think it is possible. Because you are changing the definition of table dynamically as itab1, itab2, itab3 and not its column definition. Even if we use field symbols the content column can be created dynamically but the field symbol cant increase as <fs>, <fs1>, <fs2> . Sorry I am not sure that we can do it. . Let me also check whether is it possible or not . If the client needs 10 or 15 tables max then we can declare it by if statements but more than that looks tedious. Hope some expert may answer.

With Regards,

Giriesh M

Read only

sascha_reissig
Participant
0 Likes
3,976

Hi Gaya,

even if I am not sure if I understood your requirement may be this helps:

In the above mentioned example you create 4 tables and store the result in lt_tables as reference.

I just used the INDEX as "user value" as example. Now you can create N-Tables with data.

With this coding it is possible to get the data back for further processing:

loop at lt_tables into ls_tables.
     ASSIGN ls_tables-table_ref->* to <ft_table>.

     " do want you want
     " ....
   endloop.

Hope this helps!

Regards, Sascha

Read only

rodolformoraes
Participant
0 Likes
3,975

Hi Gaja, refer to the code below:

   TYPES:
BEGIN OF gty_ref_table,
   table_ref                   TYPE REF TO data,
END OF gty_ref_table.

DATA:
lt_ref_table_data             TYPE TABLE OF gty_ref_table,
ls_ref_table_data             LIKE LINE OF lt_ref_table_data.

DO 2 TIMES.
  CLEAR ls_ref_table_data.
  CREATE DATA ls_ref_table_data-table_ref TYPE STANDARD TABLE OF REF TO ('LFA1').
  APPEND ls_ref_table_data TO lt_ref_table_data.
ENDDO.

REFRESH lt_ref_table_data.

DO 4 TIMES.

  CLEAR ls_ref_table_data.

  CREATE DATA ls_ref_table_data-table_ref TYPE STANDARD TABLE OF REF TO ('LFA1').

  APPEND ls_ref_table_data TO lt_ref_table_data.

ENDDO.

After this you'll have to work with the tables references.

Regards,

Rodolfo