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: 

Nested Loops

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

data: current_idx type sy-tabix.
loop at ITAB.
current_idx = sy-tabix - 1.

if sy-tabix > 1.
loop at ITAB_1 to current_idx.

endloop.
endif.

endloop.
2 REPLIES 2

Former Member
0 Kudos

data: current_idx type sy-tabix.
loop at ITAB.
current_idx = sy-tabix - 1.

if sy-tabix > 1.
loop at ITAB_1 to current_idx.

endloop.
endif.

endloop.

0 Kudos

Thanks. This should take care of my issue. Awarded points too.