05-16-2014 2:01 PM
Hello Everyone,
I have a loop which I write like below:
Loop at itab into wa from index.
I use parallel cursor and use another loop.
loop at itab1 into wa1.
**** my code *****
endloop.
endloop.
Now my requirement is that I start the first loop after some records if the second loop record exists.
Can I increase the value of index inside the second loop or how do I approach it?
Thanks.
05-23-2014 8:08 AM
I have resolved the problem myself.
Thank you so much guys for helping it out.
05-16-2014 2:13 PM
Hi.
create a variable l_index and use it in the second loop.
there u can increase the value of the l_index as you want.
second loop.
l_index = sy-tabix.
regards
Miguel
05-16-2014 2:17 PM
Hello Miguel,
I created one variable like index and increased the value in the second loop.
But when its going to the first loop, the value of index shows as 8, but its starting from 5.
Initially it had started from 4.
Regards,
Vinod
05-16-2014 2:22 PM
05-16-2014 2:22 PM
Hi,
what i always do is to use local variable for index inside the loop. So, for the first loop also use a l_index1, for the second loop l_index2 and use them as you want.
But becareful, do not use l_index = sy-tabix, because it will be the same.
need to create ur own counter, means
l_index1 = 1 + l_index1.
then inside the second loop.
l_index2 = 1 + l_index2.
that's all
Regards
Miguel
05-16-2014 2:28 PM
Miguel,
Thanks for the reply.
Please see the code here:
Read table itab into wa with key.
if sy-subrc = 0.
index1 = sy-tabix.
loop at itab into wa1 from lw_index1.
read table itab1 into wa2 with key.
if sy-subrc = 0.
index = sy-tabix.
loop at itab1 into wa3 from index.
***** my code here****
index1 = index1 + 1.
endloop.
endif.
endloop.
endif.
05-16-2014 2:29 PM
05-16-2014 2:32 PM
hi.
it should work...just check the result that u expect to get.
Regards
Miguel
05-16-2014 2:43 PM
05-16-2014 2:50 PM
I think that no need of the first index in the first loop. Just need the index from the second loop...
loop at itab into wa1.
l_index1 = l_index1 + 1.
read table itab1 into wa2 with key.
if sy-subrc = 0.
loop at itab1 into wa3 from index1.
***** my code here****
endloop.
endif.
endloop.
if not...please explain the original request to understand it better.
Reards
Miguel
05-16-2014 3:13 PM
Miguel,
Thank you for the reply.
Basically the above code doesn't work for me.
I do the loop on the same table twice based on different conditions.
loop at itab into wa1 from index1.
read table itab into wa2 with key.
if sy-subrc = 0.
index = sy-tabix.
loop at itab into wa3 from index.
***** my code here****
index1 = index1 + 1.
endloop.
endif.
endloop.
05-16-2014 3:22 PM
ok..rare.
well, check this condition.
loop at itab into wa1 from index1.
read table itab into wa2 with key.
if sy-subrc = 0.
index = sy-tabix.
replace for
loop at itab into wa1 from index1.
index = index + 1.
read table itab into wa2 with key.
if sy-subrc = 0.
because sy-tabix always changes ...better to use ur own counter as i told you.
Regards
Miguel
05-16-2014 3:26 PM
Miguel,
Can you kindly explain more as its confusing. 🙂
Regards,
Vinod
05-16-2014 3:28 PM
you are using 2 loops, the variables are the same sy-tabix for both loops.
So rather than use sy-tabix, use a local variable that does the same.
l_index = l_index + 1.
replace the code that i sent u and check it.
Regards
Miguel
05-16-2014 3:32 PM
Miguel,
Sorry to ask but can you give me the code as I understood the explanation but not able to get how to write it.
Regards,
Vinod
05-16-2014 3:36 PM
loop at itab into wa1 from index1.
index = index + 1.
read table itab into wa2 with key.
if sy-subrc = 0.
loop at itab1 into wa3 from index.
***** my code here****
index1 = index1 + 1.
endloop.
endif.
endloop.
that's all
good luck...check the index...just index problem...
Regards
05-16-2014 3:51 PM
Miguel,
Its not working.
Index1 value is 8 when it comes out of second loop.
But when it goes to the first loop, it is starting from 5 as initially it had started from 4.
Regards,
Vinod
05-16-2014 4:12 PM
mmm...so why do you need the index1 in the first loop. that one should always be looping without index as i understood. sorry i dont get what u need...
Regards
Miguel
05-16-2014 2:13 PM
Hi Vinod,
Please refer below coding i think it will satisfies your requirements.
DATA: I TYPE I.
I = 1.
LOOP AT ITAB1 INTO WA1.
do.
READ TABLE ITAB2 INTO WA2 INDEX I.
IF SY-SUBRC <> 0. EXIT. ENDIF.
IF WA2-K < WA1-K.
ADD 1 TO I.
ELSEIF WA2-K = WA1-K.
" ...
ADD 1 TO I.
EXIT.
ELSE.
EXIT.
endif.
enddo.
if sy-subrc <> 0. exit. endif.
ENDLOOP.
Regards,
Thangam.P
05-23-2014 8:08 AM
I have resolved the problem myself.
Thank you so much guys for helping it out.
05-23-2014 8:14 AM
Hi Vinod,
we are happy to hear the problem has been solved by your self...
Regards,
Thangam.P
05-29-2014 7:54 AM
Since I was looping the same table twice.
I added the index inside the second loop.
Below shows the result:
Loop at itab1 into wa1.
read table itab1 into wa2 with key.
index1=sy-tabix.
loop at itab1 into wa3 from index1.
index 1 = index1 + 1.
*my code*
endloop.
endloop.