03-12-2013 4:33 AM
Hi,
i have following code but in that code select statement of s031 is taking long time. what should i do. please help me.
BEGIN OF TY_OPG , " Opening File
SPMON TYPE SPMON, " Period to analyze - month
WERKS TYPE WERKS_D, " Plant
MATNR TYPE MATNR, " Material No
BASME TYPE MEINS,
MZUBB TYPE MZUBB, " Receipt Quantity
WZUBB TYPE WZUBB,
MAGBB TYPE MAGBB, " Issues Quantity
WAGBB TYPE WAGBB,
END OF TY_OPG,
TYPES:
BEGIN OF TY_MTL, " Material Master
MATNR TYPE MATNR, " Material Code
MTART TYPE MTART, " Material Type
MATKL TYPE MATKL, " Material Group
MEINS TYPE MEINS, " Base unit of Measure
WERKS TYPE WERKS_D, " Plant
MAKTX TYPE MAKTX, " Material description (Short Text)
LIFNR TYPE LIFNR, " vendor code
NAME1 TYPE NAME1_GP, " vendor name
CITY TYPE ORT01_GP, " City of Vendor
Y_RPT TYPE P DECIMALS 3, "Yearly receipt
Y_ISS TYPE P DECIMALS 3, "Yearly Consumption
M_OPG TYPE P DECIMALS 3, "Month opg
M_OPG1 TYPE P DECIMALS 3,
M_RPT TYPE P DECIMALS 3, "Month receipt
M_ISS TYPE P DECIMALS 3, "Month issue
M_CLG TYPE P DECIMALS 3, "Month Closing
D_BLK TYPE P DECIMALS 3, "Block Stock,
D_RPT TYPE P DECIMALS 3, "Today receipt
D_ISS TYPE P DECIMALS 3, "Day issues
TL_FL(2) TYPE C,
STATUS(4) TYPE C,
END OF TY_MTL,
SELECT
a~matnr
a~mtart
a~matkl
a~meins
b~werks
INTO TABLE t_m FROM mara AS a
INNER JOIN marc AS b
ON a~matnr = b~matnr
* WHERE a~mtart EQ s_mtart
WHERE a~matkl IN s_matkl
AND b~werks IN s_werks
AND b~matnr IN s_matnr .
endif.
IF t_m[] IS NOT INITIAL.
SELECT spmon
werks
matnr
basme
mzubb
WZUBB
magbb
wagbb
FROM s031 INTO TABLE t_o
FOR ALL ENTRIES IN t_m
WHERE matnr = t_m-matnr
AND werks IN s_werks
AND spmon le smonth1
AND basme = t_m-meins.
ENDIF.
03-12-2013 7:07 AM
Hi Hitesh,
You can do it like this:
SELECT MATNR WERKS
FROM MARC
INTO TABLE T_MARC
WHERE MATNR IN S_MATNR[]
AND WERKS IN S_WERKS[].
IF SY-SUBRC EQ 0.
SORT T_MARC BY MATNR WERKS.
SELECT MATNR MTART MATKL MEINS
FROM MARA
INTO T_MARA
FOR ALL ENTRIES IN T_MARC
WHERE MATNR = T_MARC-MATNR
AND MTART IN S_MTART[]
AND MATKL IN S_MATKL[].
IF SY-SUBRC EQ 0.
SORT T_MARA BY MATNR.
SELECT spmon
werks
matnr
basme
mzubb
WZUBB
magbb
wagbb
FROM s031 INTO TABLE t_S031
FOR ALL ENTRIES IN t_mARA
WHERE matnr = t_mARA-matnr
AND werks IN s_werks
AND spmon le smonth1
AND basme = t_mara-meins.
IF SY-SUBRC EQ 0.
SORT T_S031 BY WERKS MATNR.
ENDIF.
ENDIF.
ENDIF.
FOR ALL ENTRIES is always better than JOIN. Also , its better to use SORT and SY-SUBRC checks after SELECT statements. If there are no SY-SUBRC checks, even if select-options in the where conditions have no values and the above tables are blank, the below select would fetch ALL the entries. This hits performance.
Let me know if you need any more help or information!