2009 Jan 27 3:24 PM
Hi,
I have this code and its really slow. My question is how to make it faster since its taking about 10 hours.
Code:
loop at ti_equi.
select matnr sernr lief_nr kunde datum uzeit bwart posnr
appending corresponding fields of table ti_ser01
from z_objk_ser01
where sernr eq ti_equi-sernr
and matnr eq ti_equi-matnr.
endloop.
delete ti_ser01 where not ( kunde in s_kunnr and
bwart = '631' ).
sort ti_ser01 by matnr sernr datum descending uzeit descending.
delete adjacent duplicates from ti_ser01 comparing matnr sernr.
What this code does is fetch all these fields and then just keeps the one that's been modified at last.
I have created an index by sernr and matnr in table objk which makes it just a little bit faster.
Any helpful answer will be appreciated.
Regards,
Roberto
Edited by: Julius Bussche on Jan 27, 2009 4:29 PM
Code tags added. Please use more meaningfull subject titles
2009 Jan 27 3:29 PM
Hi Robetro,
Generally avoid SELECT inside LOOPs. Get the data from database tables into internal tables and use either LOOP in a LOOP (or) READ statement inside a LOOP.
I suppose in your casae you can use JOIN between EQUI and Z_OBJK_SER01 to get the data.
Thanks,
Vinay
Edited by: Vinaykumar G on Jan 27, 2009 9:00 PM
2009 Jan 27 3:29 PM
Hi Robetro,
Generally avoid SELECT inside LOOPs. Get the data from database tables into internal tables and use either LOOP in a LOOP (or) READ statement inside a LOOP.
I suppose in your casae you can use JOIN between EQUI and Z_OBJK_SER01 to get the data.
Thanks,
Vinay
Edited by: Vinaykumar G on Jan 27, 2009 9:00 PM
2009 Jan 27 3:31 PM
First of all, have you used ST05 to make sure that the SELECT is actually using your index?
Rob
2009 Jan 27 3:34 PM
Yes i have. It is using it.
Isnt there a way just to fetch the last modified register from the table SER01?
Regards,
Roberto
2009 Jan 27 6:16 PM
Hi roberto
please avoid select statment inside loop.
use code
-
data: index type sy-tabix.
data : ti-ser011 type standard table of zobjk-ser01 with header line.
select matnr sernr lief_nr kunde datum uzeit bwart posnr
from z_objk_ser01 into table ti_ser01.
sort ti_ser01 by sernr matnr.
sort ti_equi by sernr matnr.
index = 1.
loop at ti_equi.
loop at ti_ser01 from index
if ti_ser01-sernr = ti_equi-sernr
and ti_ser01-matnr = ti_equi-matnr.
move-corresponding ti_ser01 to ti_ser011.
append ti_ser011.
index = sy-tabix.
exit.
endif.
endloop.
endloop.
here i have used one more internal table ti_ser011.
you can delete specific record from ti_ser01 internal table on condition. at that time u don't need to create any other internal table like ti-ser011.
in place of loop select statement---endloop.
you can use this code. I think it will help you.
please find if it is udeful.
2009 Jan 28 6:06 AM
1) Avoid select query within the Loop -
instead fetch the records of the select query into an internal table and read them within main Loop.
2) Avoid appending corresponding field's statement within the select query
It will be of much help.
Regards,
CK
2009 Jan 28 6:46 AM
1.dont use select within loop.
2. dont use correspondig .
3.use where condition rather than delete outside the loop.
2009 Jan 28 12:36 PM
there are actually quite a lots of bugs in such a short pice of coding
from z_objk_ser01
where sernr eq ti_equi-sernr
and matnr eq ti_equi-matnr.
endloop.
delete ti_ser01 where not ( kunde in s_kunnr and
bwart = '631' ).
How is the table z_objk_ser01 defined, it must be different from ser01.
Why don't you check kunde and bwart in WHERE-condition, it is not a good idea to select the data
and delete it later, it is actually the worst you can do.
delete adjacent duplicates from ti_ser01 comparing matnr sernr.
It is much better to do that on ti_equi, save again records to be selected.
If there are still duplicates, then do it again, the operations on the internal tables are fast.
Siegfried
2009 Jan 28 8:15 PM