‎2007 Dec 07 8:54 PM
Hi experts,
I have the following select statement which has three levels of inner joins.
SELECT pplnty pplnnr pplnkn mplnal mwerks mmatnr mr~meins
pvornr psteus sdatuv sloekz INTO TABLE it_group
FROM ( ( plpo AS p
INNER JOIN plas AS s ON splnty = pplnty AND
splnnr = pplnnr AND splnkn = pplnkn )
INNER JOIN mapl AS m ON mplnty = splnty AND
mplnnr = splnnr AND mplnal = splnal )
INNER JOIN mara AS mr ON mrmatnr = mmatnr
FOR ALL ENTRIES IN it_valid_opr
WHERE p~plnty = c_routing
AND p~plnnr = it_valid_opr-plnnr
AND sdatuv <= p_valdt AND mplnty =
c_routing AND mdatuv <= p_valdt AND mloekz <> c_x .
i have some 2500 entries in the internal table it_valid_opr. This query is taking very long time to get executed. Any anyone suggest an alternative for the above SELECT query.
‎2007 Dec 07 9:15 PM
You have one expression in both a JOIN condition and the WHERE. I'd remove it from the WHERE:
SELECT p~plnty p~plnnr p~plnkn m~plnal m~werks m~matnr mr~meins
p~vornr p~steus s~datuv s~loekz
INTO TABLE it_group
FROM ( ( plpo AS p
INNER JOIN plas AS s
ON s~plnty = p~plnty AND
s~plnnr = p~plnnr AND
s~plnkn = p~plnkn )
INNER JOIN mapl AS m
ON m~plnty = s~plnty AND
m~plnnr = s~plnnr AND
m~plnal = s~plnal )
INNER JOIN mara AS mr
ON mr~matnr = m~matnr
FOR ALL ENTRIES IN it_valid_opr
WHERE p~plnty = c_routing
AND p~plnnr = it_valid_opr-plnnr
AND s~datuv <= p_valdt
* AND m~plnty = c_routing "<====
AND m~datuv <= p_valdt
AND m~loekz <> c_x .Rob
‎2007 Dec 07 9:29 PM
Thanks for ur quick reply. But is this the only reason wat is causing the performance slow down?
‎2007 Dec 07 9:52 PM
Performance can be bad for any number of reasons. The JOIN looks OK. How many records does it bring back?
Rob
‎2007 Dec 07 9:32 PM
Hi,
Types: begin of ty_plpo,
plnty type plnty,
plnnr type plnnr,
plnkn type plnkn,
vornr type vornr,
steus type steus,
end of ty_plpo,
begin of ty_plas,
plnty type plnty,
plnnr type plnnr,
plnal type plnal,
datuv type datuv,
loekz type loekz,
end of ty_plas,
begin of ty_mapl,
plnty type plnty,
plnnr type plnnr,
plnkn type plnkn,
plnal type plnal,
werks type werks_d,
matnr type matnr,
end of ty_mapl,
begin of ty_mara,
matnr type matnr,
meins type meins,
end of ty_mara.
Data: it_plpo type table of ty_plpo,
it_mplo type table of ty_mplo,
it_mapl type table of ty_mapl,
it_mara type table of ty_mara.
if it_valid_opr[] is not intial.
SELECT plnty plnnr plnkn vornr steus from plpo into table it_plpo for all entries in it_valid_opr
where plnty = c_routing
and plnnr = it_valid_opr-plnnr.
if sy-subrc = 0.
select plnty plnnr plnal datuv loekz from plas into table it_plas for all entries in it_mplo
where plnty = it_mplo-plnty
and plnnr = it_mplo-plnnr
and plnkn = it_mplo-plnkn
and datuv LE p_valdt.
if sy-subrc = 0.
select plnty plnnr plnkn plnal werks matnr from mapl into table it_mapl for all entries in it_plas
where plnty = it_plas-plnty
and plnnr = it_plas-plnnr
and plnkn = it_plas-plnal
or plnty = c_routing
and datuv LE p_valdt.
if sy-subrc = 0.
delete it_mapl where loekz EQ c_x.
select matnr meins from mara into table it_mara for all entries in it_mapl
where matnr = it_mapl-matnr.
endif.
endif.
endif.
endif.Regards,
Satish
‎2007 Dec 07 10:00 PM
‎2007 Dec 07 10:16 PM
Well, that's probably it then. One of the first rules of performance tuning is to keep the selection set small. 300,000 records isn't huge, but it isn't small either. Coupled with the fact that you aren't using the entire key.
Rob