Saturday, October 11, 2008

Report to display 12 weeks forecast, Yesterday Stocks, Onhand Stocks, MTD Pull, MTD GR

*
* Report list last 12 Week Forecast, Yesterday, MTD PULL, Onhand Stock,
* MTD PO, MTD GR or NEXT MONTH PO
*
REPORT ZAI_WEEKLY LINE-SIZE 255 NO STANDARD PAGE HEADING
LINE-COUNT 065(001).

TABLES: MDKP, "Header Data for MRP Document
MDTB, "MRP table
MKPF, "Header: Material Document
MSEG, "Document Segment: Material
MARD, "Storage Location Data for Material
EKKO, "Purchasing Document Header
EKPO, "Purchasing Document Item
EKET, "Scheduling Agreement Schedule Lines
MARC, "Plant Data for Material
EINA, "Purchasing Info Record: General Data
MARA, "General Material Data
PBIM, "Independent requirements for material
PBED. "Independent requirements data

DATA: BEGIN OF INT_MRP OCCURS 100,
MATNR(18) TYPE C,
MENGE TYPE P DECIMALS 0,
MTDPULL TYPE P DECIMALS 0,
ONHAND TYPE P DECIMALS 0,
MTDGR TYPE P DECIMALS 0,
MTDPOORD TYPE P DECIMALS 0,
MTDPODEL TYPE P DECIMALS 0,
NEXPOORD TYPE P DECIMALS 0,
NEXPODEL TYPE P DECIMALS 0,
PLNMG01 TYPE P DECIMALS 0,
PLNMG02 TYPE P DECIMALS 0,
PLNMG03 TYPE P DECIMALS 0,
PLNMG04 TYPE P DECIMALS 0,
PLNMG05 TYPE P DECIMALS 0,
PLNMG06 TYPE P DECIMALS 0,
PLNMG07 TYPE P DECIMALS 0,
PLNMG08 TYPE P DECIMALS 0,
PLNMG09 TYPE P DECIMALS 0,
PLNMG10 TYPE P DECIMALS 0,
PLNMG11 TYPE P DECIMALS 0,
PLNMG12 TYPE P DECIMALS 0,
END OF INT_MRP.

DATA: BEGIN OF INT_DATE,
DATE01(12) TYPE C,
DATE02(12) TYPE C,
DATE03(12) TYPE C,
DATE04(12) TYPE C,
DATE05(12) TYPE C,
DATE06(12) TYPE C,
DATE07(12) TYPE C,
DATE08(12) TYPE C,
DATE09(12) TYPE C,
DATE10(12) TYPE C,
DATE11(12) TYPE C,
DATE12(12) TYPE C,
END OF INT_DATE.

DATA: BEGIN OF MDTBX OCCURS 0.
INCLUDE STRUCTURE MDTB.
DATA: END OF MDTBX.

DATA: NO01(2) TYPE N,
FN01(20),
FN02(20),
X_MONTH01(20),
X_MONTH02(20),
X_MONTH03(20),
X_MONTH04(20),
X_MONTH05(20),
X_MONTH06(20),
X_MONTH07(20),
X_MONTH08(20),
X_MONTH09(20),
X_MONTH10(20),
X_MONTH11(20),
X_MONTH12(20).
FIELD-SYMBOLS: , .

DATA: FDATE LIKE SY-DATUM,
LDATE LIKE SY-DATUM,
XDATE LIKE SY-DATUM.

DATA: BEGIN OF INT_PBED,
BDZEI TYPE PBED-BDZEI,
PLNMG TYPE PBED-PLNMG,
PDATU TYPE PBED-PDATU,
END OF INT_PBED,
ITAB_PBED LIKE TABLE OF INT_PBED.

DATA: BEGIN OF INT_MKPF,
VGART TYPE MKPF-VGART,
BUDAT TYPE MKPF-BUDAT,
MBLNR TYPE MKPF-MBLNR,
MJAHR TYPE MKPF-MJAHR,
END OF INT_MKPF,
ITAB_MKPF LIKE TABLE OF INT_MKPF.

DATA: BEGIN OF INT_MSEG,
MBLNR TYPE MSEG-MBLNR,
MJAHR TYPE MSEG-MJAHR,
MATNR TYPE MSEG-MATNR,
MENGE TYPE MSEG-MENGE,
DMBTR TYPE MSEG-DMBTR,
SHKZG TYPE MSEG-SHKZG,
END OF INT_MSEG,
ITAB_MSEG LIKE TABLE OF INT_MSEG.

