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 ZCP0054 MESSAGE-ID ZC LINE-SIZE 132.************************************************************************

* Daily Production Report*

* Aveek Ghose Year: 2000.

************************************************************************* Standard IncludeINCLUDE ZSI0009.* TablesTABLES:

CAUFV,

AFVC,

MAKT,

AFPO,

CRHD,

MARA,

MSEG,

T001W,

T001,

MBEW,

PLAF,

AFVV,

ZCOO5,

ZCOO7,* ZC008,MARM,

T006,

T006A,

MKAL.* Selected data table.DATA: BEGIN OF AFPO_SELECT OCCURS 50.

DATA: EFFIC(5) TYPE P DECIMALS 2.

DATA: WDATE LIKE SY-DATUM.

DATA: DAYTXT(9) TYPE C.

DATA: POS1(3) TYPE N.

DATA: ORDTYP(1) TYPE C. " V.2

DATA: ARBPL LIKE CRHD-ARBPL.

DATA: GAMNG LIKE AFKO-GAMNG.

DATA: GMEIN LIKE AFKO-GMEIN. " V.2

INCLUDE STRUCTURE AFPO.

INCLUDE STRUCTURE ZCOO5. " V.2

DATA: END OF AFPO_SELECT.

* New internal area for caufv selection

types: begin of t_caufv,

aufnr type caufv-aufnr,

aufpl type caufv-aufpl,

plnbez type caufv-plnbez,

objnr type caufv-objnr,

gamng type caufv-gamng,

gmein type caufv-gmein,

end of t_caufv.

data: i_caufv type standard table of t_caufv,

wa_caufv type t_caufv.

DATA BEGIN OF CALKEY. " V.2

INCLUDE STRUCTURE ZC008A. " V.2

DATA END OF CALKEY. " V.2

" V.2

DATA BEGIN OF CAL OCCURS 50. " V.2

INCLUDE STRUCTURE ZC008A. " V.2

DATA END OF CAL. " V.2

" V.2

DATA BEGIN OF UOM_IN. " V.2

INCLUDE STRUCTURE T006. " V.2

DATA END OF UOM_IN. " V.2

" V.2

DATA BEGIN OF UOM_OUT. " V.2

INCLUDE STRUCTURE T006. " V.2

DATA END OF UOM_OUT. " V.2

" V.2

DATA BEGIN OF MARM_IN. " V.2

INCLUDE STRUCTURE MARM. " V.2

DATA END OF MARM_IN. " V.2

" V.2

DATA BEGIN OF MARM_OUT. " V.2

INCLUDE STRUCTURE MARM. " V.2

DATA END OF MARM_OUT. " V.2

" V.2

DATA BEGIN OF P_LINE. " V.2

INCLUDE STRUCTURE ZCOO7. " V.2

DATA END OF P_LINE. " V.2

" V.2

DATA BEGIN OF SUBTOT. " V.2

INCLUDE STRUCTURE ZCOO7. " V.2

DATA END OF SUBTOT. " V.2

" V.2

DATA BEGIN OF PERTOT. " V.2

INCLUDE STRUCTURE ZCOO7. " V.2

DATA END OF PERTOT. " V.2

" V.2

DATA BEGIN OF TOTAL. " V.2

INCLUDE STRUCTURE ZCOO7. " V.2

DATA END OF TOTAL. " V.2

" V.2

DATA BEGIN OF OLD. " V.2

DATA: " V.2

FIRST(1) TYPE C VALUE 'Y', " V.2

YEAR LIKE ZCOO7-ZYEAR VALUE 0, " V.2

PERIOD LIKE ZCOO7-ZPERIOD VALUE 0, " V.2

ARBPL LIKE ZCOO7-ZARBPL VALUE ' ', " V.2

BISMT LIKE ZCOO7-ZBISMT VALUE ' ', " V.2

ORDTYP(1) TYPE C VALUE '1', " V.2

WEEK LIKE ZCOO7-ZWEEK1 VALUE 0. " V.2

DATA END OF OLD. " V.2

" V.2

DATA BEGIN OF CLEAR_LINE. " V.2

DATA:

ZPLQTY1 LIKE ZCOO7-ZPLQTY1 VALUE 0, " V.2

ZACQTY1 LIKE ZCOO7-ZACQTY1 VALUE 0, " V.2

ZPCT1 LIKE ZCOO7-ZPCT1 VALUE 0,

ZPLQTY2 LIKE ZCOO7-ZPLQTY2 VALUE 0, " V.2

ZACQTY2 LIKE ZCOO7-ZACQTY2 VALUE 0, " V.2

ZPCT2 LIKE ZCOO7-ZPCT2 VALUE 0,

ZPLQTY3 LIKE ZCOO7-ZPLQTY3 VALUE 0, " V.2

ZACQTY3 LIKE ZCOO7-ZACQTY3 VALUE 0, " V.2

ZPCT3 LIKE ZCOO7-ZPCT3 VALUE 0,

ZPLQTY4 LIKE ZCOO7-ZPLQTY4 VALUE 0, " V.2

ZACQTY4 LIKE ZCOO7-ZACQTY4 VALUE 0, " V.2

ZPCT4 LIKE ZCOO7-ZPCT4 VALUE 0,

ZPLQTY5 LIKE ZCOO7-ZPLQTY5 VALUE 0, " V.2

ZACQTY5 LIKE ZCOO7-ZACQTY5 VALUE 0, " V.2

ZPCT5 LIKE ZCOO7-ZPCT5 VALUE 0,

ZTOTALP LIKE ZCOO7-ZTOTALP VALUE 0, " V.2

ZTOTALA LIKE ZCOO7-ZTOTALA VALUE 0, " V.2

ZPCTOT LIKE ZCOO7-ZPCTOT VALUE 0.

DATA END OF CLEAR_LINE. " V.2

" V.2

DATA BEGIN OF ITCPO. " V.2

INCLUDE STRUCTURE ITCPO. " V.2

DATA END OF ITCPO. " V.2

* Temp Data

DATA: DATE_FLD_IN TYPE D. " V.2

DATA: NO_WK_CENTRE(1) TYPE C.

DATA: CUR_POS(30) TYPE C.

DATA: DAYTXT(9) TYPE C.

DATA: TMPDATE LIKE SY-DATUM.

DATA: TMPQTY LIKE AFKO-GAMNG.

DATA: TMPQTY2 LIKE AFKO-GAMNG.

DATA: TMPQTY3(7) TYPE P DECIMALS 3.

DATA: GTMPQTY LIKE AFKO-GAMNG.

DATA: GTMPQTY2 LIKE AFKO-GAMNG.

DATA: GTMPQTY3(7) TYPE P DECIMALS 3.

DATA: TMPCNV LIKE AFKO-GAMNG. " V.2

DATA: TMPCNV2 LIKE AFKO-GAMNG. " V.2

DATA: TMPCNV3(7) TYPE P DECIMALS 3. " V.2

DATA: GTMPCNV LIKE AFKO-GAMNG. " V.2

DATA: GTMPCNV2 LIKE AFKO-GAMNG. " V.2

DATA: GTMPCNV3(7) TYPE P DECIMALS 3. " V.2

DATA: ACTQTY LIKE AFKO-GAMNG.

DATA: ACTMNG LIKE MSEG-MENGE. " V.2

