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

Nested Loops Question

Former Member
0 Likes
466

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.

2 REPLIES 2
Read only

Former Member
0 Likes
430

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.

Read only

rodrigo_paisante3
Active Contributor
0 Likes
430

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

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/40729734-3668-2910-deba-fa0e95e2...

Hope it helps.