DATA: BEGIN OF INT_MARD,
MATNR TYPE MARD-MATNR,
DISKZ TYPE MARD-DISKZ,
LABST TYPE MARD-LABST,
END OF INT_MARD,
ITAB_MARD LIKE TABLE OF INT_MARD.

DATA: BEGIN OF INT_EKKO,
BUKRS TYPE EKKO-BUKRS,
EBELN TYPE EKKO-EBELN,
END OF INT_EKKO,
ITAB_EKKO LIKE TABLE OF INT_EKKO.

DATA: BEGIN OF INT_EKPO,
EBELN TYPE EKPO-EBELN,
EBELP TYPE EKPO-EBELP,
MATNR TYPE EKPO-MATNR,
END OF INT_EKPO,
ITAB_EKPO LIKE TABLE OF INT_EKPO.

SELECT-OPTIONS: X_MATNR FOR MDKP-MATNR, "Material number
X_WERKS FOR MDKP-PLWRK, "Plant
X_EKGRP FOR MARC-EKGRP, "Purchasing group
X_BESKZ FOR MARC-BESKZ, "Procurement Type
X_SPART FOR MARA-SPART, "Procurement Type
X_LIFNR FOR EINA-LIFNR, "Vendor's account number
X_BUDAT FOR MDTB-DAT00, "Posting Date
X_BUDAT2 FOR MDTB-DAT00.

START-OF-SELECTION.
PERFORM DATA_ONHAND.
PERFORM DATA_MRP.
PERFORM YESTERDAY_PULL.
PERFORM DATA_MTD_PULL.
PERFORM DATA_MTD_GR.
PERFORM DATA_MTD_PO.
* PERFORM DATA_NEX_PO.
PERFORM LOOP_INT_MRP.
END-OF-SELECTION.

FORM DATA_ONHAND.
CLEAR ITAB_MARD.
INT_MARD-DISKZ = ' '.
APPEND INT_MARD TO ITAB_MARD.

SELECT WERKS MATNR LGORT LABST
INTO CORRESPONDING FIELDS OF INT_MARD
FROM MARD FOR ALL ENTRIES IN ITAB_MARD
WHERE DISKZ = ITAB_MARD-DISKZ "Storage location MRP indicator
AND WERKS IN X_WERKS
AND MATNR IN X_MATNR.

* Check Purchase Group, Procurement Type
SELECT SINGLE * FROM MARC WHERE LVORM = ' '
AND WERKS IN X_WERKS
AND MATNR = INT_MARD-MATNR
AND EKGRP IN X_EKGRP
AND BESKZ IN X_BESKZ.
IF SY-SUBRC <> 0. CONTINUE. ENDIF.

* Check Purchasing Info
SELECT SINGLE * FROM EINA WHERE LOEKZ = ' '
AND MATNR = INT_MARD-MATNR
AND LIFNR IN X_LIFNR.
IF SY-SUBRC <> 0. CONTINUE. ENDIF.

* Check Division
SELECT SINGLE * FROM MARA WHERE LVORM = ''
AND MATNR = INT_MARD-MATNR
AND SPART IN X_SPART.
IF SY-SUBRC <> 0. CONTINUE. ENDIF.

* WRITE:/ INT_MARD-MATNR, INT_MARD-LABST.

INT_MRP-ONHAND = INT_MARD-LABST.
INT_MRP-MATNR = INT_MARD-MATNR.
COLLECT INT_MRP.
CLEAR INT_MRP.
ENDSELECT.
ENDFORM.

FORM DATA_MRP.
* MDTB-DELKZ :-
* PP - IndReq
* SB - DepReq
* AR - OrdRes
LOOP AT INT_MRP.
SELECT SINGLE * FROM PBIM WHERE WERKS IN X_WERKS
AND MATNR = INT_MRP-MATNR.
INT_PBED-BDZEI = PBIM-BDZEI.
APPEND INT_PBED TO ITAB_PBED.
CLEAR NO01.
SELECT BDZEI PLNMG PDATU
INTO CORRESPONDING FIELDS OF INT_PBED
FROM PBED FOR ALL ENTRIES IN ITAB_PBED
WHERE BDZEI = ITAB_PBED-BDZEI.
ADD 1 TO NO01.
CONCATENATE 'INT_MRP-PLNMG' NO01 INTO FN01.
CONCATENATE 'INT_DATE-DATE' NO01 INTO FN02.
ASSIGN (FN01) TO .
ASSIGN (FN02) TO .