DATA: CNVQTY LIKE MSEG-MENGE. " V.2

DATA: CNVDFF(7) TYPE P DECIMALS 3. " V.2

DATA: DFFQTY(7) TYPE P DECIMALS 3.

DATA: COST1(7) TYPE P DECIMALS 2.

DATA: COST2(7) TYPE P DECIMALS 2.

DATA: COST3(7) TYPE P DECIMALS 2.

DATA: TCOST1(7) TYPE P DECIMALS 2.

DATA: TCOST2(7) TYPE P DECIMALS 2.

DATA: TCOST3(7) TYPE P DECIMALS 2.

DATA: TCENT(5) TYPE P DECIMALS 2.

DATA: PCENT(3) TYPE P DECIMALS 2.

DATA: DIFF TYPE P DECIMALS 3.

DATA: CT_PCENT(3) TYPE N.

DATA: TMPVALUE(50) TYPE C.

DATA: LINES(4) TYPE N.

DATA: FIRST(1) TYPE C.

DATA: FI_GTMPQTY(7) TYPE P DECIMALS 2.

DATA: FI_GTMPQTY2(7) TYPE P DECIMALS 2.

DATA: FI_GTMPQTY3(7) TYPE P DECIMALS 2.

DATA: COST(8) TYPE P DECIMALS 2.

DATA: PLANT LIKE T001W-NAME1. " V.2

DATA: UOM_ID(3) TYPE C VALUE 'TO '. " V.2

DATA: END_DATE LIKE SY-DATUM.

* MRC 6/2 , new variabls to output different headings

DATA: HEAD1(17) TYPE C.

DATA: HEAD2(17) TYPE C.

DATA: HEAD3(17) TYPE C.

DATA: OUTPUT_TEXT(30) TYPE C VALUE 'Controlling Area Invalid'.

DATA: V_WAERS LIKE T001-WAERS.

* Parms

SELECTION-SCREEN BEGIN OF LINE. " V.2

SELECTION-SCREEN COMMENT 20(40) TEXT-001. " V.2

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN SKIP 2. " V.2

*

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

MJAHR LIKE MSEG-MJAHR NO-DISPLAY.

SELECT-OPTIONS: PMAT FOR MARA-MATNR MEMORY ID MAT MATCHCODE

OBJECT MAT1.

SELECT-OPTIONS: ARBPL FOR CRHD-ARBPL MEMORY ID AGR MATCHCODE

OBJECT CRAM.

*

SELECTION-SCREEN SKIP 1. " V.2

SELECT-OPTIONS: WDATE FOR SY-DATUM OBLIGATORY MEMORY ID DTE. " V.2

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN POSITION 35.

PARAMETERS: WTEXT1(10) TYPE C MODIF ID WT1.

SELECTION-SCREEN POSITION 60.

PARAMETERS: WTEXT2(10) TYPE C MODIF ID WT2.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 1(33) TEXT-002. " V.2

PARAMETERS: WEEKS(2) TYPE N DEFAULT 0 MEMORY ID WKS. " V.2

SELECTION-SCREEN END OF LINE.

*

SELECTION-SCREEN SKIP 1. " V.2

SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 1(33) TEXT-003. " V.2

PARAMETERS: STEUS LIKE AFVC-STEUS DEFAULT 'PI01'.

SELECTION-SCREEN COMMENT 43(16) TEXT-004. " V.2

PARAMETERS: BESKZ LIKE PLAF-BESKZ MEMORY ID MBS DEFAULT 'E'.

SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN SKIP 1. " V.2

PARAMETERS: UOM LIKE T006A-MSEHI MEMORY ID UOM DEFAULT 'TO '. " V.2

SELECTION-SCREEN SKIP 1. " V.2

PARAMETERS: LAYSET(30) MEMORY ID ZLA DEFAULT 'Z_C_ZCOO54_L'

NO-DISPLAY. " V.2

SELECTION-SCREEN SKIP 1.

PARAMETERS: PKOKRS LIKE T001-BUKRS DEFAULT 'NUKL'.

SELECTION-SCREEN SKIP 1. " V.2

PARAMETERS: ARBPLBK AS CHECKBOX.

PARAMETERS: GTOTALS AS CHECKBOX.

PARAMETERS: FISCAL AS CHECKBOX.

PARAMETERS: OLDMAT AS CHECKBOX. " V.2

PARAMETERS: PDREP AS CHECKBOX. " V.2

PARAMETERS: PLAFREQ AS CHECKBOX. " V.2

PARAMETERS: PLACOMP AS CHECKBOX. " V.2

PARAMETERS: MATTXT AS CHECKBOX. " V.2

* Init.

INITIALIZATION.

GET PARAMETER ID 'UOM' FIELD UOM_ID. " V.2

GET PARAMETER ID 'WRK' FIELD WERKS.

MOVE SY-DATUM+0(4) TO MJAHR.

GET PARAMETER ID 'DTE' FIELD WDATE-LOW.

* Validate Inputs

AT SELECTION-SCREEN OUTPUT.

LOOP AT SCREEN.

IF SCREEN-GROUP1 = 'WT1'.

SCREEN-INPUT = '0'.

SCREEN-INVISIBLE = '1'.

MODIFY SCREEN.

ENDIF.

ENDLOOP.

IF NOT WDATE-LOW IS INITIAL.

IF WEEKS > 0. " V.2

WDATE-HIGH = ( WDATE-LOW + 7 * WEEKS ) - 1. " V.2

* WDATE-HIGH = END_DATE. " V.2

MODIFY WDATE INDEX 1. " V.2

ENDIF. " V.2

* MODIFY WDATE INDEX 1. " V.2

LOOP AT SCREEN.

IF SCREEN-GROUP1 = 'WT1'.

MOVE WDATE-LOW TO TMPDATE.

MOVE WDATE-HIGH TO END_DATE. " V.2

PERFORM GET_DAY USING TMPDATE DAYTXT.

MOVE DAYTXT TO WTEXT1.

SCREEN-INPUT = '0'.

SCREEN-INVISIBLE = '0'.

MODIFY SCREEN.

ENDIF.

ENDLOOP.

LOOP AT SCREEN.

IF SCREEN-GROUP1 = 'WT2'.

SCREEN-INPUT = '0'.

SCREEN-INVISIBLE = '1'.

MODIFY SCREEN.

ENDIF.

ENDLOOP.

IF NOT WDATE-HIGH IS INITIAL.

LOOP AT SCREEN.

IF SCREEN-GROUP1 = 'WT2'.

MOVE WDATE-HIGH TO TMPDATE.

PERFORM GET_DAY USING TMPDATE DAYTXT.

MOVE DAYTXT TO WTEXT2.

SCREEN-INPUT = '0'.

SCREEN-INVISIBLE = '0'.

MODIFY SCREEN.

ENDIF.

ENDLOOP.

ENDIF.

ENDIF. " V.2

* Validate Inputs

AT SELECTION-SCREEN.

SELECT SINGLE * FROM T001W WHERE WERKS = WERKS. " V.2

IF SY-SUBRC = 0. " V.2

MOVE T001W-NAME1 TO PLANT. " V.2

ENDIF. " V.2

* SELECT SINGLE WAERS

* FROM T001

* INTO V_WAERS

* WHERE BUKRS = PKOKRS.

* IF SY-SUBRC NE 0.

