Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

MSKA query performance

Hi,

How to optimize this query ? When i monitored my programme from ST05,most of time is spending in this query.

    SELECT c~vbeln c~auart c~kunnr d~name1 e~kdmat e~posnr e~arktx

                 e~abgru

                 b~mtart b~zz_ugerw AS urungr

                 a~matnr f~maktx a~lgort a~charg a~kalab a~kains

                 a~kaspe b~meins a~werks b~matkl h~bwtar i~strgr e~cuobj

                 c~vkorg c~vtweg

                 e~matnr AS sipmat

            INTO CORRESPONDING FIELDS OF TABLE tb_mska

            FROM mska AS a

            INNER JOIN mara AS b ON b~matnr = a~matnr

            INNER JOIN vbak AS c ON c~vbeln = a~vbeln

            INNER JOIN marc AS i ON i~matnr = a~matnr

                                AND i~werks = a~werks

            LEFT  JOIN kna1 AS d ON d~kunnr = c~kunnr

            INNER JOIN vbap AS e ON e~vbeln = a~vbeln

                                AND e~posnr = a~posnr

            LEFT  JOIN makt AS f ON a~matnr = f~matnr

                                AND f~spras = sy-langu

            LEFT  JOIN mcha AS h ON a~matnr = h~matnr

                                AND a~werks = h~werks

                                AND a~charg = h~charg

            WHERE a~matnr IN so_matnr

              AND a~werks IN so_werks

              AND a~lgort IN so_lgort

              AND a~charg IN so_charg

              AND a~vbeln IN so_vbeln

              AND e~posnr IN so_posnr

              AND b~mtart IN so_mtart

              AND c~kunnr IN so_kunnr

              AND c~auart IN so_auart

              AND c~abrvw IN so_abrvw

              AND e~matnr IN so_sipma

              AND ( a~kalab NE 0

                OR   a~kains NE 0

                OR   a~kaspe NE 0 ) .

Former Member
replied

Hi,

Don't use the left join command

SELECT c~vbeln c~auart d~name1 e~kdmat e~posnr e~arktx

                 e~abgru

                 b~mtart b~zz_ugerw AS urungr

                 a~matnr a~lgort a~charg a~kalab a~kains

                 a~kaspe b~meins a~werks b~matkl i~strgr e~cuobj

                 c~vkorg c~vtweg

                 e~matnr AS sipmat

            INTO CORRESPONDING FIELDS OF TABLE tb_mska

            FROM mska AS a

            INNER JOIN mara AS b ON b~matnr = a~matnr

            INNER JOIN vbak AS c ON c~vbeln = a~vbeln

            INNER JOIN marc AS i ON i~matnr = a~matnr

                                AND i~werks = a~werks

            INNER JOIN vbap AS e ON e~vbeln = a~vbeln

                                AND e~posnr = a~posnr.

            WHERE a~matnr IN so_matnr

              AND a~werks IN so_werks

              AND a~lgort IN so_lgort

              AND a~charg IN so_charg

              AND a~vbeln IN so_vbeln

              AND e~posnr IN so_posnr

              AND b~mtart IN so_mtart

              AND c~kunnr IN so_kunnr

              AND c~auart IN so_auart

              AND c~abrvw IN so_abrvw

              AND e~matnr IN so_sipma

              AND ( a~kalab NE 0

                OR   a~kains NE 0

                OR   a~kaspe NE 0 ) .

LOOP AT tb_mska.

   select single name1 into tb_mska-name1 from kna1 where kna1  = tb_mska-kunnr.

   select single maktx into tb_mska-maktx from makt where matnr = tb_mska-matnr and spras = sy-langu.

   select single bwtar into tb_mska-bwtar from mcha where matnr = tb_mska-matnr and werks = tb_mska-werks and charg = tb_mska-charg.

   MODIFY tb_mska.

ENDLOOP.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question