‎2008 Mar 27 10:48 PM
Hi, I am new to ABAP and would like to know how to loop at two internal tables. The following is my scenario:
ITAB and ITAB_1 are internal tables with same data and the data is sorted on Fiscal Year Period. Now I want to do is as :
loop at ITAB.
loop at ITAB_1.
endloop.
endloop.
During the first pass through ITAB, I should loop at ITAB_1 zero times. During the second pass through ITAB, I should loop at ITAB_1 1 time and so on. Basically I want to loop through all records in ITAB_1 that are just above my current record in ITAB.
How can I do this? Any ideas.
Thanks and regards.
‎2008 Mar 28 5:41 PM
loop at itab1.
setup a field containing the current line index of the * * first table - 1
l-index = sy-tabix - 1.
check sy-tabix > 1.
loop at itab2 from 1 to l_index.
endloop.
endloop.
‎2008 Mar 28 5:55 PM
Hi,
Searching in the forum for "nested loop" you will find useful tips like these:
/people/rob.burbank/blog/2006/02/07/performance-of-nested-loops
/people/siegfried.boes/blog/2007/09/12/runtimes-of-reads-and-loops-on-internal-tables
Hope it helps.