Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

REPORT ZCP0050 MESSAGE-ID ZC LINE-SIZE 132.************************************************************************

* Master Data Control Sheet

************************************************************************* Standard IncludeINCLUDE ZSI0009.* TablesTABLES: MAKT, MAST, STKO, STAS, STPO, MARA, MAPL, PLPO, PLKO, PLAS,

CRHD, MBEW, PLMZ, marc.* MaterialsDATA: BEGIN OF MATS OCCURS 100.

DATA: MATNR LIKE MARA-MATNR,

meins like mara-meins.

DATA END OF MATS.* Production versionsDATA: BEGIN OF it_mkal OCCURS 0.

INCLUDE STRUCTURE mkal.

DATA END OF it_mkal.* Bom headersDATA: BEGIN OF it_mast OCCURS 0.

INCLUDE STRUCTURE mast.

DATA END OF it_mast.* Component allocationsDATA: BEGIN OF it_plmz OCCURS 0.

INCLUDE STRUCTURE plmz.

DATA END OF it_plmz.* Internal MAPLDATA: BEGIN OF MAPLI OCCURS 100.

INCLUDE STRUCTURE MAPL.

DATA END OF MAPLI.* Internal STKODATA: BEGIN OF STKOI OCCURS 100.

INCLUDE STRUCTURE STKO.

DATA: MATNR LIKE MARA-MATNR,

STLAN LIKE MAST-STLAN.

DATA END OF STKOI.

* Internal STPO

DATA: BEGIN OF STPOI OCCURS 100.

INCLUDE STRUCTURE STPO.

DATA STLAL LIKE STAS-STLAL.

DATA DELET LIKE STAS-LKENZ.

DATA END OF STPOI.

* Recipe Info

DATA: BEGIN OF ROUTES OCCURS 10.

DATA: matnr like mara-matnr,

PLNNR LIKE PLKO-PLNNR,

PLNAL LIKE PLKO-PLNAL,

plnkn like plpo-plnkn,

VORNR LIKE PLPO-VORNR,

arbid like plpo-arbid,

ARBPL LIKE CRHD-ARBPL,

STEUS LIKE PLPO-STEUS,

phflg type plpo-phflg,

datuv type plas-datuv,

loekz type plas-loekz.

DATA END OF ROUTES.

* Recipe 1 Info

DATA: BEGIN OF ROUTE1 OCCURS 10.

DATA: PLNNR LIKE PLKO-PLNNR,

PLNAL LIKE PLKO-PLNAL,

VORNR LIKE PLPO-VORNR,

ARBPL LIKE CRHD-ARBPL,

STEUS LIKE PLPO-STEUS,

phflg type plpo-phflg.

DATA END OF ROUTE1.

* Recipe 2 Info

DATA: BEGIN OF ROUTE2 OCCURS 10.

DATA: PLNNR LIKE PLKO-PLNNR,

PLNAL LIKE PLKO-PLNAL,

VORNR LIKE PLPO-VORNR,

ARBPL LIKE CRHD-ARBPL,

STEUS LIKE PLPO-STEUS,

phflg type plpo-phflg.

DATA END OF ROUTE2.

* Recipe 3 Info

DATA: BEGIN OF ROUTE3 OCCURS 10.

DATA: PLNNR LIKE PLKO-PLNNR,

PLNAL LIKE PLKO-PLNAL,

VORNR LIKE PLPO-VORNR,

ARBPL LIKE CRHD-ARBPL,

STEUS LIKE PLPO-STEUS,

phflg type plpo-phflg.

DATA END OF ROUTE3.

* Recipe 4 Info

DATA: BEGIN OF ROUTE4 OCCURS 10.

DATA: PLNNR LIKE PLKO-PLNNR,

PLNAL LIKE PLKO-PLNAL,

VORNR LIKE PLPO-VORNR,

ARBPL LIKE CRHD-ARBPL,

STEUS LIKE PLPO-STEUS,

phflg type plpo-phflg.

DATA END OF ROUTE4.

* Temp Data

DATA: LINES(4) TYPE N.

DATA: POS(3) TYPE N VALUE 17.

DATA: POS2(3) TYPE N VALUE 5.

DATA: GET_RID(1) TYPE C.

DATA: MAX_ROUTES(1) TYPE N.

DATA: ROUTE_INDEX(2) TYPE N VALUE 1.

DATA: FINISH1(1) TYPE C VALUE 'X'.

DATA: FINISH2(1) TYPE C VALUE 'X'.

DATA: FINISH3(1) TYPE C VALUE 'X'.

DATA: FINISH4(1) TYPE C VALUE 'X'.

DATA: PRICE LIKE MBEW-STPRS.

DATA: PRICE_DIS(10) TYPE C.

DATA: PRICE_DIS2(10) TYPE C.

DATA: QTY_DIS(12) TYPE C.

DATA: CUR_POS(30) TYPE C.

DATA: TDATUV LIKE STKO-DATUV.

DATA: COUNT(6) TYPE N.

DATA: COUNT1(6) TYPE N.

DATA: COUNT2(6) TYPE N.

DATA: FTIME(1) TYPE C.

DATA: IBMENG(5) TYPE P DECIMALS 3.

data: wa_mapli type mapl,

wa_mast type mast,

output_text(60) type c,

i_found_r type c,

i_found_b type c,

i_wqty type stpo-menge,

i_qty type stpo-menge,

i_totcost type mbew-stprs,