* MESSAGE E087 WITH OUTPUT_TEXT.

* endif.

* 16/10/02 PH - calendar call fails if no wdate-high,

* therefore copy low date into high if no high

if wdate-high is initial.

wdate-high = wdate-low.

modify wdate index 1.

endif.

* Main Select Processing.

START-OF-SELECTION.

*

IF ARBPL-LOW IS INITIAL.

IF ARBPL-HIGH IS INITIAL.

MOVE 'AAAAAAAA' TO ARBPL-LOW.

MOVE 'ZZZZZZZZ' TO ARBPL-HIGH.

MODIFY ARBPL INDEX 1. " V.2

ENDIF.

ENDIF.

IF NOT ( ARBPLBK IS INITIAL ).

CLEAR NO_WK_CENTRE.

ELSE.

MOVE 'X' TO NO_WK_CENTRE.

ENDIF.

IF PMAT-LOW IS INITIAL. " V.2

MOVE ' ' TO PMAT-LOW. " V.2

MOVE 'ZZZZZZZZZZZZZZZZZZ' TO PMAT-HIGH. " V.2

MODIFY PMAT INDEX 1. " V.2

ENDIF. " V.2

IF PMAT-HIGH IS INITIAL. " V.2

MOVE PMAT-LOW TO PMAT-HIGH. " V.2

MODIFY PMAT INDEX 1. " V.2

ENDIF. " V.2

** Set up Reporting calendar table " V.2

* CALL FUNCTION 'Z_C_PERIOD_WEEK_DAYNAME' " V.2

* EXPORTING " V.2

* DATE_FROM = WDATE-LOW " V.2

* DATE_TO = WDATE-HIGH " V.2

* TABLES " V.2

* CAL = CAL " V.2

* EXCEPTIONS " V.2

* DATE_INVALID = 01 " V.2

* T009_NOT_FOUND = 02 " V.2

* T009B_NOT_FOUND = 03. " V.2

* IF NOT SY-SUBRC = 00. " V.2

* MESSAGE E039. " V.2

* ENDIF. " V.2

" V.2

* Set Gui

SET PF-STATUS 'STD'.

* Get Data

IF STEUS IS INITIAL.

MOVE '%' TO STEUS.

ENDIF.

* trying to speed up program so select into table and then loop

SELECT *

into corresponding fields of table i_caufv

FROM CAUFV

WHERE WERKS = WERKS

AND PLNBEZ IN PMAT " V.2

AND GSTRP IN WDATE.

loop at i_caufv into wa_caufv.

CLEAR: makt, afpo, afvv, afvc.

* Get the order info (only one item per order currently)

SELECT single * FROM AFPO

WHERE AUFNR = WA_CAUFV-AUFNR.

* Get all phase data for the order

select afvc~aufpl afvc~vornr afvc~arbid afvv~ssavd

into (afvc-aufpl, afvc-vornr, afvc-arbid, afvv-ssavd)

from afvc join afvv

on afvc~aufpl = afvv~aufpl

and afvc~aplzl = afvv~aplzl

where afvc~aufpl = wa_caufv-aufpl

and afvc~steus like steus

and afvc~phflg = 'X'

order by afvc~aufpl afvc~vornr descending.

* Get the work centre info

SELECT SINGLE arbpl into crhd-arbpl

FROM CRHD

WHERE OBJTY = 'A'

AND OBJID = AFVC-ARBID

AND ARBPL IN ARBPL.

IF SY-SUBRC EQ 0.

MOVE-CORRESPONDING AFPO TO AFPO_SELECT.

MOVE CRHD-ARBPL TO AFPO_SELECT-ARBPL.

MOVE AFVV-SSAVD TO AFPO_SELECT-WDATE. "NS 10/00

PERFORM GET_DAY USING AFVV-SSAVD DAYTXT.

MOVE DAYTXT TO AFPO_SELECT-DAYTXT.

MOVE WA_CAUFV-GAMNG TO AFPO_SELECT-GAMNG.

MOVE WA_CAUFV-GMEIN TO AFPO_SELECT-GMEIN.

MOVE '2' TO AFPO_SELECT-ORDTYP. " V.2

* insert optional print fields in ZCOO5 " v.2

PERFORM OPT_FIELDS. " v.2

* Only want order once if not doing work centre breakdown

IF ARBPLBK IS INITIAL.

LOOP AT AFPO_SELECT

WHERE AUFNR EQ AFPO_SELECT-AUFNR.

ENDLOOP.

IF SY-SUBRC NE 0.

APPEND AFPO_SELECT.

ENDIF.

ELSE.

APPEND AFPO_SELECT.

ENDIF.

ENDIF.

ENDSELECT.

endloop.

* Get planned orders if required " V.2

CLEAR: PLAF, AFPO_SELECT.

IF PLAFREQ = 'X' OR PLACOMP = 'X'. " V.2

SELECT * FROM PLAF

WHERE PLWRK = WERKS

AND BESKZ = BESKZ

AND MATNR IN PMAT

AND PEDTR IN WDATE.

MOVE PLAF-MATNR TO: AFPO_SELECT-MATNR, AFPO-MATNR. " V.2

MOVE ' ' TO AFPO_SELECT-AUFNR. " V.2

* Get planning work centre " V.2

CLEAR MKAL. " V.2

select single * from mkal

where matnr = plaf-matnr

and werks = plaf-plwrk

and verid = plaf-verid

and mdv01 in arbpl.

IF SY-SUBRC = 0. " V.2

IF MKAL-MDV01 = SPACE.

MOVE ' PLANNED' TO AFPO_SELECT-ARBPL.

ELSE.

MOVE MKAL-MDV01 TO AFPO_SELECT-ARBPL. " V.2

ENDIF.

ELSE.

MOVE ' PLANNED' TO AFPO_SELECT-ARBPL. " V.2

ENDIF.

IF PLACOMP = 'X'. " Separate line for planned orders ?

MOVE '1' TO AFPO_SELECT-ORDTYP." V.2

ELSE.

MOVE '2' TO AFPO_SELECT-ORDTYP." V.2

ENDIF.

MOVE PLAF-PEDTR TO AFPO_SELECT-WDATE. " V.2

PERFORM GET_DAY USING PLAF-PEDTR DAYTXT. " V.2

MOVE DAYTXT TO AFPO_SELECT-DAYTXT. " V.2

MOVE PLAF-GSMNG TO AFPO_SELECT-GAMNG. " V.2

MOVE PLAF-MEINS TO AFPO_SELECT-GMEIN. " V.2

PERFORM OPT_FIELDS. " v.2

APPEND AFPO_SELECT. " V.2

ENDSELECT. " V.2

ENDIF. " V.2

END-OF-SELECTION.

* Check we found something.

DESCRIBE TABLE AFPO_SELECT LINES LINES.

IF LINES LT 1.

MESSAGE S022.

IF SY-CALLD IS INITIAL.

CASE SY-TCODE.

WHEN 'ZC54'.

LEAVE TO TRANSACTION SY-TCODE.

WHEN OTHERS.

LEAVE.

ENDCASE.

ELSE.

LEAVE.

ENDIF.

ENDIF.

* Build tables for each page of report.

SORT AFPO_SELECT BY WDATE ARBPL AUFNR.

* Build and Print Report " V.2

