‎2008 Jun 23 1:33 PM
what are the other alternative of avoiding loop withing loop , as it will increase lots of processing and load on system.
I know these options :
1. for all entries in
2. Joins
but it is also not much fruitful as it is having some disadvantages.
‎2008 Jun 23 1:56 PM
Hi as you suggested you can use FOR ALL ENTRIES and JOINS but in case you are not able to check out the Parallel Cursor Method which avoids the nested loop.
Check out these codes :
Conventional Method
loop at lt_vbpa into wa_vbpa.
loop at lt_kna1 into wa_kna1 where kunnr = wa_vbpa-kunnr.
****** Your Actual logic within inner loop ******
endloop.
endloop.
Parallel Cursor Method
sort: lt_vbpa by kunnr, "Sorting by key is very important
lt_kna1 by kunnr. "Same key which is used for where condition is used here
loop at lt_vbpa into wa_vbpa.
read lt_kna1 into wa_kna1 " This sets the sy-tabix
with key kunnr = wa_vbpa-kunnr
binary search.
if sy-subrc = 0. "Does not enter the inner loop
v_kna1_index = sy-tabix.
loop at lt_kna1 into wa_kna1 from v_kna1_index. "Avoiding Where clause
if wa_kna1-kunnr <> wa_vbpa-kunnr. "This checks whether to exit out of loop
exit.
endif.
****** Your Actual logic within inner loop ******
endloop. "KNA1 Loop
endif.
endloop. " VBPA Loop
Reward if helpful.
Regards.
‎2008 Jun 23 1:34 PM
‎2008 Jun 23 1:35 PM
Hi,
Follow these links...
http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb3b23358411d1829f0000e829fbfe/content.htm
http://www.saptechnical.com/Tutorials/ABAP/ParallelCursor.htm
http://learnabap.blogspot.com/2007/05/performance-tuning-using-parallel.html
http://karsap.blogspot.com/2007/06/avoiding-nested-loops-using-parallel_19.html
Reward points if useful....
Regards
Azad
‎2008 Jun 23 1:36 PM
‎2008 Jun 23 1:36 PM
hiiii
you can use parallel cursor method to avoid it..use it like below.
clear it_s.
clear it_e.
DATA: incd TYPE i, incs TYPE i,inci TYPE i, incf TYPE i.
DATA: it_tmp TYPE ty_t_data WITH HEADER LINE.
it_tmp[] = it_prd[].
DATA: inc TYPE i.
LOOP AT it_prd.
READ TABLE it_chs WITH KEY
spras w_langu
msehi = it_prd-msehi.
w_tmp = it_prd-msehi.
IF sy-subrc NE 0.
WRITE:/ w_tmp.
APPEND it_prd TO it_s.
incs = incs + 1.
ENDIF.
if sy-subrc EQ 0.
append it_prd to it_e.
endif.
ENDLOOP.reward if useful
thx
twinkal
‎2008 Jun 23 1:36 PM
Hi,
In your previous thread, it was suggested Join can be used.
try that, if not use FOR ALL ENTRIES.
if both are not possible, then use parallel cursor method, as suggested by everyone.
regards,
madhu
‎2008 Jun 23 1:37 PM
Hi,
First loop at 1st itab and then read 2nd itab.Both the internal tables should have one common key field.
e.g.
Loop at itab.
read table itab2 with key k1 = itab1-key.
-
-
endloop.
‎2008 Jun 23 1:46 PM
Hi,
Please find the link below which has a tutorial on using the Parallel Cursor which can be a very good alternative to Loop within Loop.
http://www.saptechnical.com/Tutorials/ABAP/ParallelCursor.htm
Reward if helpful.
Warm Regards,
R Adarsh
‎2008 Jun 23 1:56 PM
Hi as you suggested you can use FOR ALL ENTRIES and JOINS but in case you are not able to check out the Parallel Cursor Method which avoids the nested loop.
Check out these codes :
Conventional Method
loop at lt_vbpa into wa_vbpa.
loop at lt_kna1 into wa_kna1 where kunnr = wa_vbpa-kunnr.
****** Your Actual logic within inner loop ******
endloop.
endloop.
Parallel Cursor Method
sort: lt_vbpa by kunnr, "Sorting by key is very important
lt_kna1 by kunnr. "Same key which is used for where condition is used here
loop at lt_vbpa into wa_vbpa.
read lt_kna1 into wa_kna1 " This sets the sy-tabix
with key kunnr = wa_vbpa-kunnr
binary search.
if sy-subrc = 0. "Does not enter the inner loop
v_kna1_index = sy-tabix.
loop at lt_kna1 into wa_kna1 from v_kna1_index. "Avoiding Where clause
if wa_kna1-kunnr <> wa_vbpa-kunnr. "This checks whether to exit out of loop
exit.
endif.
****** Your Actual logic within inner loop ******
endloop. "KNA1 Loop
endif.
endloop. " VBPA Loop
Reward if helpful.
Regards.