i_totdis(14) type c,

i_rgekz type c.

* Parms

PARAMETERS: WERKS LIKE LQUA-WERKS MEMORY ID WRK OBLIGATORY,

USAGE LIKE MAST-STLAN DEFAULT '1' OBLIGATORY,

BOMTY LIKE STKO-STLTY DEFAULT 'M' OBLIGATORY,

ROUTY LIKE MAPL-PLNTY DEFAULT '2' OBLIGATORY,

DATUV LIKE STKO-DATUV MEMORY ID ZD2,

p_valdat like stko-datuv,

STEUS LIKE PLPO-STEUS,

MTART LIKE MARA-MTART,

MATNR LIKE LQUA-MATNR MATCHCODE OBJECT MAT1

MEMORY ID MAT,

DESC(40) TYPE C MODIF ID DES,

p_waste as checkbox.

* Init.

INITIALIZATION.

* Get any stored parameters

GET PARAMETER ID 'MAT' FIELD MATNR.

GET PARAMETER ID 'WRK' FIELD WERKS.

GET PARAMETER ID 'ZD2' FIELD DATUV.

* default to tadays date

IF DATUV IS INITIAL.

MOVE SY-DATUM TO DATUV.

ENDIF.

* default to todays date

IF p_valdat IS INITIAL.

MOVE SY-DATUM TO p_valdat.

ENDIF.

* Validate Inputs

AT SELECTION-SCREEN OUTPUT.

LOOP AT SCREEN.

IF SCREEN-GROUP1 = 'DES'.

SCREEN-INPUT = '0'.

SCREEN-INVISIBLE = '1'.

MODIFY SCREEN.

ENDIF.

ENDLOOP.

IF NOT ( MATNR IS INITIAL ).

LOOP AT SCREEN.

IF SCREEN-GROUP1 = 'DES'.

CLEAR MAKT-MAKTX.

SELECT SINGLE * FROM MAKT

WHERE MATNR = MATNR

AND SPRAS = SY-LANGU.

IF SY-SUBRC EQ 0.

MOVE MAKT-MAKTX TO DESC.

SCREEN-INPUT = '0'.

SCREEN-INVISIBLE = '0'.

MODIFY SCREEN.

ENDIF.

ENDIF.

ENDLOOP.

ENDIF.

* Validate Inputs

AT SELECTION-SCREEN.

IF MATNR IS INITIAL.

IF MTART IS INITIAL.

* MESSAGE E021.

ENDIF.

ENDIF.

IF NOT ( MATNR IS INITIAL ).

IF NOT ( MTART IS INITIAL ).

* MESSAGE E021.

ENDIF.

ENDIF.

IF DATUV IS INITIAL.

MOVE SY-DATUM TO DATUV.

ENDIF.

IF p_valdat IS INITIAL.

MOVE SY-DATUM TO p_valdat.

ENDIF.

* Main Select Processing.

START-OF-SELECTION.

* Build Mats table.

move 'Extracting Materials' to output_text.

perform inform_user_of_progress.

REFRESH MATS.

CLEAR MATS.

IF NOT ( MATNR IS INITIAL ).

MOVE MATNR TO MATS-MATNR.

* Get the material uom

select single meins into mats-meins

from mara

where matnr = mats-matnr.

APPEND MATS.

ELSEIF NOT ( MTART IS INITIAL ).

SELECT MATNR meins FROM mcon

INTO TABLE MATS

WHERE werks = werks

and MTART = MTART.

ENDIF.

* Set Gui

SET PF-STATUS 'STD'.

SORT MATS BY MATNR.

* Ere we go.

LOOP AT MATS.

* Get the production version info and bom & recipe headers

concatenate 'Extracting Master Data details for material :'

mats-matnr into output_text.

perform inform_user_of_progress.

perform get_prod_vers.

* Get Recipe Information

PERFORM GET_RecipeS.

* Get BOM Information

PERFORM GET_BOM_INFO.

* Delete materials that haven't got any master data

if i_found_r = space and i_found_b = space.

delete mats.

endif.

ENDLOOP.

END-OF-SELECTION.

CLEAR: COUNT1, COUNT2.

DESCRIBE TABLE STPOI LINES COUNT1.

DESCRIBE TABLE ROUTES LINES COUNT2.

IF COUNT1 GT 0 OR COUNT2 GT 0.

SORT ROUTES BY matnr plnnr plnal vornr.

move 'Producing Report' to output_text.

perform inform_user_of_progress.

* Produce Report of details extracted above.

PERFORM PRODUCE_REPORT.

ENDIF.

* Standard Include

INCLUDE ZSI0010.

* Top of Page

TOP-OF-PAGE.

WRITE: /1 '(ZC50) Master Data Control Sheet'.

SKIP.

* Act on user commands.

AT LINE-SELECTION.

GET CURSOR FIELD CUR_POS.

IF NOT ( STPOI-IDNRK IS INITIAL ).

SUBMIT ZCP0050 AND RETURN WITH MATNR EQ STPOI-IDNRK

WITH WERKS EQ WERKS

WITH USAGE EQ USAGE

WITH BOMTY EQ BOMTY

WITH ROUTY EQ ROUTY.

CLEAR STPOI-IDNRK.

ENDIF.

IF CUR_POS EQ 'ROUTE1-ARBPL'.

SET PARAMETER ID 'WRK' FIELD WERKS.

SET PARAMETER ID 'AGR' FIELD ROUTE1-ARBPL.