PERFORM PRODUCE_REPORT. " standard report " V.2

IF PDREP = 'X'. " V.2

PERFORM PERIOD_REPORT. " period summary print " V.2

ENDIF. " V.2

* Standard Include

INCLUDE ZSI0010.

* Top of Page

TOP-OF-PAGE.

WRITE: /1 '(ZC54) Production Planned vs Actual Report'.

SKIP.

* Act on user commands.

AT LINE-SELECTION.

GET CURSOR FIELD CUR_POS VALUE TMPVALUE.

IF CUR_POS = 'AFPO_SELECT-AUFNR'.

SET PARAMETER ID 'BR1' FIELD TMPVALUE.

CALL TRANSACTION 'COR3' AND SKIP FIRST SCREEN.

ENDIF.

IF CUR_POS = 'AFPO_SELECT-ARBPL'.

SET PARAMETER ID 'WRK' FIELD WERKS.

SET PARAMETER ID 'AGR' FIELD TMPVALUE.

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 'ZC54'.

LEAVE TO TRANSACTION SY-TCODE.

WHEN OTHERS.

LEAVE.

ENDCASE.

ELSE.

LEAVE.

ENDIF.

ENDCASE.

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

*& Form GET_DAY

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

FORM GET_DAY USING TMPDATE DAYTXT.

* CALL FUNCTION 'Z_S_CALCULATE_DAY'

* EXPORTING

* DATE = TMPDATE

* IMPORTING

* DAY = DAYTXT.

ENDFORM. " GET_DAY

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

*& Form PRODUCE_REPORT

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

FORM PRODUCE_REPORT.

IF FISCAL IS INITIAL.

HEAD1 = 'Planned Quantity'.

HEAD2 = 'Actual Quantity'.

HEAD3 = 'Diff Quantity'.

ELSE.

CONCATENATE 'Planned Value' V_WAERS INTO HEAD1 SEPARATED BY SPACE.

CONCATENATE 'Actual Value' V_WAERS INTO HEAD2 SEPARATED BY SPACE.

CONCATENATE 'Diff Value' V_WAERS INTO HEAD3 SEPARATED BY SPACE.

ENDIF.

CLEAR FIRST.

LOOP AT AFPO_SELECT.

IF NO_WK_CENTRE IS INITIAL.

ON CHANGE OF AFPO_SELECT-WDATE

OR AFPO_SELECT-ARBPL.

IF NOT ( FIRST IS INITIAL ).

clear: pcent.

perform calc_percent using tmpcnv tmpcnv2.

perform output_totals.

ENDIF.

MOVE 'X' TO FIRST.

NEW-PAGE.

CLEAR PCENT.

CLEAR CT_PCENT.

CLEAR: TMPQTY, TMPCNV. " V.2

CLEAR: TMPQTY2, TMPCNV2. " V.2

CLEAR: TMPQTY3, TMPCNV3. " V.2

CLEAR TCOST1.

CLEAR TCOST2.

CLEAR TCOST3.

FORMAT INTENSIFIED ON.

WRITE: /1 SY-ULINE(40).

IF NO_WK_CENTRE IS INITIAL.

WRITE: 50 SY-ULINE(31).

ENDIF.

WRITE: /1 SY-VLINE,

'Daily Report',

SY-VLINE,

AFPO_SELECT-DAYTXT INTENSIFIED OFF,

AFPO_SELECT-WDATE INTENSIFIED OFF,

40 SY-VLINE.

IF NO_WK_CENTRE IS INITIAL.

WRITE: 50 SY-VLINE,

'Work Centre',

SY-VLINE,

AFPO_SELECT-ARBPL INTENSIFIED OFF,

80 SY-VLINE.

ENDIF.

WRITE: /1 SY-ULINE(40).

IF NO_WK_CENTRE IS INITIAL.

WRITE: 50 SY-ULINE(31).

ENDIF.

SKIP.

WRITE: /1 SY-ULINE(132).

WRITE: /1 SY-VLINE,

'Material',

20 SY-VLINE,

'Description',

47 SY-VLINE,

'Order No',

62 SY-VLINE,

HEAD1,

83 SY-VLINE,

HEAD2,

104 SY-VLINE,

HEAD3,

122 SY-VLINE,

'Perf(%)',

132 SY-VLINE.

WRITE: /1 SY-ULINE(132).

FORMAT INTENSIFIED OFF.

ENDON.

ELSE.

ON CHANGE OF AFPO_SELECT-WDATE.

IF NOT ( FIRST IS INITIAL ).

clear: pcent.

perform calc_percent using tmpcnv tmpcnv2.

perform output_totals.

ENDIF.

MOVE 'X' TO FIRST.

NEW-PAGE.

CLEAR PCENT.

CLEAR CT_PCENT.

CLEAR: TMPQTY, TMPCNV.

CLEAR: TMPQTY2, TMPCNV2.

CLEAR: TMPQTY3, TMPCNV3.

CLEAR TCOST1.

CLEAR TCOST2.

CLEAR TCOST3.

FORMAT INTENSIFIED ON.

WRITE: /1 SY-ULINE(40).

IF NO_WK_CENTRE IS INITIAL.

WRITE: 50 SY-ULINE(31).

ENDIF.

WRITE: /1 SY-VLINE,

'Daily Report',

SY-VLINE,

AFPO_SELECT-DAYTXT INTENSIFIED OFF,

AFPO_SELECT-WDATE INTENSIFIED OFF,

40 SY-VLINE.

IF NO_WK_CENTRE IS INITIAL.

WRITE: 50 SY-VLINE,

'Work Centre',

SY-VLINE,

AFPO_SELECT-ARBPL INTENSIFIED OFF,

80 SY-VLINE.

ENDIF.

WRITE: /1 SY-ULINE(40).

IF NO_WK_CENTRE IS INITIAL.

WRITE: 50 SY-ULINE(31).

ENDIF.

SKIP.

WRITE: /1 SY-ULINE(132).

WRITE: /1 SY-VLINE,

'Material',

20 SY-VLINE,

'Description',

47 SY-VLINE,

'Order No',

62 SY-VLINE,

HEAD1,

83 SY-VLINE,

HEAD2,

104 SY-VLINE,

HEAD3,

122 SY-VLINE,

'Perf(%)',

132 SY-VLINE.

WRITE: /1 SY-ULINE(132).

FORMAT INTENSIFIED OFF.

ENDON.

ENDIF.

SELECT SINGLE * FROM MAKT

WHERE MATNR = AFPO_SELECT-MATNR

AND SPRAS = SY-LANGU.

CONDENSE MAKT-MAKTX.

PERFORM GET_ACTUAL_QTY USING ACTQTY CNVQTY. " V.2

IF FISCAL IS INITIAL.

WRITE: /1 SY-VLINE,

AFPO_SELECT-ZBISMT, " V.2

20 SY-VLINE,

MAKT-MAKTX+0(24),

SY-VLINE,

AFPO_SELECT-AUFNR,

SY-VLINE,

AFPO_SELECT-ZPLQTY, " V.2

83 SY-VLINE. " V.2

WRITE:

CNVQTY, " V.2

104 SY-VLINE. " V.2

WRITE:

CNVDFF, " V.2

122 SY-VLINE. " V.2

ELSE.

SELECT single * FROM MBEW

WHERE MATNR = AFPO_SELECT-MATNR

