‎2009 Jun 10 7:14 AM
Hi all,
I am having a performance issue.
it_coepd1 is having around 50000 records with condition abwst = '09' and for every record of this Outer loop there are Twice the No of Records in the Inner loop for both it_coepd & it_coep i.e 1,00,000 records.
We need to delete the Records matching the condition...
Kindly tell me which of the blow code gives better performance..
1)
LOOP AT it_coepd1 INTO w_coepd where abwst EQ '09'.
loop at it_coepd where kokrs = w_coepd-kokrs and
belnr = w_coepd-belnr and
buzei = w_coepd-buzei.
delete it_coepd.
endloop.
loop at it_coep where kokrs = w_coepd-kokrs and
belnr = w_coepd-belnr and
buzei = w_coepd-buzei.
delete it_coep.
endloop.
Endloop.
2)
LOOP AT it_coepd1 INTO w_coepd where abwst EQ '09'.
DELETE it_coepd WHERE kokrs = w_coepd-kokrs
AND belnr = w_coepd-belnr
AND buzei = w_coepd-buzei.
DELETE it_coep WHERE kokrs = w_coepd-kokrs
AND belnr = w_coepd-belnr
AND buzei = w_coepd-buzei.
Endloop.
Moderator message - The correct response was to try it before asking the forum - thread locked
Edited by: Rob Burbank on Jun 10, 2009 9:39 AM
‎2009 Jun 10 7:31 AM
Use inernal table of type sorted or hashed for large no of data
for example
DATA : it_temp_coepd like sorted table of it_coepd with non-unique key kokrs belnr buzei.
now move data
it_temp_coepd[] = it_coepd[].
now process on it_temp_coepd.
Regars,
Alpesh
Edited by: Alpesh on Jun 10, 2009 12:01 PM
‎2009 Jun 10 7:26 AM
why not check it for ur self.
data:
W_RUNTIME1 TYPE I,
W_RUNTIME2 TYPE I,
W_RUNTIME3 TYPE I,
W_RUNTIME4 TYPE I.
get RUN TIME FIELD w_runtime1.
LOOP AT it_coepd1 INTO w_coepd where abwst EQ '09'.
loop at it_coepd where kokrs = w_coepd-kokrs and
belnr = w_coepd-belnr and
buzei = w_coepd-buzei.
delete it_coepd.
endloop.
loop at it_coep where kokrs = w_coepd-kokrs and
belnr = w_coepd-belnr and
buzei = w_coepd-buzei.
delete it_coep.
endloop.
Endloop.
get RUN TIME FIELD w_runtime2.
w_runtime2 = w_runtime2 - w_runtime1.
write w_runtime2.
get RUN TIME FIELD w_runtime3.
LOOP AT it_coepd1 INTO w_coepd where abwst EQ '09'.
DELETE it_coepd WHERE kokrs = w_coepd-kokrs
AND belnr = w_coepd-belnr
AND buzei = w_coepd-buzei.
DELETE it_coep WHERE kokrs = w_coepd-kokrs
AND belnr = w_coepd-belnr
AND buzei = w_coepd-buzei.
Endloop
get RUN TIME FIELD w_runtime4.
w_runtime4 = w_runtime4 - w_runtime3.
write w_runtime4.Use the above code to check the performance urself.
I also suggest u to take a look at implementing parallel cursor technique in ur code to improve ur performance.
see this thread for help
Edited by: Kartik Tarla on Jun 10, 2009 11:57 AM
Edited by: Kartik Tarla on Jun 10, 2009 11:58 AM
‎2009 Jun 10 7:29 AM
You can find it yourself using SE30 transaction.
Select Tips and tricks in application toolbar in SE30.
Post your code and see the measure runtime.
I guess the second will give you the better performance.
‎2009 Jun 10 7:31 AM
Use inernal table of type sorted or hashed for large no of data
for example
DATA : it_temp_coepd like sorted table of it_coepd with non-unique key kokrs belnr buzei.
now move data
it_temp_coepd[] = it_coepd[].
now process on it_temp_coepd.
Regars,
Alpesh
Edited by: Alpesh on Jun 10, 2009 12:01 PM
‎2009 Jun 10 7:39 AM
Forget the cursor technique it is nowhere described for the general case.
Normal LOOPs and READs are absolutely suifficient.
You programm is automatically fine, if you switch the second loop to a sorted table, i.e.
a table with an index.
Without index is MUST be slow!!!!
How to optimize LOOP WHERE on standard tables can be found here, section 3,
READ BINARY SEARCH, LOOP FROM INDEX and EXIT condfition !!!!!!
Measurements on internal tables: Reads and Loops:
/people/siegfried.boes/blog/2007/09/12/runtimes-of-reads-and-loops-on-internal-tables
Also for the delete use it with index, store tabix = sy-tabix after the loop.
Siegfried
‎2009 Jun 10 12:38 PM
for every record of this Outer loop there are Twice the No of Records in the Inner loop for both it_coepd & it_coepi think this clears everything. sry if my early post was Uncivil.
but ppl do understand that a person having lesser points does not mean his dum or he cant write wiki's
Nafran
‎2009 Jun 10 9:18 AM
this code will be very fast.
data: lv_index type sy-index,
lv_index2 type sy-index,
lv_index3 type sy-index.
sort it_coepd1 by abwst kokrs belnr buzei.
sort it_coepd by abwst kokrs belnr buzei.
sort it_coep rom by abwst kokrs belnr buzei.
read table it_coepd1
into w_coepd
with key abwst EQ '09' binary search.
lv_index = sy-tabix.
LOOP AT it_coepd1 INTO w_coepd from lv_index.
if w_coepd-abwst = '09'.
loop at it_coepd from lv_index1.
if kokrs ne w_coepd-kokrs or belnr ne w_coepd-belnr or
buzei ne w_coepd-buzei.
lv_index1 = sy-tabix.
exit.
endif.
delete it_coepd.
endloop.
loop at it_coep rom lv_index1.
if kokrs ne w_coepd-kokrs ne belnr = w_coepd-belnr ne
buzei = w_coepd-buzei.
lv_index2 = sy-tabix.
exit.
endif.
delete it_coep.
endloop.
endif.
Endloop.check this link for more.
[http://nafran.blogspot.com/2009/05/best-way-to-code-nested-loops-sap.html|http://nafran.blogspot.com/2009/05/best-way-to-code-nested-loops-sap.html]
Nafran
‎2009 Jun 10 11:41 AM
This code is fast, but it is not correct!
LOOP AT it_coepd1 INTO w_coepd from lv_index.
if w_coepd-abwst = '09'.
loop at it_coepd from lv_index1.
Use not three condition but only one:
itab1
a
b
d
itab2
a
c
d
As value c is missing in itab1, it will never continue!
Also the three sorts are not necessary.
The sorted or hashed table are the BEST SOLUTIONS!, the optimization with the binary search is
the other solution. There is no need for additional solutions.
Siegfried
‎2009 Jun 10 11:50 AM
Edited by: Matt on Jun 10, 2009 1:18 PM - removed rude reply
‎2009 Jun 10 12:21 PM