CALL TRANSACTION 'CR03' AND SKIP FIRST SCREEN.

ENDIF.

IF CUR_POS EQ 'ROUTE2-ARBPL'.

SET PARAMETER ID 'WRK' FIELD WERKS.

SET PARAMETER ID 'AGR' FIELD ROUTE2-ARBPL.

CALL TRANSACTION 'CR03' AND SKIP FIRST SCREEN.

ENDIF.

IF CUR_POS EQ 'ROUTE3-ARBPL'.

SET PARAMETER ID 'WRK' FIELD WERKS.

SET PARAMETER ID 'AGR' FIELD ROUTE3-ARBPL.

CALL TRANSACTION 'CR03' AND SKIP FIRST SCREEN.

ENDIF.

IF CUR_POS EQ 'ROUTE4-ARBPL'.

SET PARAMETER ID 'WRK' FIELD WERKS.

SET PARAMETER ID 'AGR' FIELD ROUTE4-ARBPL.

CALL TRANSACTION 'CR03' AND SKIP FIRST SCREEN.

ENDIF.

* Act on user commands.

AT USER-COMMAND.

CASE SY-UCOMM.

WHEN 'BCK'.

IF SY-CALLD IS INITIAL.

CASE SY-TCODE.

WHEN 'ZC50'.

LEAVE TO TRANSACTION SY-TCODE.

WHEN OTHERS.

LEAVE.

ENDCASE.

ELSE.

LEAVE.

ENDIF.

ENDCASE.

*---------------------------------------------------------------------*

* FORMS SECTION *

* *

*---------------------------------------------------------------------*

*---------------------------------------------------------------------*

* FORM GET_BOM_INFO *

*---------------------------------------------------------------------*

* ........ *

*---------------------------------------------------------------------*

FORM GET_BOM_INFO. "03/98

* Get BOM Information

* Get the effective date

loop at it_mast where matnr = mats-matnr.

SELECT datuv into stko-datuv

FROM STKO

WHERE STLTY = BOMTY

AND STLNR = it_MAST-STLNR

AND STLAL = it_MAST-STLAL

order by datuv ascending.

IF STKO-DATUV LE DATUV.

MOVE STKO-DATUV TO TDATUV.

ENDIF.

endselect.

endloop.

CLEAR: STKOI, STPOI, i_found_b.

* Select all Material records on BOM tables.

loop at it_mast where matnr = mats-matnr.

* For each material record with a BOM Extract BOM Header.

CLEAR: STKO, STKOI.

SELECT * appending corresponding fields of table stkoi

FROM STKO

WHERE STLTY = BOMTY

AND STLNR = it_MAST-STLNR

AND STLAL = it_MAST-STLAL

AND DATUV EQ TDATUV.

loop at stkoi where matnr = space.

* Complete the master details

MOVE: MATS-MATNR TO STKOI-MATNR,

it_MAST-STLAN TO STKOI-STLAN.

modify stkoi.

endloop.

loop at stkoi where matnr = mats-matnr

and stlnr = it_mast-stlnr

and stlal = it_mast-stlal.

* For each header record found extract Item information.

* This next bit of code was changed around completely 12/98

* The old coding couldn't cope with ECM duplicates

* Get the records from STPO which may still be valid

CLEAR: STPO, STPOI. "03/99

SELECT * into corresponding fields of stpoi

FROM STPO

WHERE STLTY = STKOI-STLTY

AND STLNR = STKOI-STLNR

AND DATUV LE DATUV

and postp = 'L'.

* Now we need to check which bom items we want to keep

* Read from stas and get the items in change number order

GET_RID = 'N'.

CLEAR STAS. "03/99

SELECT aennr lkenz datuv stlal

into (stas-aennr, stas-lkenz, stas-datuv, stas-stlal)

FROM STAS

WHERE STLTY = STKOI-STLTY

AND STLNR = STKOI-STLNR

AND STLAL = STKOI-STLAL

AND STLKN = STPOI-STLKN

ORDER BY AENNR.

* If the item has been deleted and the effective date is in the past

* then we don't want this bom item

IF NOT ( STAS-LKENZ IS INITIAL ) AND

STAS-DATUV LE DATUV.

GET_RID = 'Y'.

ENDIF.

* If the effective date is in the future then we don't want it

if stas-datuv gt datuv.

get_rid = 'Y'.

endif.

ENDSELECT.

IF GET_RID = 'N'.

MOVE: STAS-STLAL TO STPOI-STLAL.

APPEND STPOI.

i_found_b = 'X'.

ENDIF.

ENDSELECT.

endloop. "stkoi

endloop. "it_mast

ENDFORM. " GET_BOM_INFO

*---------------------------------------------------------------------*

* FORM GET_RecipeS *

*---------------------------------------------------------------------*

* ........ *

*---------------------------------------------------------------------*

FORM GET_RecipeS. "03/98

* Get Recipe Information

IF STEUS IS INITIAL.

MOVE '%' TO STEUS.

ENDIF.

clear i_found_r.

* Find any Recipes which are allocated to this material

loop at mapli WHERE MATNR = MATS-MATNR.

* Which operations do we need

SELECT * appending corresponding fields of table routes

FROM PLAS

WHERE PLNTY = mapli-plnty

AND PLNNR = mapli-PLNNR

and plnal = mapli-plnal

order by datuv descending.

clear i_found_r.

