Skip to Content
0
Mar 24, 2020 at 09:22 AM

Select Query takes too long time

482 Views

Hello,
I made a selection query from table AFRU but it is taking too long time to execute.
What can I do to optimize it?
This is the query:
SELECT a~werks a~aufnr a~budat a~vornr a~grund a~zzcurrency a~stokz SUM( a~xmnga ) AS xmnga SUM( a~zzscrapvalue) AS zzscrapvalue SUM( a~lmnga ) AS lmnga b~lead_aufnr b~plnbez c~matnr d~arbpl e~steus e~ltxa1

FROM afru AS a

INNER JOIN afko AS b ON b~aufnr = a~aufnr
INNER JOIN afpo AS c ON c~aufnr = b~aufnr
INNER JOIN s022 AS d ON d~aufnr = b~aufnr AND d~werks = p_werks AND d~matnr = b~plnbez AND d~posnr = c~posnr
INNER JOIN afvc AS e ON e~aufpl = b~aufpl AND e~plnfl = d~plnfl AND e~vornr = d~vornr
INTO CORRESPONDING FIELDS OF TABLE gt_dummy
WHERE a~werks = p_werks
AND a~ersda = p_ersda
GROUP BY a~werks a~aufnr a~budat a~vornr a~grund a~zzcurrency a~stokz b~lead_aufnr b~plnbez c~matnr d~arbpl e~steus e~ltxa1.
I can't put another selection parameter because the query must work with only plant and confirmation entry date.
I did a test with a confirmation date that had 15.000+ records in table AFRU and the query took 20+ min to execute..

Thank you for your help!
Alex