Skip to Content
0
Former Member
Jan 19, 2012 at 09:43 AM

Bad performance of MKPF / MSEG selects

641 Views

Hi,

I am working on report for performance issue.

select-options : matnr FOR  mara-matnr,
                         mtart FOR  mara-mtart,
                         werks FOR  mseg-werks NO INTERVALS,
                          lgort FOR  mseg-lgort NO INTERVALS,
                         budat FOR  mkpf-budat ,"OBLIGATORY,
                         reci  FOR  mseg-bwart ,"OBLIGATORY NO INTERVALS,
                         iss   FOR  mseg-bwart ."

select queries are followings but inside loop.

loop at itab.

at new matnr.
SELECT SUM( MENGE ) INTO qty1 from mkpf inner join mseg on
 MKPF~MBLNR = MSEG~MBLNR and MKPF~MJAHR = MSEG~MJAHR
 WHERE MSEG~MATNR = itab-MATNR AND WERKS in WERKS
 AND BUDAT < BUDAT-LOW and SHKZG = 'S'
 AND  BWART IN ('561','105','101','309','701'). 



SELECT SUM( MENGE ) INTO qty2 from mkpf inner join mseg on
 MKPF~MBLNR = MSEG~MBLNR and MKPF~MJAHR = MSEG~MJAHR
 WHERE MSEG~MATNR = itab-MATNR AND WERKS in WERKS
 AND BUDAT < BUDAT-LOW and SHKZG = 'H'
 AND  BWART IN ('562','201','261','502','543','333','551' ) .

SELECT SUM( MENGE ) INTO r_qty1 from mkpf inner join mseg on
 MKPF~MBLNR = MSEG~MBLNR and MKPF~MJAHR = MSEG~MJAHR
 WHERE MSEG~MATNR = itab-MATNR AND WERKS in WERKS
 AND BUDAT IN BUDAT AND SHKZG = 'S' AND
bwart in reci.


SELECT SUM( MENGE ) INTO R_qty2 from mkpf inner join mseg on
 MKPF~MBLNR = MSEG~MBLNR and MKPF~MJAHR = MSEG~MJAHR
 WHERE MSEG~MATNR = itab-MATNR AND WERKS in WERKS
 AND BUDAT IN BUDAT and SHKZG = 'H'
and bwart in reci.

SELECT SUM( menge ) INTO q1_qty1 from mkpf inner join mseg on
 MKPF~MBLNR = MSEG~MBLNR and MKPF~MJAHR = MSEG~MJAHR
 WHERE MSEG~MATNR = itab-MATNR AND WERKS in WERKS
 AND BUDAT IN BUDAT AND SHKZG = 'S' AND
bwart in iss.

SELECT SUM( menge ) INTO q1_qty2 from mkpf inner join mseg on
 MKPF~MBLNR = MSEG~MBLNR and MKPF~MJAHR = MSEG~MJAHR
 WHERE MSEG~MATNR = itab-MATNR AND WERKS in WERKS
 AND BUDAT IN BUDAT AND SHKZG = 'S' AND
bwart in iss.

after that  calculations.. 

endat.

endloop.

Its performance is very poor. It takes lot much time to get output.

I want to replace the code with for all entries..

Then 2 slect statements based on mkpf table

1 ) for budat in budat

2) for budat > budat-low.

the based on this 8- 10 select statement from mseg table.

how to get into final table all data ....