* Check to see if we want the operations/phases selected

loop at routes where matnr = space.

clear i_found_r.

if routes-datuv gt datuv.

* Op/phase is for the future so don't want it.

delete routes.

i_found_r = 'N'.

check 1 = 2.

endif.

if routes-datuv le datuv and routes-loekz ne space.

* This operation/phase has been deleted so don't want it

delete routes where plnnr = routes-plnnr

and plnal = routes-plnal

and plnkn = routes-plnkn.

i_found_r = 'N'.

check 1 = 2.

endif.

* Now get the op info

SELECT single vornr steus arbid phflg

into corresponding fields of routes

FROM plpo

WHERE PLNTY = mapli-PLNTY

AND PLNNR = routes-PLNNR

AND LOEKZ = SPACE

and plnkn = routes-plnkn

and steus like steus.

* Get rid of this phase / op if plpo select didn't work

if sy-subrc ne 0.

delete routes.

i_found_r = 'N'.

check 1 = 2.

endif.

* Add the work centre description and material number

routes-matnr = mats-matnr.

SELECT single arbpl into routes-arbpl

FROM CRHD

WHERE OBJID = routes-ARBID.

modify ROUTES.

i_found_r = 'X'.

endloop. "routes

endloop. "mapli

* Add Dummy Record to routes table

read table routes with key matnr = mats-matnr.

if sy-subrc ne 0.

clear i_found_r.

else.

routes-matnr = mats-matnr.

MOVE 'XXXXXXXX' TO ROUTES-PLNNR.

MOVE 'XX' TO ROUTES-PLNAL.

MOVE 'XXXX' TO ROUTES-VORNR.

APPEND ROUTES.

ENDIF.

ENDFORM. " GET_RecipeS

*---------------------------------------------------------------------*

* FORM PRODUCE_REPORT *

*---------------------------------------------------------------------*

* ........ *

*---------------------------------------------------------------------*

FORM PRODUCE_REPORT.

loop at mats.

* Do the header bits

PERFORM CLEAR_VARIABLES.

NEW-PAGE.

FORMAT INTENSIFIED OFF.

SELECT SINGLE * FROM MAKT

WHERE MATNR = MATS-MATNR

AND SPRAS = SY-LANGU.

MOVE MAKT-MAKTX TO DESC.

WRITE: /1 SY-ULINE(73),

117 SY-ULINE(14).

WRITE: /1 SY-VLINE,

'Material:' INTENSIFIED ON,

MATS-MATNR,

DESC,

SY-VLINE,

117 SY-VLINE,

SY-DATUM,

SY-VLINE.

WRITE: /1 SY-ULINE(73),

117 SY-ULINE(14).

* Do the production versions first

perform output_pvers.

* Now do the Recipes

PERFORM OUTPUT_RecipeS.

* Now do the BOMs

PERFORM OUTPUT_BOMS.

endloop.

ENDFORM. " PRODUCE_REPORT

*---------------------------------------------------------------------*

* FORM OUTPUT_RecipeS *

*---------------------------------------------------------------------*

* ........ *

*---------------------------------------------------------------------*

FORM OUTPUT_RecipeS.

* Reformat Recipe Information ready for printing

CLEAR MAX_ROUTES.

clear: routes, route1, route2, route3, route4.

refresh: route1, route2, route3, route4.

LOOP AT ROUTES where matnr = mats-matnr.

ON CHANGE OF ROUTES-PLNNR.

IF ROUTES-PLNNR = 'XXXXXXXX'.

DELETE ROUTES.

EXIT.

ENDIF.

ADD 1 TO MAX_ROUTES.

IF MAX_ROUTES GT 4.

EXIT.

ENDIF.

ENDON.

* Delete the dummy record from single bom lists

ON CHANGE OF ROUTES-PLNAL.

IF ROUTES-PLNAL = 'XX'.

DELETE ROUTES.

EXIT.

ENDIF.

ENDON.

IF MAX_ROUTES EQ 1.

MOVE-CORRESPONDING ROUTES TO ROUTE1.

CLEAR FINISH1.

APPEND ROUTE1.

ENDIF.

IF MAX_ROUTES EQ 2.

MOVE-CORRESPONDING ROUTES TO ROUTE2.

CLEAR FINISH2.

APPEND ROUTE2.

ENDIF.

IF MAX_ROUTES EQ 3.

MOVE-CORRESPONDING ROUTES TO ROUTE3.

CLEAR FINISH3.

APPEND ROUTE3.

ENDIF.

IF MAX_ROUTES EQ 4.

MOVE-CORRESPONDING ROUTES TO ROUTE4.

CLEAR FINISH4.

APPEND ROUTE4.

ENDIF.

ENDLOOP.

* Sort into Order

SORT ROUTE1 BY PLNNR PLNAL VORNR.

SORT ROUTE2 BY PLNNR PLNAL VORNR.

SORT ROUTE3 BY PLNNR PLNAL VORNR.

SORT ROUTE4 BY PLNNR PLNAL VORNR.

* Write all of the Recipe info

MOVE 1 TO ROUTE_INDEX.

MOVE 12 TO POS.

MOVE 1 TO POS2.

IF MAX_ROUTES GE 1.

CLEAR FINISH1.

ENDIF.

IF MAX_ROUTES GE 2.

CLEAR FINISH2.

ENDIF.

IF MAX_ROUTES GE 3.

CLEAR FINISH3.

ENDIF.

