‎2006 Sep 10 2:06 PM
What is the best way to fix this loop performance wise?
loop at i_vbak.
loop at i_vbap where vbeln = i_vbak-vbeln.
loop at i_vbep where vbeln = i_vbep-vbeln.
xxxxxxxx
xxxxxxxx
endloop.
endloop.
endloop.
and also .... do you see any errors/performance issues with these statements. Please donot take "select" query in to consideration. of course "sort i_vbak" is one that needs to be considered i guess
select * into i_vbak.
read table i_vbak where vbeln = 'xxx'
posnr = 'yyy'
vkorg = 'zzz'
binary search.
Thanks in advance. Enjoy! your weekends.
Mary
‎2006 Sep 10 2:25 PM
Hi
It depends on number of hits inserted in the internal table. U can try to improve the performance using SORTED TABLE:
DATA: I_VBAP TYPE SORTED TABLE OF VBAP WITH NON-UNIQUE KEY VBELN WITH HEADER LINE,
I_VBEP TYPE SORTED TABLE OF VBEP WITH NON-UNIQUE KEY VBELN WITH HEADER LINE.
loop at i_vbak.
loop at i_vbap where vbeln = i_vbak-vbeln.
loop at i_vbep where vbeln = i_vbep-vbeln.
xxxxxxxx
xxxxxxxx
endloop.
endloop.
endloop.
- U have to sort your table before using BINARY SEARCH options:
SORT TABLE BY VBELN VKORG.
READ TABLE VBAK WITH KEY VBELN = ...
VKORG = .... binary search.
Max
‎2006 Sep 10 2:25 PM
Hi
It depends on number of hits inserted in the internal table. U can try to improve the performance using SORTED TABLE:
DATA: I_VBAP TYPE SORTED TABLE OF VBAP WITH NON-UNIQUE KEY VBELN WITH HEADER LINE,
I_VBEP TYPE SORTED TABLE OF VBEP WITH NON-UNIQUE KEY VBELN WITH HEADER LINE.
loop at i_vbak.
loop at i_vbap where vbeln = i_vbak-vbeln.
loop at i_vbep where vbeln = i_vbep-vbeln.
xxxxxxxx
xxxxxxxx
endloop.
endloop.
endloop.
- U have to sort your table before using BINARY SEARCH options:
SORT TABLE BY VBELN VKORG.
READ TABLE VBAK WITH KEY VBELN = ...
VKORG = .... binary search.
Max
‎2006 Sep 10 2:40 PM
Hi,
use below logic to increse performance
sort i_vbak by vbeln.
sort i_vbap by vbeln posnr.
sort i_vbep by vbeln posnr .
data lv_index like sy-tabix.
lv_index1 like sy-tabix.
loop at i_vbak.
clear lv_index,lv_index1.
read table i_vbap with key vbeln = i_vbak-vbeln
binary search.
if sy-subrc eq 0.
lv_index = sy-tabix.
loop at i_vbap from lv-index.
if i_vbap-vbeln <> i_vbak-vbeln.
exit.
endif.
read table i_vbep with key vbeln = i_vbap-vbeln
posnr = i_vbap-posnr
binary search.
if sy-subrc eq 0.
lv_index1 = sy-tabix.
loop at i_vbep from lv-index1.
if i_vbep-vbeln <> i_vbak-vbeln.
exit.
endif.
endloop.
endif.
endloop.
endif.
Regards
Amole
‎2006 Sep 11 8:46 AM
no it did not improve performance any way
pls ans 2nd question too plez
‎2006 Sep 11 8:55 AM
select * into i_vbak.
select only those field which are required.
and use into table.
select field1 field2 into table i_vbak from vbak where cond.
<b>sort i_vbak .</b>
read table i_vbak <b>with key</b> vbeln = 'xxx'
posnr = 'yyy'
vkorg = 'zzz'
binary search.
<b>don't use nested loop.</b>
it is better u 1st take join b/w vbak and vbap.
loop at i_vbak.
loop at i_vbap where vbeln = i_vbak-vbeln.
loop at i_vbep where vbeln = i_vbep-vbeln.
xxxxxxxx
xxxxxxxx
endloop.
endloop.
endloop.
‎2006 Sep 11 9:16 AM
First of all nested loop is not good..we should always try and avoid it. As for your required since you dont want to use SELECT..is to surely sort the internal tables.
sort i_vbak.
sort i_vbap.
sort i_vbep.
loop at i_vbak.
clear i_vbap.
loop at i_vbap where vbeln = i_vbak-vbeln.
clear i_vbep.
read table i_vbep with key vbeln = i_vbap-vbeln
and posnr = i_vbap-posnr.
if sy-subrc = 0.
endif.
endloop.
endloop.
--Try the above logic..
Regards
Anurag