‎2013 Oct 25 10:23 AM
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
‎2013 Oct 25 1:56 PM
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
‎2013 Oct 25 10:27 AM
‎2013 Oct 25 10:35 AM
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
‎2013 Oct 25 11:46 AM
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
‎2013 Oct 25 12:24 PM
Try this
<link farms removed>
Message was edited by: Suhas Saha
‎2013 Oct 25 12:59 PM
‎2013 Oct 25 1:39 PM
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
‎2013 Oct 25 1:56 PM
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
‎2013 Oct 25 2:04 PM
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