ADD INT_PBED-PLNMG TO .
= INT_PBED-PDATU.

MODIFY INT_MRP.

IF NO01 => 12.
EXIT.
ENDIF.
ENDSELECT.
ENDLOOP.
ENDFORM.

FORM YESTERDAY_PULL.
INT_MKPF-BUDAT = SY-DATUM - 1.
APPEND INT_MKPF TO ITAB_MKPF.

SELECT BUDAT MBLNR MJAHR
INTO CORRESPONDING FIELDS OF INT_MKPF
FROM MKPF FOR ALL ENTRIES IN ITAB_MKPF
WHERE BUDAT = ITAB_MKPF-BUDAT.

* WRITE: / INT_MKPF-BUDAT, INT_MKPF-MBLNR, INT_MKPF-MJAHR.

CLEAR ITAB_MSEG.
INT_MSEG-MBLNR = INT_MKPF-MBLNR.
INT_MSEG-MJAHR = INT_MKPF-MJAHR.
APPEND INT_MSEG TO ITAB_MSEG.
SELECT MBLNR MJAHR MATNR MENGE DMBTR SHKZG
INTO CORRESPONDING FIELDS OF INT_MSEG
FROM MSEG FOR ALL ENTRIES IN ITAB_MSEG
WHERE MBLNR = ITAB_MSEG-MBLNR
AND MJAHR = ITAB_MSEG-MJAHR
AND MATNR IN X_MATNR
AND LGORT IN ('G1', 'G2', 'G3', 'G4')
AND BWART IN ('311', '312').

IF INT_MSEG-SHKZG = 'S'.
MULTIPLY INT_MSEG-MENGE BY -1.
MULTIPLY INT_MSEG-DMBTR BY -1.
ENDIF.

* WRITE: / INT_MSEG-MBLNR, INT_MSEG-MATNR, INT_MSEG-MENGE.
INT_MRP-MENGE = INT_MSEG-MENGE.
INT_MRP-MATNR = INT_MSEG-MATNR.
COLLECT INT_MRP.
CLEAR INT_MRP.
ENDSELECT.
ENDSELECT.

ENDFORM.

FORM DATA_MTD_PULL.
INT_MKPF-VGART = ' '.
APPEND INT_MKPF TO ITAB_MKPF.
SELECT BUDAT MBLNR MJAHR
INTO CORRESPONDING FIELDS OF INT_MKPF
FROM MKPF FOR ALL ENTRIES IN ITAB_MKPF
WHERE VGART <> ITAB_MKPF-VGART
AND BUDAT IN X_BUDAT.

* MTD Pull
SELECT * FROM MSEG WHERE WERKS IN X_WERKS
AND MBLNR = INT_MKPF-MBLNR
AND MJAHR = INT_MKPF-MJAHR
AND MATNR IN X_MATNR
AND LGORT IN ('G1', 'G2',
'G3', 'G4')
AND BWART IN ('311', '312').
IF MSEG-SHKZG = 'S'.
MULTIPLY MSEG-MENGE BY -1.
MULTIPLY MSEG-DMBTR BY -1.
ENDIF.

INT_MRP-MTDPULL = MSEG-MENGE.
INT_MRP-MATNR = MSEG-MATNR.

COLLECT INT_MRP.
CLEAR INT_MRP.

ENDSELECT.

ENDSELECT.
ENDFORM.

FORM DATA_MTD_GR.
INT_MKPF-VGART = ' '.
APPEND INT_MKPF TO ITAB_MKPF.
SELECT BUDAT MBLNR MJAHR
INTO CORRESPONDING FIELDS OF INT_MKPF
FROM MKPF FOR ALL ENTRIES IN ITAB_MKPF
WHERE VGART <> ITAB_MKPF-VGART
AND BUDAT IN X_BUDAT.

* MTD Goods Receipts
SELECT * FROM MSEG WHERE WERKS IN X_WERKS
AND MBLNR = INT_MKPF-MBLNR
AND MJAHR = INT_MKPF-MJAHR
AND MATNR IN X_MATNR
AND LGORT IN ('G1')
AND BWART IN ('101', '102').
IF MSEG-SHKZG = 'H'.
MULTIPLY MSEG-MENGE BY -1.
MULTIPLY MSEG-DMBTR BY -1.
ENDIF.

INT_MRP-MTDGR = MSEG-MENGE.
INT_MRP-MATNR = MSEG-MATNR.

COLLECT INT_MRP.
CLEAR INT_MRP.