IF MAX_ROUTES GE 4.

CLEAR FINISH4.

ENDIF.

PERFORM ROUTE_DETAIL_ULINE1.

* Print Recipe Titles.

CLEAR: MAX_ROUTES.

FTIME = 'Y'.

LOOP AT ROUTES where matnr = mats-matnr.

AT NEW PLNNR.

IF FTIME = 'Y'.

FTIME = 'N'.

ELSE.

ADD 1 TO MAX_ROUTES.

IF MAX_ROUTES GT 4.

EXIT.

ENDIF.

ADD 30 TO POS2.

ADD 30 TO POS.

ENDIF.

POSITION POS2.

WRITE: SY-VLINE,

'Recipe' INTENSIFIED ON,

SY-VLINE.

POSITION POS.

WRITE: ROUTES-PLNNR,

SY-VLINE.

ENDAT.

ENDLOOP.

* Write the column headings

PERFORM ROUTE_DETAIL_ULINE.

PERFORM ROUTE_DETAIL_HEADER.

PERFORM ROUTE_DETAIL_ULINE.

* Now write the details of the Recipes

LOOP AT ROUTES where matnr = mats-matnr.

PERFORM ROUTE_DETAILS.

ADD 1 TO ROUTE_INDEX.

ENDLOOP.

ROUTE_INDEX = ROUTE_INDEX - 1.

PERFORM ROUTE_DETAIL_ULINE.

ENDFORM. " OUTPUT_RecipeS

*---------------------------------------------------------------------*

* FORM OUTPUT_BOMS *

*---------------------------------------------------------------------*

* ........ *

*---------------------------------------------------------------------*

FORM OUTPUT_BOMS.

* Loop round the boms for this material

FORMAT INTENSIFIED OFF.

LOOP AT STKOI

WHERE MATNR = MATS-MATNR.

SKIP.

* Write the bom header info

MOVE STKOI-BMENG TO IBMENG.

WRITE: /1 SY-ULINE(72).

WRITE: /1 SY-VLINE,

'BOM Alt No:' INTENSIFIED ON,

STKOI-STLAL,

SY-VLINE,

'BOM Usage' INTENSIFIED ON,

STKOI-STLAN,

SY-VLINE,

'Base Qty:' INTENSIFIED ON,

IBMENG,

SY-VLINE,

'Base UOM:' INTENSIFIED ON,

mats-MEINS,

SY-VLINE.

WRITE: /1 SY-ULINE(72).

clear i_totcost.

PERFORM WRITE_BOM_HDR.

* For each header record found extract Item information.

LOOP AT STPOI

WHERE STLTY = STKOI-STLTY

AND STLNR = STKOI-STLNR

AND STLAL = STKOI-STLAL.

clear: marc, makt, mbew.

* Print BOM Details.

SELECT SINGLE * FROM MAKT

WHERE MATNR = STPOI-IDNRK

AND SPRAS = SY-LANGU.

CONDENSE MAKT-MAKTX.

* Get the price at entered valuation date

SELECT * FROM MBEW

WHERE MATNR = STPOI-IDNRK

AND BWKEY = WERKS

and zkdat le p_valdat

order by zkdat descending.

EXIT.

ENDSELECT.

* Get the component allocations

CLEAR it_PLMZ.

refresh it_plmz.

SELECT * INTO table it_plmz FROM PLMZ

WHERE STLTY = STPOI-STLTY

AND STLNR = STPOI-STLNR

AND STLKN = STPOI-STLKN

AND STLAL = STPOI-STLAL

AND PLNTY = ROUTY.

sort it_plmz by plnnr zuonr ascending datuv descending.

loop at it_plmz.

if it_plmz-datuv gt datuv.

* Allocation is for the future so don't want it.

delete it_plmz.

clear it_plmz.

check 1 = 2.

endif.

if it_plmz-datuv le datuv and it_plmz-loekz ne space.

* This allocation has been deleted so don't want it

delete it_plmz where plnnr = it_plmz-plnnr

and zuonr = it_plmz-zuonr.

clear it_plmz.

check 1 = 2.

endif.

* Make sure it's allocated to a recipe for this material

read table routes with key matnr = mats-matnr

plnnr = it_plmz-plnnr plnal = it_plmz-plnal.

if sy-subrc ne 0.

delete it_plmz.

clear it_plmz.

check 1 = 2.

endif.

* Check the task list header to ensure it's not been deleted

select single * from plko

where plnty = it_plmz-plnty

and plnnr = it_plmz-plnnr

and plnal = it_plmz-plnal

and loekz eq space.

if sy-subrc ne 0.

delete it_plmz.

clear it_plmz.

check 1 = 2.

endif.

* Make sure the component is allocated to a phase

select single * from plpo

where plnty = it_plmz-plnty

and plnnr = it_plmz-plnnr

and plnkn = it_plmz-plnkn

and phflg ne space.

if sy-subrc ne 0.

delete it_plmz.

clear it_plmz.

endif.

endloop.

sort it_plmz by plnnr.

* Get the first record to output

read table it_plmz index 1.

* Get the backflush indicator from the material master

if sy-subrc = 0.

select single rgekz into marc-rgekz

from marc

where matnr = stpoi-idnrk

and werks = werks.

endif.

clear: i_wqty, i_rgekz.

* Use the backflush ind from the material master if the bom is blank

if it_plmz-rgekz ne space.

i_rgekz = 'R'.

