在庫帳簿年齢分析報告書(中二)
7142 ワード
IF A1 = 'X'. "0-30
CLEAR: GS_TOTAL,GT_TOTAL[].
LASTDATE = SY-DATUM.
CONCATENATE LASTDATE+(6) '01' INTO FIRSTDAY.
* CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
* EXPORTING
* date = sy-datum
* days = 0
* months = 1
* SIGNUM = '-'
* years = 0
* IMPORTING
* CALC_DATE = CALC_DATE.
DELETE GT_TEMP1 WHERE BUDAT NOT BETWEEN FIRSTDAY AND LASTDATE.
LOOP AT GT_TEMP1 INTO GS_TEMP1."
GS_TEMP1-BUDAT = ''.
MODIFY GT_TEMP1 FROM GS_TEMP1.
ENDLOOP.
CLEAR GS_TEMP1.
LOOP AT GT_TEMP1 INTO GS_TEMP1."
MOVE-CORRESPONDING GS_TEMP1 TO GS_TOTAL.
COLLECT GS_TOTAL INTO GT_TOTAL.
ENDLOOP.
LOOP AT GT_TEMP1 INTO GS_TEMP1."
LOOP AT GT_TOTAL INTO GS_TOTAL WHERE BUKRS = GS_TEMP1-BUKRS AND WERKS = GS_TEMP1-WERKS AND LGORT = GS_TEMP1-LGORT AND MATNR = GS_TEMP1-MATNR AND MAKTX = GS_TEMP1-MAKTX.
GS_TOTAL-STPRS = GS_TEMP1-STPRS.
GS_TOTAL-PEINH = GS_TEMP1-PEINH.
GS_TOTAL-LABST = GS_TEMP1-LABST.
GS_TOTAL-INSME = GS_TEMP1-INSME.
GS_TOTAL-SPEME = GS_TEMP1-SPEME.
GS_TOTAL-PRLAB = GS_TEMP1-PRLAB.
GS_TOTAL-KALAB = GS_TEMP1-KALAB.
GS_TOTAL-SLABS = GS_TEMP1-SLABS.
GS_TOTAL-LBLAB = GS_TEMP1-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.
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-STNM1 = GS_TOTAL-MENGE.
GS_STOCK-MENGE1 = GS_TOTAL-MENGE.
ELSE.
GS_OUTPUT-STNM1 = CURRENT_STOCK.
GS_OUTPUT-STNM2 = -1.
GS_OUTPUT-STNM3 = -1.
GS_OUTPUT-STNM4 = -1.
GS_OUTPUT-STNM5 = -1.
GS_OUTPUT-STNM6 = -1.
GS_OUTPUT-TRMB2 = -1.
GS_OUTPUT-TRMB3 = -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.
GS_OUTPUT-TRMB1 = GS_TOTAL-STPRS / GS_TOTAL-PEINH * GS_OUTPUT-STNM1.
MODIFY GT_OUTPUT FROM GS_OUTPUT.
ENDLOOP.
ENDLOOP.
ENDIF.
IF A2 = 'X'. "30-60
CLEAR: GS_TOTAL,GT_TOTAL[].
CALL FUNCTION 'FIMA_DATE_CREATE'
EXPORTING
I_DATE = SY-DATUM
I_YEARS = 0
I_MONTHS = '-1'
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_TEMP2 WHERE BUDAT NOT BETWEEN FIRSTDAY AND LASTDATE.
LOOP AT GT_TEMP2 INTO GS_TEMP2."
GS_TEMP2-BUDAT = ''.
MODIFY GT_TEMP2 FROM GS_TEMP2.
ENDLOOP.
CLEAR GS_TEMP2.
LOOP AT GT_TEMP2 INTO GS_TEMP2.
MOVE-CORRESPONDING GS_TEMP2 TO GS_TOTAL.
COLLECT GS_TOTAL INTO GT_TOTAL.
ENDLOOP.
LOOP AT GT_TEMP2 INTO GS_TEMP2."
LOOP AT GT_TOTAL INTO GS_TOTAL WHERE BUKRS = GS_TEMP2-BUKRS AND WERKS = GS_TEMP2-WERKS AND LGORT = GS_TEMP2-LGORT AND MATNR = GS_TEMP2-MATNR AND MAKTX = GS_TEMP2-MAKTX.
GS_TOTAL-STPRS = GS_TEMP2-STPRS.
GS_TOTAL-PEINH = GS_TEMP2-PEINH.
GS_TOTAL-LABST = GS_TEMP2-LABST.
GS_TOTAL-INSME = GS_TEMP2-INSME.
GS_TOTAL-SPEME = GS_TEMP2-SPEME.
GS_TOTAL-PRLAB = GS_TEMP2-PRLAB.
GS_TOTAL-KALAB = GS_TEMP2-KALAB.
GS_TOTAL-SLABS = GS_TEMP2-SLABS.
GS_TOTAL-LBLAB = GS_TEMP2-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-STNM2 = GS_TOTAL-MENGE.
GS_STOCK-MENGE2 = GS_TOTAL-MENGE.
ELSE.
GS_OUTPUT-STNM2 = CURRENT_STOCK - GS_OUTPUT-STNM1.
GS_OUTPUT-STNM3 = -1.
GS_OUTPUT-STNM4 = -1.
GS_OUTPUT-STNM5 = -1.
GS_OUTPUT-STNM6 = -1.
GS_OUTPUT-TRMB3 = -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-STNM2 >= 0.
CURRENT_STOCK = GS_STOCK-STOCK.
IF GS_TOTAL-MENGE + GS_STOCK-MENGE1 <= CURRENT_STOCK.
GS_OUTPUT-STNM2 = GS_TOTAL-MENGE.
GS_STOCK-MENGE2 = GS_TOTAL-MENGE.
ELSE.
GS_OUTPUT-STNM2 = CURRENT_STOCK - GS_OUTPUT-STNM1.
GS_OUTPUT-STNM3 = -1.
GS_OUTPUT-STNM4 = -1.
GS_OUTPUT-STNM5 = -1.
GS_OUTPUT-STNM6 = -1.
GS_OUTPUT-TRMB3 = -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-TRMB2 = GS_TOTAL-STPRS / GS_TOTAL-PEINH * GS_OUTPUT-STNM2.
MODIFY GT_OUTPUT FROM GS_OUTPUT.
ENDLOOP.
ENDLOOP.
ENDIF.