and bwkey = werks.

COST1 = ( MBEW-STPRS * AFPO_SELECT-GAMNG ) / MBEW-PEINH.

COST2 = ( MBEW-STPRS * ACTQTY ) / MBEW-PEINH.

COST3 = ( MBEW-STPRS * DFFQTY ) / MBEW-PEINH.

WRITE: /1 SY-VLINE,

AFPO_SELECT-ZBISMT, " V.2

20 SY-VLINE,

MAKT-MAKTX+0(24),

SY-VLINE,

AFPO_SELECT-AUFNR,

SY-VLINE,

67 COST1,

SY-VLINE.

WRITE: 88 COST2,

SY-VLINE.

WRITE: 106 COST3,

SY-VLINE.

ENDIF.

clear: pcent.

IF ACTQTY = 0.

MOVE 0 TO PCENT.

ELSE.

clear: pcent.

perform calc_percent using afpo_select-zplqty cnvqty.

ENDIF.

CT_PCENT = CT_PCENT + 1.

WRITE: PCENT,

SY-VLINE.

WRITE: 130 '%'.

WRITE: /1 SY-ULINE(132).

TMPQTY = TMPQTY + AFPO_SELECT-GAMNG.

TMPQTY2 = TMPQTY2 + ACTQTY.

TMPQTY3 = TMPQTY3 + DFFQTY.

TMPCNV = TMPCNV + AFPO_SELECT-ZPLQTY. " V.2

TMPCNV2 = TMPCNV2 + CNVQTY. " V.2

TMPCNV3 = TMPCNV3 + CNVDFF. " V.2

TCOST1 = TCOST1 + COST1.

TCOST2 = TCOST2 + COST2.

TCOST3 = TCOST3 + COST3.

IF NOT ( GTOTALS IS INITIAL ).

PERFORM GET_GRAND_TOTALS.

endif.

ENDLOOP.

clear: pcent.

perform calc_percent using tmpcnv tmpcnv2.

perform output_totals.

IF NOT ( GTOTALS IS INITIAL ).

perform calc_percent using gtmpcnv gtmpcnv2.

FORMAT INTENSIFIED ON.

NEW-PAGE.

WRITE: /62 SY-ULINE(71).

WRITE: /62 SY-VLINE,

HEAD1,

83 SY-VLINE,

HEAD2,

104 SY-VLINE,

HEAD3,

122 SY-VLINE,

'Perf(%)',

132 SY-VLINE.

WRITE: /1 SY-ULINE(132).

WRITE: /1 SY-VLINE,

'Grand Totals',

62 SY-VLINE,

GTMPCNV INTENSIFIED OFF, " V.2

83 SY-VLINE,

GTMPCNV2 INTENSIFIED OFF," V.2

104 SY-VLINE,

GTMPCNV3 INTENSIFIED OFF," V.2

122 SY-VLINE,

PCENT INTENSIFIED OFF,

130 '%',

132 SY-VLINE.

WRITE: /1 SY-ULINE(132).

IF NOT ( FISCAL IS INITIAL ).

WRITE: /1 SY-VLINE,

'Financial Totals',

62 SY-VLINE,

67 FI_GTMPQTY INTENSIFIED OFF,

83 SY-VLINE,

88 FI_GTMPQTY2 INTENSIFIED OFF,

104 SY-VLINE,

106 FI_GTMPQTY3 INTENSIFIED OFF,

122 SY-VLINE.

WRITE: /1 SY-ULINE(122).

ENDIF.

ENDIF.

ENDFORM. " PRODUCE_REPORT

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

*& Form GET_GRAND_TOTALS

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

FORM GET_GRAND_TOTALS.

GTMPQTY = GTMPQTY + AFPO_SELECT-GAMNG.

GTMPQTY2 = GTMPQTY2 + ACTQTY.

GTMPQTY3 = GTMPQTY3 + DFFQTY.

GTMPCNV = GTMPCNV + AFPO_SELECT-ZPLQTY. " V.2

GTMPCNV2 = GTMPCNV2 + CNVQTY. " V.2

GTMPCNV3 = GTMPCNV3 + CNVDFF. " V.2

IF NOT ( fiscal IS INITIAL ).

COST = ( MBEW-STPRS * AFPO_SELECT-GAMNG ) / MBEW-PEINH.

FI_GTMPQTY = FI_GTMPQTY + COST.

COST = ( MBEW-STPRS * ACTQTY ) / MBEW-PEINH.

FI_GTMPQTY2 = FI_GTMPQTY2 + COST.

COST = ( MBEW-STPRS * DFFQTY ) / MBEW-PEINH.

FI_GTMPQTY3 = FI_GTMPQTY3 + COST.

endif.

ENDFORM. " GET_GRAND_TOTALS

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

* FORM OPT_FIELDS *

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

* ........ Insert optional print fields into afpo_select *

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

FORM OPT_FIELDS. " V.2

* get material old number " V.2

IF OLDMAT = 'X'. " V.2

CLEAR MARA. " V.2

SELECT SINGLE * FROM MARA WHERE MATNR = AFPO-MATNR. " V.2

IF SY-SUBRC = 0 AND " V.2

NOT MARA-BISMT IS INITIAL " V.2

AND NOT MARA-BISMT = ' '. " V.2

AFPO_SELECT-ZBISMT = MARA-BISMT. " V.2

ELSE. " V.2

AFPO_SELECT-ZBISMT = AFPO-MATNR. " V.2

ENDIF. " V.2

ELSE. " V.2

AFPO_SELECT-ZBISMT = AFPO-MATNR. " V.2

ENDIF. " V.2

* insert week no. " V.2

MOVE AFPO_SELECT-WDATE TO DATE_FLD_IN. " V.2

CLEAR CAL. " V.2

READ TABLE CAL WITH KEY DATE_FLD_IN. " V.2

" V.2

MOVE CAL-ZYEAR TO AFPO_SELECT-ZYEAR. " V.2

MOVE CAL-ZWEEK TO AFPO_SELECT-ZWEEK. " V.2

MOVE CAL-ZPERIOD TO AFPO_SELECT-ZPERIOD. " V.2

MOVE AFPO_SELECT-MATNR TO AFPO_SELECT-ZMATNR. " V.2

MOVE PLANT TO AFPO_SELECT-ZPLANT. " V.2

MOVE AFPO_SELECT-WDATE TO AFPO_SELECT-ZDATE. " V.2

MOVE AFPO_SELECT-ARBPL TO AFPO_SELECT-ZARBPL. " V.2

MOVE AFPO_SELECT-AUFNR TO AFPO_SELECT-ZAUFNR. " V.2

MOVE UOM TO AFPO_SELECT-ZPLUOM. " V.2

MOVE UOM TO AFPO_SELECT-ZACUOM. " V.2

*Convert Planned Qty

* PERFORM MARM_CONVERT USING AFPO_SELECT-GAMNG AFPO_SELECT-ZPLQTY.

* Convert Actuals

PERFORM GET_ACTUAL_QTY USING ACTQTY AFPO_SELECT-ZACQTY.

MOVE AFPO_SELECT-ZPLUOM TO AFPO_SELECT-ZACUOM.

ENDFORM. " OPT_FIELDS V.2

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

* FORM GET_ACTUAL_QTY *

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