ENDSELECT.

ENDSELECT.
ENDFORM.

FORM DATA_MTD_PO.
CLEAR ITAB_EKKO.
INT_EKKO-BUKRS = '0010'. "Company Code
APPEND INT_EKKO TO ITAB_EKKO.
SELECT BUKRS EBELN
INTO CORRESPONDING FIELDS OF INT_EKKO
FROM EKKO FOR ALL ENTRIES IN ITAB_EKKO
WHERE BUKRS = ITAB_EKKO-BUKRS
AND LOEKZ = ' '.

CLEAR ITAB_EKPO.
INT_EKPO-EBELN = INT_EKKO-EBELN.
APPEND INT_EKPO TO ITAB_EKPO.
SELECT EBELN EBELP MATNR
INTO CORRESPONDING FIELDS OF INT_EKPO
FROM EKPO FOR ALL ENTRIES IN ITAB_EKPO
WHERE EBELN = ITAB_EKPO-EBELN
AND MATNR IN X_MATNR
AND LOEKZ = ' '
* "Delivery completed" indicator
AND ELIKZ = ' '.

CLEAR EKET.
SELECT SINGLE * FROM EKET WHERE EBELN = INT_EKPO-EBELN
AND EBELP = INT_EKPO-EBELP
AND EINDT IN X_BUDAT.
IF SY-SUBRC = 0.
INT_MRP-MATNR = INT_EKPO-MATNR.
INT_MRP-MTDPOORD = EKET-MENGE.
INT_MRP-MTDPODEL = EKET-WEMNG.
COLLECT INT_MRP.
CLEAR INT_MRP.
ENDIF.
ENDSELECT.
ENDSELECT.
ENDFORM.

FORM DATA_NEX_PO.
CLEAR ITAB_EKKO.
INT_EKKO-BUKRS = '0010'. "Company Code
APPEND INT_EKKO TO ITAB_EKKO.
SELECT BUKRS EBELN
INTO CORRESPONDING FIELDS OF INT_EKKO
FROM EKKO FOR ALL ENTRIES IN ITAB_EKKO
WHERE BUKRS = ITAB_EKKO-BUKRS
AND LOEKZ = ' '.

CLEAR ITAB_EKPO.
INT_EKPO-EBELN = INT_EKKO-EBELN.
APPEND INT_EKPO TO ITAB_EKPO.
SELECT EBELN EBELP MATNR
INTO CORRESPONDING FIELDS OF INT_EKPO
FROM EKPO FOR ALL ENTRIES IN ITAB_EKPO
WHERE EBELN = ITAB_EKPO-EBELN
AND MATNR IN X_MATNR
AND LOEKZ = ' '
* "Delivery completed" indicator
AND ELIKZ = ' '.

CLEAR EKET.
SELECT SINGLE * FROM EKET WHERE EBELN = INT_EKPO-EBELN
AND EBELP = INT_EKPO-EBELP
AND EINDT IN X_BUDAT2.
IF SY-SUBRC = 0.
INT_MRP-MATNR = INT_EKPO-MATNR.
INT_MRP-NEXPOORD = EKET-MENGE.
INT_MRP-NEXPODEL = EKET-WEMNG.
COLLECT INT_MRP.
CLEAR INT_MRP.
ENDIF.
ENDSELECT.
ENDSELECT.
ENDFORM.

FORM LOOP_INT_MRP.
SORT INT_MRP.
LOOP AT INT_MRP.
* Check Purchase Group, Procurement Type
SELECT SINGLE * FROM MARC WHERE LVORM = ' '
AND WERKS IN X_WERKS
AND MATNR = INT_MRP-MATNR
AND EKGRP IN X_EKGRP
AND BESKZ IN X_BESKZ.
IF SY-SUBRC <> 0. CONTINUE. ENDIF.

* Check Purchasing Info
SELECT SINGLE * FROM EINA WHERE LOEKZ = ' '
AND MATNR = INT_MRP-MATNR
AND LIFNR IN X_LIFNR.
IF SY-SUBRC <> 0. CONTINUE. ENDIF.

* Check Division
SELECT SINGLE * FROM MARA WHERE LVORM = ''
AND MATNR = INT_MRP-MATNR
AND SPART IN X_SPART.
IF SY-SUBRC <> 0. CONTINUE. ENDIF.

