在庫帳簿年齢分析報告書(中四)
9060 ワード
IF A5 = 'X'. "180-360
CLEAR: GS_TOTAL,GT_TOTAL[].
CALL FUNCTION 'FIMA_DATE_CREATE'
EXPORTING
I_DATE = SY-DATUM
I_YEARS = 0
I_MONTHS = '-11'
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 = '-6'
I_DAYS = 0
I_CALENDAR_DAYS = 0
I_SET_LAST_DAY_OF_MONTH = 'X'
IMPORTING
E_DATE = LASTDATE.
DELETE GT_TEMP5 WHERE BUDAT NOT BETWEEN FIRSTDAY AND LASTDATE.
LOOP AT GT_TEMP5 INTO GS_TEMP5."
GS_TEMP5-BUDAT = ''.
MODIFY GT_TEMP5 FROM GS_TEMP5.
ENDLOOP.
CLEAR GS_TEMP5.
LOOP AT GT_TEMP5 INTO GS_TEMP5.
MOVE-CORRESPONDING GS_TEMP5 TO GS_TOTAL.
COLLECT GS_TOTAL INTO GT_TOTAL.
ENDLOOP.
LOOP AT GT_TEMP5 INTO GS_TEMP5."
LOOP AT GT_TOTAL INTO GS_TOTAL WHERE BUKRS = GS_TEMP5-BUKRS AND WERKS = GS_TEMP5-WERKS AND LGORT = GS_TEMP5-LGORT AND MATNR = GS_TEMP5-MATNR AND MAKTX = GS_TEMP5-MAKTX.
GS_TOTAL-STPRS = GS_TEMP5-STPRS.
GS_TOTAL-PEINH = GS_TEMP5-PEINH.
GS_TOTAL-LABST = GS_TEMP5-LABST.
GS_TOTAL-INSME = GS_TEMP5-INSME.
GS_TOTAL-SPEME = GS_TEMP5-SPEME.
GS_TOTAL-PRLAB = GS_TEMP5-PRLAB.
GS_TOTAL-KALAB = GS_TEMP5-KALAB.
GS_TOTAL-SLABS = GS_TEMP5-SLABS.
GS_TOTAL-LBLAB = GS_TEMP5-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-STNM5 = GS_TOTAL-MENGE.
GS_STOCK-MENGE5 = GS_TOTAL-MENGE.
ELSE.
GS_OUTPUT-STNM5 = CURRENT_STOCK - GS_OUTPUT-STNM1 - GS_OUTPUT-STNM2 - GS_OUTPUT-STNM3 - GS_OUTPUT-STNM4.
GS_OUTPUT-STNM6 = -1.
GS_OUTPUT-TRMB6 = -1.
ENDIF.
GS_OUTPUT-STOCK = GS_STOCK-STOCK.
APPEND GS_STOCK TO GT_STOCK.
ELSE.
IF GS_OUTPUT-STNM5 >= 0.
CURRENT_STOCK = GS_STOCK-STOCK.
IF GS_TOTAL-MENGE + GS_STOCK-MENGE1 + GS_STOCK-MENGE2 + GS_STOCK-MENGE3 + GS_STOCK-MENGE4 <= CURRENT_STOCK.
GS_OUTPUT-STNM5 = GS_TOTAL-MENGE.
GS_STOCK-MENGE5 = GS_TOTAL-MENGE.
ELSE.
GS_OUTPUT-STNM5 = CURRENT_STOCK - GS_OUTPUT-STNM1 - GS_OUTPUT-STNM2 - GS_OUTPUT-STNM3 - GS_OUTPUT-STNM4.
GS_OUTPUT-STNM6 = -1.
GS_OUTPUT-TRMB6 = -1.
ENDIF.
GS_OUTPUT-STOCK = GS_STOCK-STOCK.
COLLECT GS_STOCK INTO GT_STOCK.
ELSE.
CONTINUE.
ENDIF.
ENDIF.
GS_OUTPUT-TRMB5 = GS_TOTAL-STPRS / GS_TOTAL-PEINH * GS_OUTPUT-STNM5.
MODIFY GT_OUTPUT FROM GS_OUTPUT.
ENDLOOP.
ENDLOOP.
ENDIF.
IF A6 = 'X'. "360
CLEAR: GS_TOTAL,GT_TOTAL[].
CALL FUNCTION 'FIMA_DATE_CREATE'
EXPORTING
I_DATE = SY-DATUM
I_YEARS = 0
I_MONTHS = '-12'
I_DAYS = 0
I_CALENDAR_DAYS = 0
I_SET_LAST_DAY_OF_MONTH = 'X'
IMPORTING
E_DATE = LASTDATE.
DELETE GT_TEMP6 WHERE BUDAT NOT BETWEEN '00000000' AND LASTDATE.
LOOP AT GT_TEMP6 INTO GS_TEMP6."
GS_TEMP6-BUDAT = ''.
MODIFY GT_TEMP6 FROM GS_TEMP6.
ENDLOOP.
CLEAR GS_TEMP6.
LOOP AT GT_TEMP6 INTO GS_TEMP6.
MOVE-CORRESPONDING GS_TEMP6 TO GS_TOTAL.
COLLECT GS_TOTAL INTO GT_TOTAL.
ENDLOOP.
LOOP AT GT_TEMP6 INTO GS_TEMP6."
LOOP AT GT_TOTAL INTO GS_TOTAL WHERE BUKRS = GS_TEMP6-BUKRS AND WERKS = GS_TEMP6-WERKS AND LGORT = GS_TEMP6-LGORT AND MATNR = GS_TEMP6-MATNR AND MAKTX = GS_TEMP6-MAKTX.
GS_TOTAL-STPRS = GS_TEMP6-STPRS.
GS_TOTAL-PEINH = GS_TEMP6-PEINH.
GS_TOTAL-LABST = GS_TEMP6-LABST.
GS_TOTAL-INSME = GS_TEMP6-INSME.
GS_TOTAL-SPEME = GS_TEMP6-SPEME.
GS_TOTAL-PRLAB = GS_TEMP6-PRLAB.
GS_TOTAL-KALAB = GS_TEMP6-KALAB.
GS_TOTAL-SLABS = GS_TEMP6-SLABS.
GS_TOTAL-LBLAB = GS_TEMP6-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-STNM6 = GS_TOTAL-MENGE.
GS_STOCK-MENGE6 = GS_TOTAL-MENGE.
ELSE.
GS_OUTPUT-STNM6 = CURRENT_STOCK - GS_OUTPUT-STNM1 - GS_OUTPUT-STNM2 - GS_OUTPUT-STNM3 - GS_OUTPUT-STNM4 - GS_OUTPUT-STNM5.
ENDIF.
GS_OUTPUT-STOCK = GS_STOCK-STOCK.
APPEND GS_STOCK TO GT_STOCK.
ELSE.
IF GS_OUTPUT-STNM6 >= 0.
CURRENT_STOCK = GS_STOCK-STOCK.
IF GS_TOTAL-MENGE + GS_STOCK-MENGE1 + GS_STOCK-MENGE2 + GS_STOCK-MENGE3 + GS_STOCK-MENGE4 + GS_STOCK-MENGE5 <= CURRENT_STOCK.
GS_OUTPUT-STNM6 = GS_TOTAL-MENGE.
GS_STOCK-MENGE6 = GS_TOTAL-MENGE.
ELSE.
GS_OUTPUT-STNM6 = CURRENT_STOCK - GS_OUTPUT-STNM1 - GS_OUTPUT-STNM2 - GS_OUTPUT-STNM3 - GS_OUTPUT-STNM4 - GS_OUTPUT-STNM5.
ENDIF.
GS_OUTPUT-STOCK = GS_STOCK-STOCK.
COLLECT GS_STOCK INTO GT_STOCK.
ELSE.
CONTINUE.
ENDIF.
ENDIF.
GS_OUTPUT-TRMB6 = GS_TOTAL-STPRS / GS_TOTAL-PEINH * GS_OUTPUT-STNM6.
MODIFY GT_OUTPUT FROM GS_OUTPUT.
ENDLOOP.
ENDLOOP.
ENDIF.
A1 = T1.
A2 = T2.
A3 = T3.
A4 = T4.
A5 = T5.
A6 = T6.
LOOP AT GT_OUTPUT INTO GS_OUTPUT.
IF GS_OUTPUT-STNM1 < 0.
CLEAR GS_OUTPUT-STNM1.
ENDIF.
IF GS_OUTPUT-TRMB1 < 0.
CLEAR GS_OUTPUT-TRMB1.
ENDIF.
IF GS_OUTPUT-STNM2 < 0.
CLEAR GS_OUTPUT-STNM2.
ENDIF.
IF GS_OUTPUT-TRMB2 < 0.
CLEAR GS_OUTPUT-TRMB2.
ENDIF.
IF GS_OUTPUT-STNM3 < 0.
CLEAR GS_OUTPUT-STNM3.
ENDIF.
IF GS_OUTPUT-TRMB3 < 0.
CLEAR GS_OUTPUT-TRMB3.
ENDIF.
IF GS_OUTPUT-STNM4 < 0.
CLEAR GS_OUTPUT-STNM4.
ENDIF.
IF GS_OUTPUT-TRMB4 < 0.
CLEAR GS_OUTPUT-TRMB4.
ENDIF.
IF GS_OUTPUT-STNM5 < 0.
CLEAR GS_OUTPUT-STNM5.
ENDIF.
IF GS_OUTPUT-TRMB5 < 0.
CLEAR GS_OUTPUT-TRMB5.
ENDIF.
IF GS_OUTPUT-STNM6 < 0.
CLEAR GS_OUTPUT-STNM6.
ENDIF.
IF GS_OUTPUT-TRMB6 < 0.
CLEAR GS_OUTPUT-TRMB6.
ENDIF.
MODIFY GT_OUTPUT FROM GS_OUTPUT.
ENDLOOP.
DELETE GT_OUTPUT WHERE STNM1 IS INITIAL
AND STNM2 IS INITIAL
AND STNM3 IS INITIAL
AND STNM4 IS INITIAL
AND STNM5 IS INITIAL
AND STNM6 IS INITIAL.
ENDFORM."frm_retrive_data