elseif marc-rgekz = '1'.

i_rgekz = 'M'.

endif.

* Work out waste qty if required for cost calculation

if p_waste ne space.

i_wqty = ( stpoi-menge * stpoi-ausch ) / 100.

endif.

i_qty = stpoi-menge + i_wqty.

PRICE = ( MBEW-STPRS * i_qty ) / MBEW-PEINH.

i_totcost = i_totcost + price.

MOVE PRICE TO PRICE_DIS.

MOVE MBEW-STPRS TO PRICE_DIS2.

MOVE STPOI-MENGE TO QTY_DIS.

WRITE: /1 SY-VLINE,

STPOI-IDNRK,

20 SY-VLINE,

MAKT-MAKTX+0(20),

SY-VLINE,

QTY_DIS NO-ZERO,

57 SY-VLINE,

58 STPOI-MEINS,

62 SY-VLINE,

63 '%',

STPOI-AUSCH,

71 SY-VLINE,

72 PRICE_DIS2 NO-ZERO,

83 SY-VLINE,

84 PRICE_DIS NO-ZERO,

94 SY-VLINE,

i_rgekz,

98 sy-vline,

it_plmz-plnnr,

109 SY-VLINE,

STPOI-SANKA,

113 SY-VLINE,

STPOI-LGORT,

120 SY-VLINE,

STPOI-DATUV DD/MM/YY,

131 SY-VLINE.

HIDE: STPOI.

* See if there are any more component allocations to print

describe table it_plmz lines count.

if count ge 2.

loop at it_plmz from 2.

clear: i_rgekz.

* Use the backflush ind from the material master if the bom is blank

if it_plmz-rgekz ne space.

i_rgekz = 'R'.

elseif marc-rgekz = '1'.

i_rgekz = 'M'.

endif.

WRITE: /1 SY-VLINE,

20 SY-VLINE,

43 SY-VLINE,

57 SY-VLINE,

62 SY-VLINE,

71 SY-VLINE,

83 SY-VLINE,

94 SY-VLINE,

i_rgekz,

98 sy-vline,

it_plmz-plnnr,

109 SY-VLINE,

113 SY-VLINE,

120 SY-VLINE,

131 SY-VLINE.

endloop.

endif.

ENDLOOP.

WRITE: /1 SY-ULINE(131).

move i_totcost to i_totdis.

Write: /71 sy-vline,

73 'TOTAL:' intensified on,

i_totdis no-zero,

94 sy-vline.

write: /71 sy-uline(24).

ENDLOOP.

ENDFORM. " OUTPUT_BOMS

*---------------------------------------------------------------------*

* FORM WRITE_BOM_HDR *

*---------------------------------------------------------------------*

* ........ *

*---------------------------------------------------------------------*

FORM WRITE_BOM_HDR.

* Column headings for bom items

FORMAT INTENSIFIED ON.

SKIP.

WRITE: /3 text-001.

WRITE: /3 text-002.

WRITE: /1 SY-ULINE(131).

WRITE: /1 SY-VLINE,

'Material',

20 SY-VLINE,

'Description',

43 SY-VLINE,

'Quantity',

57 SY-VLINE,

'UOM',

62 SY-VLINE,

'Waste',

71 SY-VLINE,

75 'Price',

83 SY-VLINE.

if p_waste is initial.

write 87 'Cost'.

else.

write 84 'Cost/waste'.

endif.

write: 94 SY-VLINE,

95 'BF',

98 sy-vline,

'Allocn',

109 SY-VLINE,

110 'RC',

113 SY-VLINE,

'Loc.',

120 SY-VLINE,

'Valid Fr',

131 SY-VLINE.

WRITE: /1 SY-ULINE(131).

FORMAT INTENSIFIED OFF.

ENDFORM. " WRITE_BOM_HDR

*---------------------------------------------------------------------*

* FORM ROUTE_DETAILS *

*---------------------------------------------------------------------*

* ........ *

*---------------------------------------------------------------------*

FORM ROUTE_DETAILS.

READ TABLE ROUTE1 INDEX ROUTE_INDEX.

FORMAT INTENSIFIED OFF.

IF SY-SUBRC EQ 0.

WRITE: / SY-VLINE,

ROUTE1-PLNAL,

SY-VLINE,

7 ROUTE1-VORNR.

* Indicate a phase

if route1-phflg ne space.

write 12 'P'.

endif.

write: 13 SY-VLINE,

ROUTE1-ARBPL,

SY-VLINE,

ROUTE1-STEUS,

SY-VLINE.

HIDE: ROUTE1.

ELSE.

IF FINISH1 IS INITIAL.

WRITE: / SY-ULINE(31).

MOVE 'X' TO FINISH1.

ENDIF.

ENDIF.

READ TABLE ROUTE2 INDEX ROUTE_INDEX.

IF SY-SUBRC EQ 0.

WRITE: 31 SY-VLINE,

ROUTE2-PLNAL,

SY-VLINE,

37 ROUTE2-VORNR.

* Indicate a phase

if route2-phflg ne space.

write 42 'P'.

endif.

write: 43 SY-VLINE,

ROUTE2-ARBPL,

SY-VLINE,

ROUTE2-STEUS,

SY-VLINE.

HIDE: ROUTE2.

ELSE.

IF FINISH2 IS INITIAL.

WRITE: 31 SY-ULINE(31).

MOVE 'X' TO FINISH2.

ENDIF.

ENDIF.