WRITE: / INT_MRP-MATNR UNDER ' Material',
INT_MRP-PLNMG01 UNDER X_MONTH01,
INT_MRP-PLNMG02 UNDER X_MONTH02,
INT_MRP-PLNMG03 UNDER X_MONTH03,
INT_MRP-PLNMG04 UNDER X_MONTH04,
INT_MRP-PLNMG05 UNDER X_MONTH05,
INT_MRP-PLNMG06 UNDER X_MONTH06,
INT_MRP-PLNMG07 UNDER X_MONTH07,
INT_MRP-PLNMG08 UNDER X_MONTH08,
INT_MRP-PLNMG09 UNDER X_MONTH09,
INT_MRP-PLNMG10 UNDER X_MONTH10,
INT_MRP-PLNMG11 UNDER X_MONTH11,
INT_MRP-PLNMG12 UNDER X_MONTH12,
INT_MRP-MENGE UNDER 'Yesterday Pull',
INT_MRP-MTDPULL UNDER ' MTD Pull',
INT_MRP-ONHAND UNDER ' On Hand'.
INT_MRP-MTDPOORD = INT_MRP-MTDPOORD - INT_MRP-MTDPODEL.
* INT_MRP-NEXPOORD = INT_MRP-NEXPOORD - INT_MRP-NEXPODEL.
WRITE: / INT_MRP-MTDPOORD UNDER ' MTD PO',
INT_MRP-MTDGR UNDER ' MTD GR'.
ENDLOOP.
ENDFORM.

TOP-OF-PAGE.
FORMAT COLOR COL_TOTAL.
WRITE: / SY-DATUM, SY-UZEIT, SY-REPID,
110 'Material Consumption',
200 SY-UNAME, SY-PAGNO.

SKIP.
CLEAR NO01.
DO 12 TIMES.
ADD 1 TO NO01.
CONCATENATE 'INT_DATE-DATE' NO01 INTO FN01.
CONCATENATE 'X_MONTH' NO01 INTO FN02.
ASSIGN (FN01) TO .
ASSIGN (FN02) TO .
* Date conversion to 31 January 2003
* CALL FUNCTION 'CONVERSION_EXIT_LDATE_OUTPUT'
* EXPORTING
* INPUT =
* IMPORTING
* OUTPUT = .
* = .
CONCATENATE +6(2) +4(2) (4) INTO .
ENDDO.

WRITE: /1 ' Material',
20 X_MONTH01(8),
35 X_MONTH02(8),
50 X_MONTH03(8),
65 X_MONTH04(8),
80 X_MONTH05(8),
95 X_MONTH06(8),
110 X_MONTH07(8),
125 X_MONTH08(8),
140 X_MONTH09(8),
155 X_MONTH10(8),
170 X_MONTH11(8),
185 X_MONTH12(8),
200 'Yesterday Pull',
215 ' MTD Pull',
230 ' On Hand'.
WRITE: /215 ' MTD PO',
230 ' MTD GR'.

INITIALIZATION.
CASE SY-DATUM+4(2).
WHEN '01'.
ADD 31 TO SY-DATUM.
WHEN '02'.
ADD 28 TO SY-DATUM.
WHEN '03'.
ADD 31 TO SY-DATUM.
WHEN '04'.
ADD 30 TO SY-DATUM.
WHEN '05'.
ADD 31 TO SY-DATUM.
WHEN '06'.
ADD 30 TO SY-DATUM.
WHEN '07'.
ADD 31 TO SY-DATUM.
WHEN '08'.
ADD 31 TO SY-DATUM.
WHEN '09'.
ADD 30 TO SY-DATUM.
WHEN '10'.
ADD 31 TO SY-DATUM.
WHEN '11'.
ADD 30 TO SY-DATUM.
WHEN '12'.
ADD 31 TO SY-DATUM.
WHEN OTHERS.
ADD 28 TO SY-DATUM.
ENDCASE.
LDATE = FDATE = SY-DATUM.
LDATE+6(2) = '01'.
SUBTRACT 1 FROM LDATE.
FDATE = LDATE.
FDATE+6(2) = '01'.
MOVE: FDATE TO X_BUDAT-LOW,
LDATE TO X_BUDAT-HIGH.
APPEND X_BUDAT.

LDATE+6(2) = '28'.
ADD 60 TO LDATE.
LDATE+6(2) = '01'.
SUBTRACT 1 FROM LDATE.
FDATE = LDATE.
FDATE+6(2) = '01'.
MOVE: FDATE TO X_BUDAT2-LOW,
LDATE TO X_BUDAT2-HIGH.
APPEND X_BUDAT2.

No comments:

Archive