Application Development 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: 

Loop through different ITAB with field symbols

hergardinho
Explorer
0 Kudos

Hello Guys,

i have a program where several itabs (infotype tables) are filled with data. This itabs were extracted to application server with open dataset output and appending which is a huge performance issue.

My plan now is to collect all the data in these itabs and write them to server with only open dataset for OUTPUT (tested it for 1 itab and it's 90% faster).

To make the code clear and not repeating 15 open datasets, i'd like to loop through a table where the itab names are stored and afterwards looping through the actual itab an write to server.

Every itab should be a own file on the server, so that's the requirement.

I tried with field symbols but i cant access the itab data.

Do you have a clue how to do it?.

Example:

itab1

itab2

itab3

itab4...itab15.

I would build an own itab which has the itab names and the server path in it.

Like: itab-name = 'it0000'

itab-path = '/SAP/export/inftyp00'.

Like: itab-name = 'it0001'

itab-path = '/SAP/export/inftyp01'. and so on

So i'd loop through the first itab where the itab names and paths are stored and afterwards through the actual itab content. Like that:

loop at itab into wa.
open dataset <path> for output in text mode encoding default.
loop at <itab>.
 transfer <wa> to <path>.
endloop.
close dataset.
endloop.

But how do i get access to the itab in loop at <itab>.

Thank you and best regards

3 REPLIES 3

Sandra_Rossi
Active Contributor

I don't exactly get the question but is it ASSIGN that you're looking for?

DATA it0000 TYPE TABLE OF pa0000.
FIELD-SYMBOLS <itab> TYPE TABLE.

ASSIGN ('IT0000') TO <itab>.

Tomas_Buryanek
Active Contributor

Hello,

as sandra.rossi suggest, it can be done with dynamic ASSIGN. Just in your case your table name will not be hardcoded, but inside your table of itab names 🙂 See sample code:

TYPES: BEGIN OF lty_tables,
name TYPE string,
END OF lty_tables.

DATA: lt_tables TYPE TABLE OF lty_tables.
FIELD-SYMBOLS: <lt_dyn_table> TYPE ANY TABLE.

APPEND VALUE #( name = 'LT_MARA' ) TO lt_tables.
APPEND VALUE #( name = 'LT_MARC' ) TO lt_tables.

LOOP AT lt_tables ASSIGNING FIELD-SYMBOL(<ls_tables>)
WHERE name IS NOT INITIAL.

ASSIGN (<ls_tables>-name) TO <lt_dyn_table>. "This is the trick
IF sy-subrc = 0.
LOOP AT <lt_dyn_table> ASSIGNING FIELD-SYMBOL(<ls_dyn_line>).
"...
ENDLOOP.
ENDIF.

ENDLOOP.
-- Tomas --

Hi,

thank you very much, your code worked, that was exactly what i was looking for!

Many thanks and have a nice day 🙂

PS: also thanks to Sandra 🙂