* ........Read MSEG and extract actual movement quantities *

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

FORM GET_ACTUAL_QTY USING ACTQTY CNVQTY.

CLEAR: ACTQTY, CNVQTY. " V.2

SELECT * FROM MSEG " V.2

WHERE AUFNR = AFPO_SELECT-AUFNR " V.2

AND MJAHR = AFPO_SELECT-ZYEAR " V.2

AND ( BWART = '101' OR BWART = '102' ) " V.2

AND MATNR = AFPO_SELECT-MATNR. " V.2

CASE MSEG-BWART. " V.2

WHEN '101'. " V.2

ACTQTY = ACTQTY + MSEG-MENGE. " V.2

WHEN '102'. " V.2

ACTQTY = ACTQTY - MSEG-MENGE. " V.2

ENDCASE. " V.2

ENDSELECT. " V.2

* Convert the quantity (only once to speed up the report)

PERFORM MARM_CONVERT USING actqty cnvqty.

CNVDFF = CNVQTY - AFPO_SELECT-ZPLQTY.

DFFQTY = ACTQTY - AFPO_SELECT-GAMNG.

ENDFORM. " V.2

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

* FORM MARM_CONVERT " V.2 *

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

* ........ Check MARM for Alternate UOMs *

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

FORM MARM_CONVERT USING QTY_IN QTY_OUT." V.2

* CALL FUNCTION 'Z_M_CONVERT_MATERIAL_UOM' " V.2

* EXPORTING

* MATNR = AFPO_SELECT-ZMATNR

* QTY_IN = QTY_IN

* UOM_IN = AFPO_SELECT-GMEIN

* UOM_OUT = AFPO_SELECT-ZPLUOM

* IMPORTING

* QTY_OUT = QTY_OUT

* EXCEPTIONS

* INVALID_UOM = 01

* NOCONV = 02.

*

* IF NOT SY-SUBRC = 0. " V.2

* MOVE QTY_IN TO QTY_OUT. " V.2

* MOVE '***' TO AFPO_SELECT-ZPLUOM. " V.2

* ENDIF. " V.2

* EXIT. " V.2

ENDFORM. " V.2

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

* FORM PERIOD_REPORT " V.2 *

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

* ........ Routine to print SAPscript form Z_C_ZCOO54 *

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

FORM PERIOD_REPORT. " V.2

" V.2

SORT AFPO_SELECT BY ZWERKS " V.2

ZYEAR " V.2

ZPERIOD " V.2

ZARBPL " V.2

ZBISMT " V.2

ORDTYP " V.2

ZWEEK. " V.2

" V.2

ITCPO-TDNEWID = 'X'. " V.2

ITCPO-TDIMMED = 'X'. " V.2

ITCPO-TDDELETE = 'X'. " V.2

" V.2

CALL FUNCTION 'OPEN_FORM' " V.2

EXPORTING " V.2

FORM = LAYSET " V.2

OPTIONS = ITCPO. " V.2

" V.2

* SAPSCRIPT print loop. " V.2

" V.2

LOOP AT AFPO_SELECT. " V.2

MOVE-CORRESPONDING AFPO_SELECT TO ZCOO5. " V.2

* First entry

IF OLD-FIRST = 'Y'. " V.2

OLD-FIRST = 'N'. " V.2

PERFORM NEW_PAGE. " V.2

ENDIF. " V.2

IF OLD-PERIOD = 0. " V.2

OLD-PERIOD = ZCOO5-ZPERIOD. " V.2

OLD-YEAR = ZCOO5-ZYEAR. " V.2

ENDIF.

* New Year

IF OLD-YEAR < ZCOO5-ZYEAR.

ZCOO5-ZPERIOD = 01.

ENDIF.

* New Period

IF NOT OLD-PERIOD = ZCOO5-ZPERIOD OR

NOT OLD-YEAR = ZCOO5-ZYEAR. " V.2

OLD-YEAR = ZCOO5-ZYEAR. " V.2

OLD-PERIOD = ZCOO5-ZPERIOD. " V.2

OLD-ARBPL = ' '. " V.2

OLD-BISMT = ' '. " V.2

PERFORM DO_SUBTOT. " V.2

PERFORM WRITE_LINE. " V.2

PERFORM DO_PERTOT. " V.2

PERFORM WRITE_SUBTOT. " V.2

PERFORM WRITE_TOTAL. " V.2

CALL FUNCTION 'END_FORM'. " V.2

PERFORM NEW_PAGE. " V.2

ENDIF. " V.2

* New Work Centre " V.2

IF OLD-ARBPL = ' '. " V.2

OLD-ARBPL = ZCOO5-ZARBPL. " V.2

ELSEIF NOT OLD-ARBPL = ZCOO5-ZARBPL. " V.2

OLD-ARBPL = ZCOO5-ZARBPL. " V.2

OLD-BISMT = ' '. " V.2

PERFORM DO_SUBTOT. " V.2

PERFORM WRITE_LINE. " V.2

PERFORM DO_PERTOT. " V.2

PERFORM WRITE_SUBTOT. " V.2

MOVE-CORRESPONDING CLEAR_LINE TO SUBTOT. " V.2

PERFORM NEW_ARBPL. " V.2

ENDIF. " V.2

* New Line Code

IF OLD-BISMT = ' '. " V.2

OLD-BISMT = ZCOO5-ZBISMT. " V.2

OLD-ORDTYP = AFPO_SELECT-ORDTYP.

ELSEIF NOT OLD-BISMT = ZCOO5-ZBISMT OR

NOT OLD-ORDTYP = AFPO_SELECT-ORDTYP. " V.2

OLD-ORDTYP = AFPO_SELECT-ORDTYP.

OLD-BISMT = ZCOO5-ZBISMT. " V.2

PERFORM DO_SUBTOT. " V.2

PERFORM WRITE_LINE. " V.2

ENDIF. " V.2

* item processing " V.2

IF MATTXT = 'X'.

* Want the material description

SELECT SINGLE maktx into makt-maktx

FROM MAKT

WHERE MATNR = afpo_select-matnr

AND SPRAS = SY-LANGU.

P_LINE-ZBISMT = makt-MAKTX.

ELSE.

P_LINE-ZBISMT = ZCOO5-ZBISMT. " V.2

ENDIF.

CASE ZCOO5-ZWEEK. " V.2

WHEN P_LINE-ZWEEK1. " V.2

P_LINE-ZPLQTY1 = P_LINE-ZPLQTY1 + ZCOO5-ZPLQTY. " V.2

P_LINE-ZACQTY1 = P_LINE-ZACQTY1 + ZCOO5-ZACQTY. " V.2

PERFORM CALC_PCNT USING

P_LINE-ZACQTY1 P_LINE-ZPLQTY1 P_LINE-ZPCT1.

" V.2

WHEN P_LINE-ZWEEK2. " V.2

P_LINE-ZPLQTY2 = P_LINE-ZPLQTY2 + ZCOO5-ZPLQTY. " V.2

P_LINE-ZACQTY2 = P_LINE-ZACQTY2 + ZCOO5-ZACQTY. " V.2

PERFORM CALC_PCNT USING

P_LINE-ZACQTY2 P_LINE-ZPLQTY2 P_LINE-ZPCT2.

" V.2

WHEN P_LINE-ZWEEK3. " V.2

