REPORT zmat_req.
*REPORT z62mr023_mat_req_list .
*---------------------------------------------------------------------*
* MODULE : MM. *
*---------------------------------------------------------------------*
* Material Requirement List With Pending Orders *
* *
* *
* Date Created *
* Consultant *
* Author *
* Location *
* LDB ..... *
*---------------------------------------------------------------------*
*---------------------------------------------------------------------*
* Amendment History *
*---------------------------------------------------------------------*
* Who/date Reason *
* ¯¯¯¯¯¯¯¯¯¯ ¯¯¯¯¯¯ *
* XXXXDDMMYYYY Where xxxx = developers initials...................... *
* ...................................................... *
* *
* XXXXDDMMYYYY ..................................................... *
* ...................................................... *
*---------------------------------------------------------------------*
*---------------------------------------------------------------------*
* Tables *
*---------------------------------------------------------------------*
TABLES: resb,
mbew,
marc,
mara,
makt,
ekpo,
eket,
lfa1,
t023,
ekko.
*---------------------------------------------------------------------*
* Data Statments *
*---------------------------------------------------------------------*
*---Internal table to select requirements data
DATA: BEGIN OF it_init_data OCCURS 10,
matnr LIKE resb-matnr,
werks LIKE resb-werks,
ekgrp LIKE resb-ekgrp,
bdter LIKE resb-bdter,
bdmng LIKE resb-bdmng,
enmng LIKE resb-enmng,
lbkum LIKE mbew-lbkum,
meins LIKE mara-meins,
maktx LIKE makt-maktx,
rsnum LIKE resb-rsnum,
END OF it_init_data.
DATA: BEGIN OF it_repo OCCURS 10,
matnr LIKE resb-matnr,
werks LIKE resb-werks,
ekgrp LIKE resb-ekgrp,
bdter LIKE resb-bdter,
w_month1(6),
bdmng LIKE resb-bdmng,
enmng LIKE resb-enmng,
lbkum LIKE mbew-lbkum,
maktx LIKE makt-maktx,
short LIKE resb-bdmng,
rsnum LIKE resb-rsnum,
ebeln LIKE eket-ebeln,
ebelp LIKE eket-ebelp,
eindt LIKE eket-eindt,
menge LIKE eket-menge,
meins LIKE ekpo-meins,
lifnr LIKE ekko-lifnr,
name1 LIKE lfa1-name1,
banfn LIKE eban-banfn,
bnfpo LIKE eban-bnfpo,
menge_req LIKE eban-menge,
lfdat LIKE eban-lfdat,
END OF it_repo.
DATA: BEGIN OF it_eket OCCURS 10,
lifnr LIKE ekko-lifnr,
ebeln LIKE eket-ebeln,
ebelp LIKE eket-ebelp,
eindt LIKE eket-eindt,
menge LIKE eket-menge,
wemng LIKE eket-wemng,
meins LIKE ekpo-meins,
END OF it_eket.
DATA: BEGIN OF it_eban OCCURS 10,
banfn LIKE eban-banfn,
bnfpo LIKE eban-bnfpo,
menge LIKE eban-menge,
lfdat LIKE eban-lfdat,
bsmng LIKE eban-bsmng,
meins LIKE eban-meins,
END OF it_eban.
DATA: w_lin TYPE i,
w_month(2),
w_month1(3),
w_bal LIKE mbew-lbkum,
w_req LIKE resb-bdmng,
w_iss LIKE resb-enmng,
w_bdmng LIKE resb-bdmng,
w_bdmng1 LIKE resb-bdmng,
w_bal_qty LIKE eket-wemng,
w_req_qty LIKE eban-menge,
w_matnr LIKE ekpo-matnr,
w_werks LIKE ekpo-werks,
w_count TYPE i,
flag.
* Begin of Addition Nigel D'Souza 22.01.03(SBS, S'pore )
DATA : w_year(4).
* End of Addition Nigel D'Souza
*---------------------------------------------------------------------*
* INITIALIZATION *
*---------------------------------------------------------------------*
INITIALIZATION.
SKIP 2.
SELECTION-SCREEN BEGIN OF BLOCK 1 WITH FRAME TITLE text-001.
*---------------------------------------------------------------------*
* SELECTION-OPTION *
*---------------------------------------------------------------------*
SELECT-OPTIONS:
* Start of Changes - Giri (2002/12/20)
* so_matnr FOR resb-matnr OBLIGATORY,
so_matnr FOR resb-matnr ,
so_matkl FOR t023-matkl,
so_baugr FOR resb-baugr,
* End of Changes - Giri (2002/12/20)
so_werks FOR resb-werks OBLIGATORY
NO-EXTENSION NO INTERVALS,
so_bdter FOR resb-bdter,
so_ekgrp FOR resb-ekgrp,
so_dispo FOR marc-dispo,
so_mtart FOR mara-mtart.
SELECTION-SCREEN END OF BLOCK 1.
* begin of changes Nigel 10.01.2003
SELECTION-SCREEN BEGIN OF BLOCK 2 WITH FRAME TITLE text-100.
PARAMETERS : p_ar RADIOBUTTON GROUP type,
p_sb RADIOBUTTON GROUP type,
p_bt RADIOBUTTON GROUP type.
SELECTION-SCREEN END OF BLOCK 2.
* end of Change Nigel 10.01.2003
*---------------------------------------------------------------------*
* START-OF-SELECTION *
*---------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM data_collction.
PERFORM build_disp_table.
PERFORM data_display.
*----------------------------------------------------------------------*
* TOP-OF-PAGE *
*----------------------------------------------------------------------*
TOP-OF-PAGE.
WRITE : sy-uline.
FORMAT COLOR COL_HEADING INTENSIFIED OFF.
WRITE :/ sy-vline NO-GAP,
'Plnt',
'Material/Desc',
26 'Month',
37 'Current Stock',
58 'Requirements',
76 'Cummulative Shortages',
100 sy-vline.
FORMAT COLOR COL_HEADING INTENSIFIED OFF.
WRITE :/ sy-vline NO-GAP,
7 'Pending PO',
26 'Srno.',
37 'Pend.PO Quantity',
58 'Schd Del. Date',
100 sy-vline.
WRITE : sy-uline.
*---------------------------------------------------------------------*
* AT LINE-SELECTION *
*---------------------------------------------------------------------*
AT LINE-SELECTION.
*---Change Purchase Order (ME22N)
IF NOT it_repo-ebeln IS INITIAL.
SET PARAMETER ID 'BES' FIELD it_repo-ebeln.
* Start of Changes - Giri (2002/12/20)
* CALL TRANSACTION 'ME22N' AND SKIP FIRST SCREEN.
CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
* End of Changes - Giri (2002/12/20)
CLEAR: it_repo-ebeln.
ENDIF.
*---Change Purchase Requisition (ME53N)
IF NOT it_repo-banfn IS INITIAL.
SET PARAMETER ID 'BAN' FIELD it_repo-banfn.
CALL TRANSACTION 'ME53N' AND SKIP FIRST SCREEN.
CLEAR: it_repo-banfn.
ENDIF.
*---Stock Overview (MMBE)
IF NOT it_repo-matnr IS INITIAL AND
NOT it_repo-werks IS INITIAL.
SET PARAMETER ID 'MAT' FIELD it_repo-matnr.
SET PARAMETER ID 'WRK' FIELD it_repo-werks.
CALL TRANSACTION 'MMBE' AND SKIP FIRST SCREEN.
CLEAR: it_repo-matnr, it_repo-werks.
ENDIF.
*&---------------------------------------------------------------------*
*& Form data_collction
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM data_collction.
* begin of CHange Nigel 10.01.2003
IF p_ar = 'X'.
SELECT matnr werks bdter bdmng enmng rsnum meins
FROM resb CLIENT SPECIFIED
INTO CORRESPONDING FIELDS OF TABLE it_init_data
WHERE mandt EQ sy-mandt
AND matnr IN so_matnr
AND werks EQ so_werks-low
* Start of Changes - Giri (2002/12/20)
AND baugr IN so_baugr
AND xloek EQ space
AND kzear EQ space
* End of Changes - Giri (2002/12/20)
AND bdter IN so_bdter
* bEGIN OF CHANGE NIGEL 10.01.2003
AND bdart = 'AR'.
* END OF CHANGE NIGEL 10.01.2003
ELSEIF p_sb = 'X'.
SELECT matnr werks bdter bdmng enmng rsnum meins
FROM resb CLIENT SPECIFIED
INTO CORRESPONDING FIELDS OF TABLE it_init_data
WHERE mandt EQ sy-mandt
AND matnr IN so_matnr
AND werks EQ so_werks-low
* Start of Changes - Giri (2002/12/20)
AND baugr IN so_baugr
AND xloek EQ space
AND kzear EQ space
* End of Changes - Giri (2002/12/20)
AND bdter IN so_bdter
* bEGIN OF CHANGE NIGEL 10.01.2003
AND bdart = 'SB'.
* END OF CHANGE NIGEL 10.01.2003
ELSEIF p_bt = 'X'.
SELECT matnr werks bdter bdmng enmng rsnum meins
FROM resb CLIENT SPECIFIED
INTO CORRESPONDING FIELDS OF TABLE it_init_data
WHERE mandt EQ sy-mandt
AND matnr IN so_matnr
AND werks EQ so_werks-low
* Start of Changes - Giri (2002/12/20)
AND baugr IN so_baugr
AND xloek EQ space
AND kzear EQ space
* End of Changes - Giri (2002/12/20)
AND bdter IN so_bdter
* BEGIN OF CHANGE NIGEL 10.01.2003
AND ( bdart = 'AR' OR
bdart = 'SB' ) .
* END OF CHANGE NIGEL 10.01.2003
ENDIF.
* END OF CHANGE NIGEL 10.01.2003
DESCRIBE TABLE it_init_data LINES w_lin.
IF w_lin EQ 0.
MESSAGE e398(00) WITH 'No data exists for given selection'
space space space.
ENDIF.
LOOP AT it_init_data.
*---Remove records for non matching of MRP Controller
* and purchasing group
SELECT SINGLE * FROM marc CLIENT SPECIFIED
WHERE mandt EQ sy-mandt
AND matnr EQ it_init_data-matnr
AND werks EQ it_init_data-werks
AND dispo IN so_dispo
AND ekgrp IN so_ekgrp.
IF sy-subrc <> 0.
DELETE it_init_data.
CONTINUE.
ENDIF.
*---Remove records for non matching of Material Type
SELECT SINGLE * FROM mara CLIENT SPECIFIED
WHERE mandt EQ sy-mandt
AND matnr EQ it_init_data-matnr
* Start of Changes - Giri (2002/12/20)
AND mtart IN so_matkl
* End of Changes - Giri (2002/12/20)
AND mtart IN so_mtart.
IF sy-subrc <> 0.
DELETE it_init_data.
CONTINUE.
ENDIF.
*---Find the material description
SELECT SINGLE * FROM makt CLIENT SPECIFIED
WHERE mandt EQ sy-mandt
AND matnr EQ it_init_data-matnr
AND spras EQ 'EN'.
MOVE makt-maktx TO it_init_data-maktx.
MODIFY it_init_data.
ENDLOOP.
ENDFORM. " data_collction
*&---------------------------------------------------------------------*
*& Form BUILD_DISP_TABLE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM build_disp_table.
SORT it_init_data BY werks matnr bdter rsnum.
CLEAR: w_month, w_iss, w_count.
LOOP AT it_init_data.
AT NEW matnr.
READ TABLE it_init_data INDEX sy-tabix.
*---Find the total stock for the material
SELECT SINGLE * FROM mbew CLIENT SPECIFIED
WHERE mandt EQ sy-mandt
AND matnr EQ it_init_data-matnr
AND bwkey EQ it_init_data-werks.
w_bal = mbew-lbkum.
*---Find the material description
SELECT SINGLE * FROM makt CLIENT SPECIFIED
WHERE mandt EQ sy-mandt
AND matnr EQ it_init_data-matnr
AND spras EQ 'EN'.
CLEAR it_repo.
MOVE: it_init_data-matnr TO it_repo-matnr,
it_init_data-werks TO it_repo-werks,
it_init_data-meins TO it_repo-meins,
mbew-lbkum TO it_repo-lbkum,
makt-maktx TO it_repo-maktx.
flag = 'X'.
ENDAT.
IF it_init_data-bdter+4(2) NE w_month
* AND W_COUNT <= 3
AND flag = ' '.
*---This perform is added to convert month in words
PERFORM month_in_word.
* Begin of Change Nigel D'Souza 22.01.03(SBS, S'pore )
* it_repo-w_month1 = w_month1.
CONCATENATE w_year w_month1 INTO it_repo-w_month1.
* End of Change Nigel D'Souza
it_repo-bdmng = w_req - w_iss.
it_repo-short = it_repo-bdmng - w_bal.
IF it_repo-short < 0.
it_repo-short = 0.
ELSE.
it_repo-short = it_repo-short * -1.
ENDIF.
w_bal = w_bal - it_repo-bdmng.
APPEND it_repo.
CLEAR it_repo.
w_count = w_count + 1.
CLEAR: w_req, w_iss.
ENDIF.
w_month = it_init_data-bdter+4(2).
* Begin of Addition Nigel D'Souza 22.01.03(SBS, S'pore )
w_year = it_init_data-bdter+0(4).
* End of Addition Nigel D'Souza
w_req = w_req + it_init_data-bdmng.
w_iss = w_iss + it_init_data-enmng.
flag = ' '.
w_matnr = it_init_data-matnr.
w_werks = it_init_data-werks.
AT END OF matnr.
READ TABLE it_init_data INDEX sy-tabix.
*---This perform is added to convert month in words
PERFORM month_in_word.
* Begin of Change Nigel D'Souza 22.01.03(SBS, S'pore )
* it_repo-w_month1 = w_month1.
CONCATENATE w_year w_month1 INTO it_repo-w_month1.
* End of Change Nigel D'Souza
it_repo-bdmng = w_req - w_iss.
it_repo-short = it_repo-bdmng - w_bal.
IF it_repo-short < 0.
it_repo-short = 0.
ELSE.
it_repo-short = it_repo-short * -1.
ENDIF.
APPEND it_repo.
CLEAR it_repo.
CLEAR: w_req, w_iss, w_bal, w_month.
*---FInd the pending orders quantity & delivery date
CLEAR it_eket.
REFRESH it_eket.
SELECT a~meins
b~ebeln b~ebelp b~eindt b~menge b~wemng
INTO CORRESPONDING FIELDS OF TABLE it_eket
FROM ( ekpo AS a INNER JOIN eket AS b
ON a~ebeln EQ b~ebeln
AND a~ebelp EQ b~ebelp )
WHERE a~loekz EQ ' '
AND a~matnr EQ w_matnr
AND a~werks EQ w_werks
AND a~pstyp EQ 0
AND a~bstyp EQ 'F'
AND a~mtart IN so_mtart
AND b~wemng < b~menge.
LOOP AT it_eket.
*---Find the Vendor code
CLEAR ekko.
SELECT SINGLE * FROM ekko CLIENT SPECIFIED
WHERE mandt EQ sy-mandt
AND ebeln EQ it_eket-ebeln.
MOVE ekko-lifnr TO it_eket-lifnr.
MODIFY it_eket.
ENDLOOP.
SORT it_eket BY lifnr ebeln ebelp.
LOOP AT it_eket.
AT NEW lifnr.
*---Find the vendor name
CLEAR lfa1.
SELECT SINGLE * FROM lfa1 CLIENT SPECIFIED
WHERE mandt EQ sy-mandt
AND lifnr EQ ekko-lifnr.
MOVE: it_eket-lifnr TO it_repo-lifnr,
lfa1-name1 TO it_repo-name1.
APPEND it_repo.
CLEAR it_repo.
ENDAT.
AT NEW ebeln.
MOVE it_eket-ebeln TO it_repo-ebeln.
ENDAT.
w_bal_qty = it_eket-menge - it_eket-wemng.
MOVE: it_eket-ebelp TO it_repo-ebelp,
it_eket-eindt TO it_repo-eindt,
it_eket-meins TO it_repo-meins,
w_bal_qty TO it_repo-menge.
APPEND it_repo.
CLEAR it_repo.
ENDLOOP.
*---Find the pending purchase requisitions for the
* same material
SELECT banfn bnfpo menge meins lfdat bsmng
INTO CORRESPONDING FIELDS OF TABLE it_eban
FROM eban CLIENT SPECIFIED
WHERE mandt EQ sy-mandt
AND bstyp EQ 'B'
AND loekz EQ ' '
AND statu IN ('A', 'N', 'B')
AND matnr EQ w_matnr
AND werks EQ w_werks
AND ebakz EQ ' '.
SORT it_eban BY banfn bnfpo.
LOOP AT it_eban.
IF it_eban-bsmng < it_eban-menge.
CLEAR it_repo.
w_req_qty = it_eban-menge - it_eban-bsmng.
MOVE: it_eban-banfn TO it_repo-banfn,
it_eban-bnfpo TO it_repo-bnfpo,
it_eban-lfdat TO it_repo-lfdat,
it_eban-meins TO it_repo-meins,
w_req_qty TO it_repo-menge_req.
APPEND it_repo.
ENDIF.
ENDLOOP.
ENDAT.
ENDLOOP.
ENDFORM. " BUILD_DISP_TABLE
*&---------------------------------------------------------------------*
*& Form DATA_DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM data_display.
LOOP AT it_repo.
IF it_repo-matnr NE ' '.
WRITE:/ sy-vline NO-GAP,
100 sy-vline NO-GAP.
FORMAT COLOR COL_HEADING INTENSIFIED OFF.
WRITE:/ sy-vline NO-GAP,
it_repo-werks.
FORMAT HOTSPOT ON.
WRITE: it_repo-matnr.
FORMAT HOTSPOT OFF.
WRITE: it_repo-maktx,
100 sy-vline NO-GAP.
HIDE: it_repo-matnr, it_repo-werks.
ENDIF.
IF it_repo-w_month1 NE ' '.
IF it_repo-short < 0.
FORMAT COLOR COL_NEGATIVE INTENSIFIED OFF.
ELSE.
FORMAT COLOR COL_POSITIVE INTENSIFIED OFF.
ENDIF.
WRITE:/ sy-vline NO-GAP,
26 it_repo-w_month1.
IF it_repo-lbkum NE 0.
WRITE:32 it_repo-lbkum,
it_repo-meins.
ENDIF.
WRITE:54 it_repo-bdmng,
71 it_repo-short,
100 sy-vline NO-GAP.
ENDIF.
IF it_repo-lifnr NE ' '.
FORMAT COLOR COL_HEADING INTENSIFIED OFF.
WRITE:/ sy-vline NO-GAP,
6 it_repo-lifnr,
26 it_repo-name1,
100 sy-vline NO-GAP.
ENDIF.
IF it_repo-ebelp NE ' '.
FORMAT COLOR COL_TOTAL INTENSIFIED OFF.
WRITE:/ sy-vline NO-GAP.
FORMAT HOTSPOT ON.
WRITE:6 it_repo-ebeln.
FORMAT HOTSPOT OFF.
WRITE: 26 it_repo-ebelp,
32 it_repo-menge,
it_repo-meins,
60 it_repo-eindt,
100 sy-vline NO-GAP.
HIDE: it_repo-ebeln.
ENDIF.
IF it_repo-banfn NE ' '.
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
WRITE:/ sy-vline NO-GAP.
FORMAT HOTSPOT ON.
WRITE:6 it_repo-banfn.
FORMAT HOTSPOT OFF.
WRITE: 26 it_repo-bnfpo,
32 it_repo-menge_req,
it_repo-meins,
60 it_repo-lfdat,
100 sy-vline NO-GAP.
HIDE: it_repo-banfn.
ENDIF.
ENDLOOP.
WRITE : sy-uline.
CLEAR it_repo.
ENDFORM. " DATA_DISPLAY
*&---------------------------------------------------------------------*
*& Form MONTH_IN_WORD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM month_in_word.
* begin of CHange - Nigel D'Souza 27.01.03
* IF w_month = '01'.
* w_month1 = 'Jan'.
* ELSEIF w_month = '02'.
* w_month1 = 'Feb'.
* ELSEIF w_month = '03'.
* w_month1 = 'Mar'.
* ELSEIF w_month = '04'.
* w_month1 = 'Apr'.
* ELSEIF w_month = '05'.
* w_month1 = 'May'.
* ELSEIF w_month = '06'.
* w_month1 = 'Jun'.
* ELSEIF w_month = '07'.
* w_month1 = 'Jul'.
* ELSEIF w_month = '08'.
* w_month1 = 'Aug'.
* ELSEIF w_month = '09'.
* w_month1 = 'Sep'.
* ELSEIF w_month = '10'.
* w_month1 = 'Oct'.
* ELSEIF w_month = '11'.
* w_month1 = 'Nov'.
* ELSEIF w_month = '12'.
* w_month1 = 'Dec'.
* ENDIF.
IF w_month = '01'.
w_month1 = '01'.
ELSEIF w_month = '02'.
w_month1 = '02'.
ELSEIF w_month = '03'.
w_month1 = '03'.
ELSEIF w_month = '04'.
w_month1 = '04'.
ELSEIF w_month = '05'.
w_month1 = '05'.
ELSEIF w_month = '06'.
w_month1 = '06'.
ELSEIF w_month = '07'.
w_month1 = '07'.
ELSEIF w_month = '08'.
w_month1 = '08'.
ELSEIF w_month = '09'.
w_month1 = '09'.
ELSEIF w_month = '10'.
w_month1 = '10'.
ELSEIF w_month = '11'.
w_month1 = '11'.
ELSEIF w_month = '12'.
w_month1 = '12'.
ENDIF.
* end of change - Nigel D'Souza
ENDFORM. " MONTH_IN_WORD
No comments:
Post a Comment