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

Loop inside a Loop

Former Member
0 Likes
921

Hi

Can I know that is there any other way, to avoid using Loop inside a Loop?

Thanks

9 REPLIES 9
Read only

Former Member
0 Likes
888

u can use the read statement instead of multiple loops... thats the one good solution

Read only

0 Likes
888

The second table has more than one similar record so I cant use a READ inside the first Loop.

Any way I can avoid using Loop inside the Loop ?

Read only

0 Likes
888

Use the read statement and give the condition what differentiates one similar record from the other

Read only

0 Likes
888

ok,,let me explain a bit more..

Say my first internal table as coulmns as material number and plant

And my second internal table as materail numbers and it corresponding characteristics ie. one material number has more than one characteristics.

So I cant read on second internal table with key only as material number (which is known to me) ie, In this case I need to do a Loop inside a Loop to check for every characteristic for a material.

And I want to avoid doing that.

I hope I am clear to you.

Read only

0 Likes
888

I think there's no other option rather than using LOOP inside LOOP here.

To make it more effective you can use:

LOOP AT ITAB1.

LOOP AT ITAB2 WHERE MATNR = ITAB1-MATNR.

....

ENDLOOP.

ENDLOOP.

Second option would be to join these 2 tables on Material Number and get data into single internal table:

SELECT * INTO ITAB

FROM TABLE1 INNER JOIN TABLE 2

ON TABLE1MATNR = TABLE2MATNR.

Reward points if useful.

Read only

0 Likes
888

In that case u have to use the loop inside the loop two loops does not make that much difference in performance if u have more than two loops that makes the difference i guess....

Read only

0 Likes
888

What if there are more than 2 loops,,how can we handle it?

I think I need to do that also later in my program.

Thanks

Read only

former_member194669
Active Contributor
0 Likes
888

Hi,

May be this way.


loop at i_mara.
  do.
    read table i_mara_characteristics wuth key matnr = i_mara-matnr.
    if sy-subrc eq 0.
       <<< whatever you want to do >>>
       delete i_mara_characteristics index sy-tabix.
    else.
       exit.
    endif.
  enddo.
endloop.

aRs

Read only

Former Member
0 Likes
888

This message was moderated.