P_LINE-ZPLQTY3 = P_LINE-ZPLQTY3 + ZCOO5-ZPLQTY. " V.2

P_LINE-ZACQTY3 = P_LINE-ZACQTY3 + ZCOO5-ZACQTY. " V.2

PERFORM CALC_PCNT USING

P_LINE-ZACQTY3 P_LINE-ZPLQTY3 P_LINE-ZPCT3.

" V.2

WHEN P_LINE-ZWEEK4. " V.2

P_LINE-ZPLQTY4 = P_LINE-ZPLQTY4 + ZCOO5-ZPLQTY. " V.2

P_LINE-ZACQTY4 = P_LINE-ZACQTY4 + ZCOO5-ZACQTY. " V.2

PERFORM CALC_PCNT USING

P_LINE-ZACQTY4 P_LINE-ZPLQTY4 P_LINE-ZPCT4.

" V.2

WHEN P_LINE-ZWEEK5. " V.2

P_LINE-ZPLQTY5 = P_LINE-ZPLQTY5 + ZCOO5-ZPLQTY. " V.2

P_LINE-ZACQTY5 = P_LINE-ZACQTY5 + ZCOO5-ZACQTY. " V.2

PERFORM CALC_PCNT USING

P_LINE-ZACQTY5 P_LINE-ZPLQTY5 P_LINE-ZPCT5.

" V.2

ENDCASE. " V.2

P_LINE-ZTOTALP = P_LINE-ZTOTALP + ZCOO5-ZPLQTY. " V.2

P_LINE-ZTOTALA = P_LINE-ZTOTALA + ZCOO5-ZACQTY. " V.2

PERFORM CALC_PCNT USING

P_LINE-ZTOTALA P_LINE-ZTOTALP P_LINE-ZPCTOT.

ENDLOOP. " V.2

* finish totals " V.2

PERFORM DO_SUBTOT. " V.2

PERFORM WRITE_LINE. " V.2

PERFORM DO_PERTOT. " V.2

PERFORM WRITE_SUBTOT. " V.2

PERFORM WRITE_TOTAL. " V.2

" V.2

CALL FUNCTION 'CLOSE_FORM'. " V.2

ENDFORM. " V.2

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

* FORM DO_SUBTOT *

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

* ........ Update sub-totals for work centre *

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

FORM DO_SUBTOT.

SUBTOT-ZBISMT = 'Sub Total'.

IF NOT P_LINE-ZPLUOM = '***'.

SUBTOT-ZPLQTY1 = SUBTOT-ZPLQTY1 + P_LINE-ZPLQTY1.

SUBTOT-ZACQTY1 = SUBTOT-ZACQTY1 + P_LINE-ZACQTY1.

PERFORM CALC_PCNT USING SUBTOT-ZACQTY1 SUBTOT-ZPLQTY1 SUBTOT-ZPCT1.

SUBTOT-ZPLQTY2 = SUBTOT-ZPLQTY2 + P_LINE-ZPLQTY2.

SUBTOT-ZACQTY2 = SUBTOT-ZACQTY2 + P_LINE-ZACQTY2.

PERFORM CALC_PCNT USING SUBTOT-ZACQTY2 SUBTOT-ZPLQTY2 SUBTOT-ZPCT2.

SUBTOT-ZPLQTY3 = SUBTOT-ZPLQTY3 + P_LINE-ZPLQTY3.

SUBTOT-ZACQTY3 = SUBTOT-ZACQTY3 + P_LINE-ZACQTY3.

PERFORM CALC_PCNT USING SUBTOT-ZACQTY3 SUBTOT-ZPLQTY3 SUBTOT-ZPCT3.

SUBTOT-ZPLQTY4 = SUBTOT-ZPLQTY4 + P_LINE-ZPLQTY4.

SUBTOT-ZACQTY4 = SUBTOT-ZACQTY4 + P_LINE-ZACQTY4.

PERFORM CALC_PCNT USING SUBTOT-ZACQTY4 SUBTOT-ZPLQTY4 SUBTOT-ZPCT4.

SUBTOT-ZPLQTY5 = SUBTOT-ZPLQTY5 + P_LINE-ZPLQTY5.

SUBTOT-ZACQTY5 = SUBTOT-ZACQTY5 + P_LINE-ZACQTY5.

PERFORM CALC_PCNT USING SUBTOT-ZACQTY5 SUBTOT-ZPLQTY5 SUBTOT-ZPCT5.

SUBTOT-ZTOTALP = SUBTOT-ZTOTALP + P_LINE-ZTOTALP.

SUBTOT-ZTOTALA = SUBTOT-ZTOTALA + P_LINE-ZTOTALA.

PERFORM CALC_PCNT USING SUBTOT-ZTOTALA SUBTOT-ZTOTALP SUBTOT-ZPCTOT.

ENDIF.

MOVE UOM TO SUBTOT-ZPLUOM.

ENDFORM.

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

* FORM DO_PERTOT " V.2

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

* ........ Update totals for period *

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

FORM DO_PERTOT.

PERTOT-ZBISMT = 'Total'.

PERTOT-ZPLQTY1 = PERTOT-ZPLQTY1 + SUBTOT-ZPLQTY1.

PERTOT-ZACQTY1 = PERTOT-ZACQTY1 + SUBTOT-ZACQTY1.

PERFORM CALC_PCNT USING PERTOT-ZACQTY1 PERTOT-ZPLQTY1 PERTOT-ZPCT1.

PERTOT-ZPLQTY2 = PERTOT-ZPLQTY2 + SUBTOT-ZPLQTY2.

PERTOT-ZACQTY2 = PERTOT-ZACQTY2 + SUBTOT-ZACQTY2.

PERFORM CALC_PCNT USING PERTOT-ZACQTY2 PERTOT-ZPLQTY2 PERTOT-ZPCT2.

PERTOT-ZPLQTY3 = PERTOT-ZPLQTY3 + SUBTOT-ZPLQTY3.

PERTOT-ZACQTY3 = PERTOT-ZACQTY3 + SUBTOT-ZACQTY3.

PERFORM CALC_PCNT USING PERTOT-ZACQTY3 PERTOT-ZPLQTY3 PERTOT-ZPCT3.

PERTOT-ZPLQTY4 = PERTOT-ZPLQTY4 + SUBTOT-ZPLQTY4.

PERTOT-ZACQTY4 = PERTOT-ZACQTY4 + SUBTOT-ZACQTY4.

PERFORM CALC_PCNT USING PERTOT-ZACQTY4 PERTOT-ZPLQTY4 PERTOT-ZPCT4.

PERTOT-ZPLQTY5 = PERTOT-ZPLQTY5 + SUBTOT-ZPLQTY5.

PERTOT-ZACQTY5 = PERTOT-ZACQTY5 + SUBTOT-ZACQTY5.

PERFORM CALC_PCNT USING PERTOT-ZACQTY5 PERTOT-ZPLQTY5 PERTOT-ZPCT5.

PERTOT-ZTOTALP = PERTOT-ZTOTALP + SUBTOT-ZTOTALP.

PERTOT-ZTOTALA = PERTOT-ZTOTALA + SUBTOT-ZTOTALA.

PERFORM CALC_PCNT USING PERTOT-ZTOTALA PERTOT-ZTOTALP PERTOT-ZPCTOT.

