06-11-2007 12:58 PM
Hi expert!
I have this scenario:
<b>data: begin of tab1 occurs 0,
tipval(3) type n,
mat(18) type c,
anno(4) type n,
mese(2) type n,
eser(4) type n,
per(3) type n,
vpro(6) type c,
div(3) type c,
um(3) type c,
imp(9) type p decimals 2,
qty(9) type p decimals 3,
end of tab1.
data: begin of tab2 occurs 0,
tipval(3) type n as key,
mat(18) type c,
zmat(18) type c,
anno(4) type n,
mese(2) type n,
vpro(6) type c,
org(4) type c,
can(2) type c,
set(2) type c,
all(10) type c,
cpd(10) type c,
grp1(10) type c,
sgr(10) type c,
clf(10) type c,
clc(10) type c,
com(10) type c,
div(3) type c,
um(3) type c,
umb(3) type c,
imp(9) type p decimals 2,
qty(9) type p decimals 3,
qtyf(9) type p decimals 3,
end of tab2.
data: begin of tab3 occurs 0,
tipval(3) type n,
anno(4) type n,
mese(2) type n,
mat(18) type c,
zmat(18) type c,
vpro(6) type c,
org(4) type c,
can(2) type c,
set(2) type c,
all(10) type c,
cpd(10) type c,
grp1(10) type c,
sgr(10) type c,
clf(10) type c,
clc(10) type c,
com(10) type c,
div(3) type c,
um(3) type c,
umb(3) type c,
imp(9) type p decimals 2,
qtyf(9) type p decimals 3,
qty(9) type p decimals 3,
end of tab3.
loop at tab2.
loop at tab1 where mat = tab2-mat
and mese = tab2-mese
and anno = tab2-anno.
tab3-imp = ( tab1-imp / tab1-qty ) * tab2-qtyf.
tab3-tipval = '100'.
tab3-mat = tab2-mat.
tab3-zmat = tab2-zmat.
................
collect tab3.
endloop.
endloop.</b>
How I can improve the performances of this report?
Could you show me some efficient alternatives?
The system is very very slow when it executes this code.
Help me please.
Thanks in advance.
C.
06-11-2007 1:15 PM
Hi,
it is not advisable to use a loop in a loop.
However, if you still HAVE to use this then use loop from index for second loop.
e.g.
data: V_index type sy-tabix.
sort tab1 by mat mese anno.
sort tab1 by mat.
V_index = 1.
loop at tab2 into wa_tab2.
loop at tab1 index V_index into wa_tab1
if wa_tab1-mat > wa_tab2-mat.
V_index = sy-tabix.
exit.
elseif wa_tab1-mat = wa_tab2-mat
and wa_tab1-mese = wa_tab2-tab2-mese
and wa_tab1-anno = wa_tab2-tab2-anno.
<b>.
.
.
.</b>
Hope that this helps you,
Regards,
Sooness.
06-11-2007 1:04 PM
Hi
How you wrote the select statements?
You have not pasted them.
Are they are not consuming time?
In the loops..
first the 3 ITABs should have some common fields
then loop one ITAB
then read the ITAB and ITAB3 with the key fields
instead of looping them again..
<b>Reward points for useful Answers</b>
Regards
Anji
06-11-2007 1:05 PM
Hi Claudia ,
try this:
if not tab2[] is initial.
sort tab1 by mat mese anno.
loop at tab2.
read table tab1 transporting no fields with key mat = tab2-mat
mese = tab2-mese
anno = tab2-anno
binary search.
if sy-subrc eq 0.
tab3-imp = ( tab1-imp / tab1-qty ) * tab2-qtyf.
tab3-tipval = '100'.
tab3-mat = tab2-mat.
tab3-zmat = tab2-zmat.
endif.
................
collect tab3.
endloop.
endif.
*Reward if helps.
06-11-2007 1:14 PM
What is tab1 has more than 1 entry for mat in tab2?
you can try some of following:
sort both tab1 & tab2,
Do not use collect ab3 but use APPEND and then at the end sort tab3 and then do add/subtraction.
06-11-2007 1:15 PM
Hi,
it is not advisable to use a loop in a loop.
However, if you still HAVE to use this then use loop from index for second loop.
e.g.
data: V_index type sy-tabix.
sort tab1 by mat mese anno.
sort tab1 by mat.
V_index = 1.
loop at tab2 into wa_tab2.
loop at tab1 index V_index into wa_tab1
if wa_tab1-mat > wa_tab2-mat.
V_index = sy-tabix.
exit.
elseif wa_tab1-mat = wa_tab2-mat
and wa_tab1-mese = wa_tab2-tab2-mese
and wa_tab1-anno = wa_tab2-tab2-anno.
<b>.
.
.
.</b>
Hope that this helps you,
Regards,
Sooness.
06-11-2007 1:17 PM
HI,
correction:
data: V_index type sy-tabix.
sort tab1 by mat mese anno.
sort tab1 by mat.
V_index = 1.
loop at tab2 into wa_tab2.
loop at tab1 from V_index into wa_tab1
if wa_tab1-mat > wa_tab2-mat.
V_index = sy-tabix.
exit.
elseif wa_tab1-mat = wa_tab2-mat
and wa_tab1-mese = wa_tab2-tab2-mese
and wa_tab1-anno = wa_tab2-tab2-anno.
.
.
.
.
Hope that this helps you,
Regards,
Sooness.