在庫帳簿年齢分析報告書(中三)
8295 ワード
IF A3 = 'X'. "60-90
CLEAR: GS_TOTAL,GT_TOTAL[].
CALL FUNCTION 'FIMA_DATE_CREATE'
EXPORTING
I_DATE = SY-DATUM
I_YEARS = 0
I_MONTHS = '-2'
I_DAYS = 0
I_CALENDAR_DAYS = 0
I_SET_LAST_DAY_OF_MONTH = 'X'
IMPORTING
E_DATE = LASTDATE.
CONCATENATE LASTDATE+(6) '01' INTO FIRSTDAY.
DELETE GT_TEMP3 WHERE BUDAT NOT BETWEEN FIRSTDAY AND LASTDATE.
LOOP AT GT_TEMP3 INTO GS_TEMP3."
GS_TEMP3-BUDAT = ''.
MODIFY GT_TEMP3 FROM GS_TEMP3.
ENDLOOP.
CLEAR GS_TEMP3.
LOOP AT GT_TEMP3 INTO GS_TEMP3.
MOVE-CORRESPONDING GS_TEMP3 TO GS_TOTAL.
COLLECT GS_TOTAL INTO GT_TOTAL.
ENDLOOP.
LOOP AT GT_TEMP3 INTO GS_TEMP3."
LOOP AT GT_TOTAL INTO GS_TOTAL WHERE BUKRS = GS_TEMP3-BUKRS AND WERKS = GS_TEMP3-WERKS AND LGORT = GS_TEMP3-LGORT AND MATNR = GS_TEMP3-MATNR AND MAKTX = GS_TEMP3-MAKTX.
GS_TOTAL-STPRS = GS_TEMP3-STPRS.
GS_TOTAL-PEINH = GS_TEMP3-PEINH.
GS_TOTAL-LABST = GS_TEMP3-LABST.
GS_TOTAL-INSME = GS_TEMP3-INSME.
GS_TOTAL-SPEME = GS_TEMP3-SPEME.
GS_TOTAL-PRLAB = GS_TEMP3-PRLAB.
GS_TOTAL-KALAB = GS_TEMP3-KALAB.
GS_TOTAL-SLABS = GS_TEMP3-SLABS.
GS_TOTAL-LBLAB = GS_TEMP3-LBLAB.
MODIFY GT_TOTAL FROM GS_TOTAL.
EXIT.
ENDLOOP.
ENDLOOP.
CLEAR: GS_OUTPUT,GS_TOTAL.
LOOP AT GT_TOTAL INTO GS_TOTAL.
LOOP AT GT_OUTPUT INTO GS_OUTPUT
WHERE BUKRS = GS_TOTAL-BUKRS
AND WERKS = GS_TOTAL-WERKS
AND LGORT = GS_TOTAL-LGORT
AND MATNR = GS_TOTAL-MATNR
AND MAKTX = GS_TOTAL-MAKTX.
READ TABLE GT_STOCK INTO GS_STOCK WITH KEY BUKRS = GS_TOTAL-BUKRS WERKS = GS_TOTAL-WERKS LGORT = GS_TOTAL-LGORT MATNR = GS_TOTAL-MATNR MAKTX = GS_TOTAL-MAKTX.
IF SY-SUBRC <> 0.
GS_STOCK-BUKRS = GS_TOTAL-BUKRS.
GS_STOCK-WERKS = GS_TOTAL-WERKS.
GS_STOCK-LGORT = GS_TOTAL-LGORT.
GS_STOCK-MATNR = GS_TOTAL-MATNR.
GS_STOCK-MAKTX = GS_TOTAL-MAKTX.
GS_STOCK-STOCK = GS_TOTAL-LABST + GS_TOTAL-INSME + GS_TOTAL-SPEME + GS_TOTAL-PRLAB + GS_TOTAL-KALAB + GS_TOTAL-SLABS.
IF GS_TOTAL-LGORT IS INITIAL.
GS_STOCK-STOCK = GS_TOTAL-LBLAB.
ENDIF.
CURRENT_STOCK = GS_STOCK-STOCK.
IF GS_TOTAL-MENGE <= CURRENT_STOCK.
GS_OUTPUT-STNM3 = GS_TOTAL-MENGE.
GS_STOCK-MENGE3 = GS_TOTAL-MENGE.
ELSE.
GS_OUTPUT-STNM3 = CURRENT_STOCK - GS_OUTPUT-STNM1 - GS_OUTPUT-STNM2.
GS_OUTPUT-STNM4 = -1.
GS_OUTPUT-STNM5 = -1.
GS_OUTPUT-STNM6 = -1.
GS_OUTPUT-TRMB4 = -1.
GS_OUTPUT-TRMB5 = -1.
GS_OUTPUT-TRMB6 = -1.
ENDIF.
GS_OUTPUT-STOCK = GS_STOCK-STOCK.
APPEND GS_STOCK TO GT_STOCK.
ELSE.
IF GS_OUTPUT-STNM3 >= 0.
CURRENT_STOCK = GS_STOCK-STOCK.
IF GS_TOTAL-MENGE + GS_STOCK-MENGE1 + GS_STOCK-MENGE2 <= CURRENT_STOCK.
GS_OUTPUT-STNM3 = GS_TOTAL-MENGE.
GS_STOCK-MENGE3 = GS_TOTAL-MENGE.
ELSE.
GS_OUTPUT-STNM3 = CURRENT_STOCK - GS_OUTPUT-STNM1 - GS_OUTPUT-STNM2.
GS_OUTPUT-STNM4 = -1.
GS_OUTPUT-STNM5 = -1.
GS_OUTPUT-STNM6 = -1.
GS_OUTPUT-TRMB4 = -1.
GS_OUTPUT-TRMB5 = -1.
GS_OUTPUT-TRMB6 = -1.
ENDIF.
GS_OUTPUT-STOCK = GS_STOCK-STOCK.
COLLECT GS_STOCK INTO GT_STOCK.
ELSE.
CONTINUE.
ENDIF.
ENDIF.
GS_OUTPUT-TRMB3 = GS_TOTAL-STPRS / GS_TOTAL-PEINH * GS_OUTPUT-STNM3.
MODIFY GT_OUTPUT FROM GS_OUTPUT.
ENDLOOP.
ENDLOOP.
ENDIF.
IF A4 = 'X'. "90-180
CLEAR: GS_TOTAL,GT_TOTAL[].
CALL FUNCTION 'FIMA_DATE_CREATE'
EXPORTING
I_DATE = SY-DATUM
I_YEARS = 0
I_MONTHS = '-5'
I_DAYS = 0
I_CALENDAR_DAYS = 0
I_SET_LAST_DAY_OF_MONTH = 'X'
IMPORTING
E_DATE = LASTDATE.
CONCATENATE LASTDATE+(6) '01' INTO FIRSTDAY.
CALL FUNCTION 'FIMA_DATE_CREATE'
EXPORTING
I_DATE = SY-DATUM
I_YEARS = 0
I_MONTHS = '-3'
I_DAYS = 0
I_CALENDAR_DAYS = 0
I_SET_LAST_DAY_OF_MONTH = 'X'
IMPORTING
E_DATE = LASTDATE.
DELETE GT_TEMP4 WHERE BUDAT NOT BETWEEN FIRSTDAY AND LASTDATE.
LOOP AT GT_TEMP4 INTO GS_TEMP4."
GS_TEMP4-BUDAT = ''.
MODIFY GT_TEMP4 FROM GS_TEMP4.
ENDLOOP.
CLEAR GS_TEMP4.
LOOP AT GT_TEMP4 INTO GS_TEMP4.
MOVE-CORRESPONDING GS_TEMP4 TO GS_TOTAL.
COLLECT GS_TOTAL INTO GT_TOTAL.
ENDLOOP.
LOOP AT GT_TEMP4 INTO GS_TEMP4."
LOOP AT GT_TOTAL INTO GS_TOTAL WHERE BUKRS = GS_TEMP4-BUKRS AND WERKS = GS_TEMP4-WERKS AND LGORT = GS_TEMP4-LGORT AND MATNR = GS_TEMP4-MATNR AND MAKTX = GS_TEMP4-MAKTX.
GS_TOTAL-STPRS = GS_TEMP4-STPRS.
GS_TOTAL-PEINH = GS_TEMP4-PEINH.
GS_TOTAL-LABST = GS_TEMP4-LABST.
GS_TOTAL-INSME = GS_TEMP4-INSME.
GS_TOTAL-SPEME = GS_TEMP4-SPEME.
GS_TOTAL-PRLAB = GS_TEMP4-PRLAB.
GS_TOTAL-KALAB = GS_TEMP4-KALAB.
GS_TOTAL-SLABS = GS_TEMP4-SLABS.
GS_TOTAL-LBLAB = GS_TEMP4-LBLAB.
MODIFY GT_TOTAL FROM GS_TOTAL.
EXIT.
ENDLOOP.
ENDLOOP.
CLEAR: GS_OUTPUT,GS_TOTAL.
LOOP AT GT_TOTAL INTO GS_TOTAL.
LOOP AT GT_OUTPUT INTO GS_OUTPUT
WHERE BUKRS = GS_TOTAL-BUKRS
AND WERKS = GS_TOTAL-WERKS
AND LGORT = GS_TOTAL-LGORT
AND MATNR = GS_TOTAL-MATNR
AND MAKTX = GS_TOTAL-MAKTX.
READ TABLE GT_STOCK INTO GS_STOCK WITH KEY BUKRS = GS_TOTAL-BUKRS WERKS = GS_TOTAL-WERKS LGORT = GS_TOTAL-LGORT MATNR = GS_TOTAL-MATNR MAKTX = GS_TOTAL-MAKTX.
IF SY-SUBRC <> 0.
GS_STOCK-BUKRS = GS_TOTAL-BUKRS.
GS_STOCK-WERKS = GS_TOTAL-WERKS.
GS_STOCK-LGORT = GS_TOTAL-LGORT.
GS_STOCK-MATNR = GS_TOTAL-MATNR.
GS_STOCK-MAKTX = GS_TOTAL-MAKTX.
GS_STOCK-STOCK = GS_TOTAL-LABST + GS_TOTAL-INSME + GS_TOTAL-SPEME + GS_TOTAL-PRLAB + GS_TOTAL-KALAB + GS_TOTAL-SLABS.
IF GS_TOTAL-LGORT IS INITIAL.
GS_STOCK-STOCK = GS_TOTAL-LBLAB.
ENDIF.
CURRENT_STOCK = GS_STOCK-STOCK.
IF GS_TOTAL-MENGE <= CURRENT_STOCK.
GS_OUTPUT-STNM4 = GS_TOTAL-MENGE.
GS_STOCK-MENGE4 = GS_TOTAL-MENGE.
ELSE.
GS_OUTPUT-STNM4 = CURRENT_STOCK - GS_OUTPUT-STNM1 - GS_OUTPUT-STNM2 - GS_OUTPUT-STNM3.
GS_OUTPUT-STNM5 = -1.
GS_OUTPUT-STNM6 = -1.
GS_OUTPUT-TRMB5 = -1.
GS_OUTPUT-TRMB6 = -1.
ENDIF.
GS_OUTPUT-STOCK = GS_STOCK-STOCK.
APPEND GS_STOCK TO GT_STOCK.
ELSE.
IF GS_OUTPUT-STNM4 >= 0.
CURRENT_STOCK = GS_STOCK-STOCK.
IF GS_TOTAL-MENGE + GS_STOCK-MENGE1 + GS_STOCK-MENGE2 + GS_STOCK-MENGE3 <= CURRENT_STOCK.
GS_OUTPUT-STNM4 = GS_TOTAL-MENGE.
GS_STOCK-MENGE4 = GS_TOTAL-MENGE.
ELSE.
GS_OUTPUT-STNM4 = CURRENT_STOCK - GS_OUTPUT-STNM1 - GS_OUTPUT-STNM2 - GS_OUTPUT-STNM3.
GS_OUTPUT-STNM5 = -1.
GS_OUTPUT-STNM6 = -1.
GS_OUTPUT-TRMB5 = -1.
GS_OUTPUT-TRMB6 = -1.
ENDIF.
GS_OUTPUT-STOCK = GS_STOCK-STOCK.
COLLECT GS_STOCK INTO GT_STOCK.
ELSE.
CONTINUE.
ENDIF.
ENDIF.
GS_OUTPUT-TRMB4 = GS_TOTAL-STPRS / GS_TOTAL-PEINH * GS_OUTPUT-STNM4.
MODIFY GT_OUTPUT FROM GS_OUTPUT.
ENDLOOP.
ENDLOOP.
ENDIF.