MOVE UOM TO PERTOT-ZPLUOM.

ENDFORM.

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

* FORM WRITE_LINE " V.2

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

* ........ *

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

FORM WRITE_LINE.

MOVE-CORRESPONDING P_LINE TO ZCOO7.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

WINDOW = 'MAIN'

ELEMENT = 'MAIN'.

MOVE-CORRESPONDING ZCOO5 TO P_LINE.

MOVE-CORRESPONDING CLEAR_LINE TO P_LINE.

ENDFORM.

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

* FORM NEW_PAGE " V.2

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

* ........ *

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

FORM NEW_PAGE.

MOVE-CORRESPONDING ZCOO5 TO P_LINE.

MOVE-CORRESPONDING CLEAR_LINE TO P_LINE.

MOVE-CORRESPONDING P_LINE TO ZCOO7.

CALL FUNCTION 'START_FORM'.

PERFORM NEW_ARBPL.

CLEAR: CAL, CALKEY.

MOVE-CORRESPONDING ZCOO5 TO CALKEY.

* get first week of order period

READ TABLE CAL WITH KEY ZDATE(4) = CALKEY-ZYEAR

ZYEAR = CALKEY-ZYEAR

ZPERIOD = CALKEY-ZPERIOD.

IF SY-SUBRC = 0.

MOVE CAL-ZWEEK TO CALKEY-ZWEEK.

ENDIF.

* get week nos of period

READ TABLE CAL WITH KEY ZYEAR = CALKEY-ZYEAR

ZPERIOD = CALKEY-ZPERIOD

ZWEEK = CALKEY-ZWEEK.

IF SY-SUBRC = 0.

P_LINE-ZWEEK1 = CAL-ZWEEK.

ELSE.

P_LINE-ZWEEK1 = CALKEY-ZWEEK.

ENDIF.

CALKEY-ZWEEK = CALKEY-ZWEEK + 1.

* week 2

READ TABLE CAL WITH KEY ZYEAR = CALKEY-ZYEAR

ZPERIOD = CALKEY-ZPERIOD

ZWEEK = CALKEY-ZWEEK.

IF SY-SUBRC = 0.

P_LINE-ZWEEK2 = CAL-ZWEEK.

ELSE.

P_LINE-ZWEEK2 = CALKEY-ZWEEK.

ENDIF.

CALKEY-ZWEEK = CALKEY-ZWEEK + 1.

* week 3

READ TABLE CAL WITH KEY ZYEAR = CALKEY-ZYEAR

ZPERIOD = CALKEY-ZPERIOD

ZWEEK = CALKEY-ZWEEK.

IF SY-SUBRC = 0.

P_LINE-ZWEEK3 = CAL-ZWEEK.

ELSE.

P_LINE-ZWEEK3 = CALKEY-ZWEEK.

ENDIF.

CALKEY-ZWEEK = CALKEY-ZWEEK + 1.

* week 4

READ TABLE CAL WITH KEY ZYEAR = CALKEY-ZYEAR

ZPERIOD = CALKEY-ZPERIOD

ZWEEK = CALKEY-ZWEEK.

IF SY-SUBRC = 0.

P_LINE-ZWEEK4 = CAL-ZWEEK.

ELSE.

P_LINE-ZWEEK4 = CALKEY-ZWEEK.

ENDIF.

CALKEY-ZWEEK = CALKEY-ZWEEK + 1.

* week 5

READ TABLE CAL WITH KEY ZYEAR = CALKEY-ZYEAR

ZPERIOD = CALKEY-ZPERIOD

ZWEEK = CALKEY-ZWEEK.

IF SY-SUBRC = 0.

P_LINE-ZWEEK5 = CAL-ZWEEK.

ELSE.

P_LINE-ZWEEK5 = CALKEY-ZWEEK.

ENDIF.

MOVE-CORRESPONDING P_LINE TO: SUBTOT, PERTOT.

ENDFORM.

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

* FORM NEW_ARBPL " V.2

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

* ........ *

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

FORM NEW_ARBPL.

MOVE-CORRESPONDING P_LINE TO ZCOO7.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

WINDOW = 'MAIN'

ELEMENT = 'ARBPL'.

ENDFORM.

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

* FORM WRITE_SUBTOT * " V.2

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

* ........ *

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

FORM WRITE_SUBTOT.

MOVE-CORRESPONDING SUBTOT TO P_LINE.

MOVE-CORRESPONDING P_LINE TO ZCOO7.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

WINDOW = 'MAIN'

ELEMENT = 'SUBTOT'.

MOVE-CORRESPONDING ZCOO5 TO P_LINE.

MOVE-CORRESPONDING CLEAR_LINE TO P_LINE.

ENDFORM.

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

* FORM WRITE_TOTAL * " V.2

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

* ........ *

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

FORM WRITE_TOTAL.

MOVE-CORRESPONDING PERTOT TO P_LINE.

MOVE-CORRESPONDING P_LINE TO ZCOO7.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

WINDOW = 'TOTAL'

ELEMENT = 'TOTAL'.

MOVE-CORRESPONDING ZCOO5 TO P_LINE.

MOVE-CORRESPONDING CLEAR_LINE TO P_LINE.

ENDFORM.

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

* FORM CALC_PCNT *

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

* ........ *

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

FORM CALC_PCNT USING NUM DENOM PCNT.

* Change calculation for give absolute performance % 09/99 NS

IF NOT DENOM = 0.

DIFF = ABS( DENOM - NUM ).

PCNT = 100 - 100 * DIFF / DENOM.

ELSE.

PCNT = 0.

ENDIF.

ENDFORM.

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

*& Form CALC_PERCENT

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

* text

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

* -->P_AFPO_SELECT_ZPLQTY text

* -->P_CNVQTY text

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

FORM CALC_PERCENT USING P_PLQTY

P_ACTQTY.

* Change calculation to make it the same as ZCP0203. This is an absolute

* performance percentage 09/99 NS

* Only do calc if actuals reported

IF p_actqty = 0.

PCENT = 0.

ELSE.

DIFF = ABS( p_plqty - p_actqty ).

tcent = 100 - 100 * DIFF / p_plqty.

* Added back in cos of dumps NS 07/00

if tcent gt '999.99'.

move '999.99' to pcent.

elseif tcent lt '-999.99'. "NS 10/00

move '-999.99' to pcent.

else.

move tcent to pcent.

endif.

ENDIF.

ENDFORM. " CALC_PERCENT

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

*& Form OUTPUT_TOTALS

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

* text

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

* --> p1 text

* <-- p2 text

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

FORM OUTPUT_TOTALS.

IF FISCAL IS INITIAL.

WRITE: /1 SY-VLINE,

'Totals',

62 SY-VLINE,

TMPCNV,

83 SY-VLINE,

TMPCNV2,

104 SY-VLINE,

TMPCNV3,

122 SY-VLINE,

PCENT,

130 '%',

132 SY-VLINE.

ELSE.

WRITE: /1 SY-VLINE,

'Totals',

62 SY-VLINE,

67 TCOST1,

83 SY-VLINE,

88 TCOST2,

104 SY-VLINE,

106 TCOST3,

122 SY-VLINE,

PCENT,

130 '%',

132 SY-VLINE.

ENDIF.

WRITE: /1 SY-ULINE(132).

ENDFORM. " OUTPUT_TOTALS