Skip to Content
0
Former Member
Aug 29, 2009 at 11:31 AM

mska and mssa query slow

177 Views

Hi experts,

How to optimize and correct this query.

SELECT mska~matnr mska~werks lgort charg mska~sobkz
           mska~vbeln mska~posnr
           kalab kains kaspe kaein kzbws
           INTO (collector-matnr, collector-werks, collector-lgort,
                 collector-charg, collector-sobkz,
                 collector-vbeln, collector-posnr,
                 collector-labst, collector-insme, collector-speme,
                 collector-einme, collector-kzbws)
           FROM mska INNER JOIN mssa
           ON   mska~matnr = mssa~matnr
            AND mska~werks = mssa~werks
            AND mska~sobkz = mssa~sobkz
            AND mska~vbeln = mssa~vbeln
            AND mska~posnr = mssa~posnr
           FOR ALL entries IN t_mat
           WHERE mska~matnr = t_mat-matnr
             AND mska~werks = t_mat-werks
             AND mska~sobkz NE 'W'
             AND mska~lgort IN lgort
             AND mska~charg IN charg.

      PERFORM                f2000_collect_collector.
    ENDSELECT.
*----------------------------------------------------------------------*
FORM f2000_collect_collector.
*----------------------------------------------------------------------*
* process the functions "No zero stocks",
* "Negative stocks only", "Without batches" here
*----------------------------------------------------------------------*
  IF negativ = 'X'.
*   ignore entry if all stocks are zero or greater
    IF collector-labst >= 0 AND collector-einme >= 0 AND
       collector-insme >= 0 AND collector-retme >= 0 AND
       collector-speme >= 0 AND collector-umlme >= 0.
      EXIT.                  "--> go to exit
    ENDIF.
  ENDIF.

  IF nozero = 'X'.
*   ignore all entries without stock
    IF collector-labst = 0 AND collector-einme = 0 AND
       collector-insme = 0 AND collector-retme = 0 AND
       collector-speme = 0 AND collector-umlme = 0.
      EXIT.                  "--> go to exit
    ENDIF.
  ENDIF.
  IF xmchb IS INITIAL.
    CLEAR collector-charg.
  ENDIF.
  COLLECT                    collector.
ENDFORM.                     "f2000_COLLECT_collector.