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

Alternative for nested loops

Former Member
0 Likes
1,130

Hi Gurus,

I have the following problem :

There are 2 internal tables namely 1 &2.

Now there is a field in table 1 'AUGBL' which should be equal to field in Table2-BELNR.

Now if there is a match between TABLE1-AUGBL and TABLE2-BELNR,

so we move to table 2 to look for 'augbl' associated with 'belnr' in the same table.

Then I have to give the following logic -

If table2-belnr = table2-augbr,

Then do nothing.

Else.

Check, for the Augbl which will equal Belnr in a different position in table 2.

For ex:

Table1-AUGBL = 2.

So now we have to search a field when Table1-augbl = Table2-belnr = 2.

Now for this record in table2, there are 2 conditions:

When Table2-augbl = 2, (in which case we do nothing)

or,

Table2-augbl NE 2, or Table2-augbl = 3.

In the latter case, there will be another field in Table2-BELNR = 3. So we go to this record now and check for the associated AUGBL and do the same checks above.

We keep on continuing for this till the time we do not get the Table2-belnr = Table2-augbl in the end for the same record.

Now I want to achieve this without using nested loop.

Kindly help as I already have wated a lot of time.

Please let me know if there are any clarifications.

6 REPLIES 6
Read only

Former Member
0 Likes
680

Try to use Join in select query with common fields..

or send the query you used so we wil try to optimize and send the better solution..

Read only

Former Member
0 Likes
680

Please see [The Performance of Nested Loops|/people/rob.burbank/blog/2006/02/07/performance-of-nested-loops]

Rob

Read only

Former Member
0 Likes
680

Hey..

Before u get the data into two internal tables through SELECT stmts.

U can use JOIN instead of two SELECT stmts ..that wud fetch the data into single internal table..

and that may ease ur validations and further process..

try this out..

Thanks and Regards,

KC

Read only

0 Likes
680

Hi,

Thanks for the reply but I do need both of the tables for some other reasons. I am not selecting data in them, but putting data in them based on certain restrictions.

Read only

0 Likes
680

This works

loop at itab into wa_itab1.

read table itab2 into wa_itab2 index sy-index / sy-tabix. " (optional: Binary search with sort )
if sy-subrc eq 0.

endif.

endloop.

Read only

Former Member
0 Likes
680

Thanks.