READ TABLE ROUTE3 INDEX ROUTE_INDEX.

IF SY-SUBRC EQ 0.

WRITE: 61 SY-VLINE,

ROUTE3-PLNAL,

SY-VLINE,

67 ROUTE3-VORNR.

* Indicate a phase

if route3-phflg ne space.

write 72 'P'.

endif.

write: 73 SY-VLINE,

ROUTE3-ARBPL,

SY-VLINE,

ROUTE3-STEUS,

SY-VLINE.

HIDE: ROUTE3.

ELSE.

IF FINISH3 IS INITIAL.

WRITE: 61 SY-ULINE(31).

MOVE 'X' TO FINISH3.

ENDIF.

ENDIF.

READ TABLE ROUTE4 INDEX ROUTE_INDEX.

IF SY-SUBRC EQ 0.

WRITE: 91 SY-VLINE,

ROUTE4-PLNAL,

SY-VLINE,

97 ROUTE4-VORNR.

* Indicate a phase

if route4-phflg ne space.

write 102 'P'.

endif.

write: 103 SY-VLINE,

ROUTE4-ARBPL,

SY-VLINE,

ROUTE4-STEUS,

SY-VLINE.

HIDE: ROUTE4.

ELSE.

IF FINISH4 IS INITIAL.

WRITE: 91 SY-ULINE(31).

MOVE 'X' TO FINISH4.

ENDIF.

ENDIF.

ENDFORM.

*&---------------------------------------------------------------------*

*& Form ROUTE_DETAIL_HEADER

*&---------------------------------------------------------------------*

FORM ROUTE_DETAIL_HEADER.

FORMAT INTENSIFIED ON.

READ TABLE ROUTE1 INDEX ROUTE_INDEX.

IF SY-SUBRC EQ 0.

WRITE: / SY-VLINE,

2 'Alt',

SY-VLINE,

7 'Op/Ph',

SY-VLINE,

'Resource',

SY-VLINE,

' CK ',

SY-VLINE.

ENDIF.

READ TABLE ROUTE2 INDEX ROUTE_INDEX.

IF SY-SUBRC EQ 0.

WRITE: 31 SY-VLINE,

32 'Alt',

SY-VLINE,

37 'Op/Ph',

SY-VLINE,

'Resource',

SY-VLINE,

' CK ',

SY-VLINE.

ENDIF.

READ TABLE ROUTE3 INDEX ROUTE_INDEX.

IF SY-SUBRC EQ 0.

WRITE: 61 SY-VLINE,

62 'Alt',

SY-VLINE,

67 'Op/Ph',

SY-VLINE,

'Resource',

SY-VLINE,

' CK ',

SY-VLINE.

ENDIF.

READ TABLE ROUTE4 INDEX ROUTE_INDEX.

IF SY-SUBRC EQ 0.

WRITE: 91 SY-VLINE,

92 'Alt',

SY-VLINE,

97 'Op/Ph',

SY-VLINE,

'Resource',

SY-VLINE,

' CK ',

SY-VLINE.

ENDIF.

FORMAT INTENSIFIED OFF.

ENDFORM. " ROUTE_DETAIL_HEADER

*&---------------------------------------------------------------------*

*& Form ROUTE_DETAIL_ULINE

*&---------------------------------------------------------------------*

FORM ROUTE_DETAIL_ULINE.

READ TABLE ROUTE1 INDEX ROUTE_INDEX.

IF SY-SUBRC EQ 0.

WRITE: / SY-ULINE(31).

ENDIF.

READ TABLE ROUTE2 INDEX ROUTE_INDEX.

IF SY-SUBRC EQ 0.

WRITE: 31 SY-ULINE(31).

ENDIF.

READ TABLE ROUTE3 INDEX ROUTE_INDEX.

IF SY-SUBRC EQ 0.

WRITE: 61 SY-ULINE(31).

ENDIF.

READ TABLE ROUTE4 INDEX ROUTE_INDEX.

IF SY-SUBRC EQ 0.

WRITE: 91 SY-ULINE(31).

ENDIF.

ENDFORM. " ROUTE_DETAIL_ULINE

*&---------------------------------------------------------------------*

*& Form ROUTE_DETAIL_ULINE1

*&---------------------------------------------------------------------*

FORM ROUTE_DETAIL_ULINE1.

READ TABLE ROUTE1 INDEX ROUTE_INDEX.

IF SY-SUBRC EQ 0.

WRITE: / SY-ULINE(21).

ENDIF.

READ TABLE ROUTE2 INDEX ROUTE_INDEX.

IF SY-SUBRC EQ 0.

WRITE: 31 SY-ULINE(21).

ENDIF.

READ TABLE ROUTE3 INDEX ROUTE_INDEX.

IF SY-SUBRC EQ 0.

WRITE: 61 SY-ULINE(21).

ENDIF.

READ TABLE ROUTE4 INDEX ROUTE_INDEX.

IF SY-SUBRC EQ 0.

WRITE: 91 SY-ULINE(21).

ENDIF.

NEW-LINE.

ENDFORM. " ROUTE_DETAIL_ULINE1

*&---------------------------------------------------------------------*

*& Form CLEAR_VARIABLES

*&---------------------------------------------------------------------*

FORM CLEAR_VARIABLES.

POS = 17.

POS2 = 5.

CLEAR MAX_ROUTES.

ROUTE_INDEX = 1.

FINISH1 = 'X'.

FINISH2 = 'X'.

FINISH3 = 'X'.

FINISH4 = 'X'.

CLEAR PRICE.

CLEAR PRICE_DIS.

CLEAR PRICE_DIS2.

CLEAR QTY_DIS.

CLEAR CUR_POS.

ENDFORM. " CLEAR_VARIABLES

*&---------------------------------------------------------------------*

*& Form GET_PROD_VERS

*&---------------------------------------------------------------------*

* Procuction version information and recipe and bom header info

*----------------------------------------------------------------------*

FORM GET_PROD_VERS.

* First get the production version info

select * appending table it_mkal

from mkal

where matnr = mats-matnr

and werks = werks

and mksp = space

and bdatu >= datuv

and adatu <= datuv

and plnty = routy

and stlan = usage.

* Now get the recipe & bom headers

loop at it_mkal where matnr = mats-matnr.

perform get_pv_recipes.

perform get_pv_boms.

endloop.

* Get the recipe and bom info for materials without prod versions

perform get_recipe_headers.

perform get_bom_headers.

ENDFORM. " GET_PROD_VERS

*&---------------------------------------------------------------------*

*& Form GET_PV_RECIPES

*&---------------------------------------------------------------------*

* Get the recipe headers for materials with prod vers

*----------------------------------------------------------------------*

FORM GET_PV_RECIPES.

clear: mapli.

SELECT * FROM MAPL

into table mapli

WHERE MATNR = MATS-MATNR

AND WERKS = WERKS

AND PLNTY = it_mkal-plnty

and plnnr = it_mkal-plnnr

and plnal = it_mkal-alnal

AND LOEKZ = SPACE.

SORT MAPLI BY matnr werks DATUV ASCENDING.

ENDFORM. " GET_PV_RECIPES

*&---------------------------------------------------------------------*

*& Form GET_PV_BOMS

*&---------------------------------------------------------------------*

* Get the bom headers for materials with prod vers

*----------------------------------------------------------------------*

FORM GET_PV_BOMS.

clear: it_mast.

SELECT * FROM MAST

into table it_mast

WHERE STLAN = it_mkal-stlan

and stlal = it_mkal-stlal

AND WERKS = WERKS

AND MATNR = MATS-MATNR

and stlnr <> space.

ENDFORM. " GET_PV_BOMS

*&---------------------------------------------------------------------*

*& Form GET_RECIPE_HEADERS

*&---------------------------------------------------------------------*

* Get the recipe header for materials with no prod version

*----------------------------------------------------------------------*

FORM GET_RECIPE_HEADERS.

clear: mapli.

SELECT * FROM MAPL

into wa_mapli

WHERE MATNR = MATS-MATNR

AND WERKS = WERKS

AND PLNTY = routy

AND LOEKZ = SPACE.

* See if we've already got this one

read table mapli from wa_mapli.

if sy-subrc ne 0.

* No so add

append wa_mapli to mapli.

endif.

endselect.

SORT MAPLI BY matnr werks DATUV ASCENDING.

ENDFORM. " GET_RECIPE_HEADERS

*&---------------------------------------------------------------------*

*& Form GET_BOM_HEADERS

*&---------------------------------------------------------------------*

* Get bom headers for materials without prod versions

*----------------------------------------------------------------------*

FORM GET_BOM_HEADERS.

clear: it_mast.

SELECT * FROM MAST

into wa_mast

WHERE STLAN = usage

AND WERKS = WERKS

AND MATNR = MATS-MATNR

and stlnr <> space.

* See if we've already got this one

read table it_mast from wa_mast.

if sy-subrc ne 0.

* No so add

append wa_mast to it_mast.

endif.

endselect.

ENDFORM. " GET_BOM_HEADERS

*&---------------------------------------------------------------------*

*& Form INFORM_USER_OF_PROGRESS

*&---------------------------------------------------------------------*

* Display text line

*----------------------------------------------------------------------*

FORM INFORM_USER_OF_PROGRESS.

* Update Gui

condense output_text.

call function 'SAPGUI_PROGRESS_INDICATOR'

exporting

text = output_text.

ENDFORM. " INFORM_USER_OF_PROGRESS

*&---------------------------------------------------------------------*

*& Form OUTPUT_PVERS

*&---------------------------------------------------------------------*

* Output the production versions

*----------------------------------------------------------------------*

FORM OUTPUT_PVERS.

* Do the header

read table it_mkal with key matnr = mats-matnr.

check sy-subrc = 0.

format intensified on.

WRITE: /1 SY-ULINE(59).

WRITE: /1 SY-VLINE,

'Version',

SY-VLINE,

'Recipe',

22 SY-VLINE,

'Alt',

28 SY-VLINE,

'BOM Alt',

38 SY-VLINE,

'Usage',

46 SY-VLINE,

'Prod. Line',

59 sy-vline.

format intensified off.

loop at it_mkal where matnr = mats-matnr.

WRITE: /1 SY-ULINE(59).

WRITE: /1 SY-VLINE,

it_mkal-verid,

11 SY-VLINE,

it_mkal-plnnr,

22 SY-VLINE,

it_mkal-alnal,

28 SY-VLINE,

it_mkal-stlal,

38 SY-VLINE,

it_mkal-stlan,

46 SY-VLINE,

it_mkal-mdv01,

59 sy-vline.

endloop.

WRITE: /1 SY-ULINE(59).

ENDFORM. " OUTPUT_PVERS