|
工單差異分析系統化是有我們公司經管部提出來的Case,也是我今年做的最複雜的一個Case,雖然只是一張報表,但是涉及的數據和表以及計算方式非常複雜。
雖然現在還沒有完全的完工,但是為了發帖,我只能把它先當話題了!
1.SAP開發介面
2.代碼(還沒有完成)
REPORT ZRCO_NSG_0094 Line-size 80 line-count 64
no standard page heading .
************************************************************************
* Program ID: *
* Program Description: ZS Production order costs analysis *
* Programmer Name: Chunsheng *
* Create Date: 2010/07/13 *
************************************************************************
*----------------------------------------------------------------------*
* TABLES *
*----------------------------------------------------------------------*
TABLES: ZTMMNG_ZS001,
AFKO,
RESB,
MARA,
MAKT,
CAUFV,
COSS,
KEKO,
CKIS.
TABLES: T001, T001W, MBEW, MARC.
TABLES: ZCONSGS04.
*----------------------------------------------------------------------*
* INTERNAL TABLE DEFINITION *
*----------------------------------------------------------------------*
DATA: BEGIN OF itab1 OCCURS 100,
aufnr like RESB-aufnr,"工單
PLNBEZ like afko-PLNBEZ,"機種
GAMNG like CAUFV-GAMNG,"工單套數/投入數
IGMNG LIKE CAUFV-IGMNG,"入庫數量
GASMG LIKE CAUFV-GASMG,"報廢數量
PMCOST LIKE RESB-ENWRT VALUE 0,"計劃材料成本
ACOST LIKE COSS-WOG001 VALUE 0,"實際投入成本
AMCOST LIKE RESB-ENWRT VALUE 0,"實際投入材料成本
ALCOST LIKE COSS-WOG001 VALUE 0,"實際投入工費成本
ZCOST LIKE CKIS-WRTFW_KPF VALUE 0,"產出成本
ZUCOST LIKE CKIS-WRTFW_KPF VALUE 0,"產出成本單價
ZMCOST LIKE CKIS-WRTFW_KFX VALUE 0,"產出材料成本
ZLCOST LIKE CKIS-WRTFW_KFX VALUE 0,"產出工費成本
VLCOST LIKE CKIS-WRTFW_KFX VALUE 0,"工費差**
VCOST LIKE CKIS-WRTFW_KPF VALUE 0,"VARIANCE
VMCOST LIKE CKIS-WRTFW_KFX VALUE 0,"材料量差
MATVRC LIKE RESB-BDMNG VALUE 0,"料少領
SEMISCP LIKE CKIS-WRTFW_KFX VALUE 0,"半成品報廢
FSCP LIKE CKIS-WRTFW_KFX VALUE 0,"成品報廢
MATWST LIKE CKIS-WRTFW_KFX VALUE 0,"材料耗損
ZSLCOST LIKE COSS-WOG001 VALUE 0,
END OF itab1.
DATA: BEGIN OF itab2 OCCURS 100,
aufnr like RESB-aufnr,"工單
MATNR LIKE RESB-MATNR, "物料號碼
BDMNG LIKE RESB-BDMNG,"需求數量
GPREIS LIKE RESB-GPREIS,"計劃成本單價
PEINH LIKE RESB-PEINH,"計劃成本計價數量
ENWRT LIKE RESB-ENWRT,"實際成本
SLCOST LIKE COSS-WOG001 VALUE 0, "該工單半成品工費成本
END OF itab2.
DATA: BEGIN OF ITAB3 OCCURS 100,
AUFNR LIKE RESB-AUFNR,
MATNR LIKE RESB-MATNR,
ZCORO LIKE ZCONSGS04-ZCOOH,
END OF ITAB3.
DATA: WKWAERS LIKE T001-WAERS.
DATA: BEGIN OF ITAB_MBEW OCCURS 1.
INCLUDE STRUCTURE MBEW.
DATA END OF ITAB_MBEW.
DATA: WKKADKY1 LIKE KEKO-KADKY, "PREVIOUS PERIOD OF ASSIGN PERIOD
WKKADKY2 LIKE KEKO-KADKY. "ASSIGN PERIOD
DATA: BEGIN OF ITAB_ZCONSGS04 OCCURS 1.
INCLUDE STRUCTURE ZCONSGS04.
DATA: YCORO LIKE ZCONSGS04-YCOOH.
DATA: ZCORO LIKE ZCONSGS04-ZCOOH.
DATA: ZCORO_P LIKE ZCONSGS04-ZCOOH_P.
DATA END OF ITAB_ZCONSGS04.
DATA: WKLSTAR LIKE CKIS-LSTAR VALUE 'RO'.
DATA: ZZCOST LIKE ZCONSGS04-ZCOOH.
data: begin of itab_coss occurs 1.
include structure coss.
data end of itab_coss.
data: begin of itab_afko occurs 1,
aufnr like afko-aufnr,
end of itab_afko.
DATA: BEGIN OF ITAB_ZCOST OCCURS 100,
PLNBEZ LIKE KEKO-MATNR,
LOSGR LIKE KEKO-LOSGR VALUE 1,
Z_COST LIKE CKIS-WRTFW_KPF VALUE 0,
ZMC_COST LIKE CKIS-WRTFW_KFX VALUE 0,
END OF ITAB_ZCOST.
data: begin of itab_KEKO occurs 1.
include structure KEKO.
data end of itab_KEKO.
data: begin of itab_CKIS occurs 1.
include structure CKIS.
data end of itab_CKIS.
Ranges: R_objnr for coss-objnr.
data: wkpono like afpo-aufnr.
*----------------------------------------------------------------------*
* SELECTION-SCREEN *
*----------------------------------------------------------------------*
selection-screen begin of block B1 with frame title text-b01.
parameters : wpbukrs like t001-bukrs default 'CNZS' obligatory.
parameters: werks1 like caufv-werks default 'ZS10' obligatory.
parameters : c_year like mbewh-lfgja obligatory DEFAULT SY-DATUM(4).
parameters : c_mon like mbewh-lfmon obligatory DEFAULT SY-DATUM+4(2).
select-options: matnr1 for mara-matnr.
select-options: AUFNR1 for AFKO-AUFNR.
selection-screen end of block B1.
selection-screen begin of block b2 with frame title text-b02.
parameters: alv_def like disvariant-variant.
selection-screen end of block b2.
******* ALV DECLARATION
include rm07alvi.
data: fc_alv type slis_fieldcat_alv occurs 10 with header line.
************************************************************************
* INITIALIZATION *
************************************************************************
INITIALIZATION.
PERFORM INITIAL_PARAMETER.
*----------------------------------------------------------------------*
* START OF SELECTION *
*----------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM FRM_GET_DATA .
PERFORM FRM_WRITE_DATA .
************************************************************************
* FORM: INITIAL_PARAMETER *
* FUNCTION: *
************************************************************************
FORM INITIAL_PARAMETER.
* c_year = SY-DATUM+0(04).
* c_mon = SY-DATUM+4(02).
* IF c_mon = 12.
* c_year = c_year + 1.
* c_mon = 1.
* ELSE.
* c_mon = c_mon + 1.
* ENDIF.
ENDFORM.
*----------------------------------------------------------------------*
* FORM FRM_GET_DATA *
*----------------------------------------------------------------------*
FORM FRM_GET_DATA.
DATA: TEMPMO LIKE RESB-AUFNR,
SLEN TYPE I.
CLEAR ITAB1.
REFRESH ITAB1.
DATA: WKVAL1 LIKE COSS-WOG001.
DATA: WKVAL2 LIKE COSS-WOG001.
SELECT A~AUFNR A~PLNBEZ C~GAMNG C~IGMNG C~GASMG
FROM AFKO AS A INNER JOIN CAUFV AS C
ON A~AUFNR = C~AUFNR
APPENDING TABLE ITAB1
WHERE A~PLNBEZ IN MATNR1
AND A~AUFNR IN AUFNR1
AND C~WERKS = WERKS1
AND C~BUKRS = WPBUKRS.
SORT ITAB1 BY AUFNR.
LOOP AT ITAB1.
MOVE-CORRESPONDING ITAB1 TO ITAB_ZCOST.
APPEND ITAB_ZCOST.
SELECT AUFNR MATNR BDMNG GPREIS PEINH ENWRT FROM RESB
APPENDING TABLE ITAB2
WHERE AUFNR = ITAB1-AUFNR.
ENDLOOP.
DELETE ADJACENT DUPLICATES FROM ITAB_ZCOST.
PERFORM GET_ZCOST. "GET 產出成本要素
LOOP AT ITAB_ZCOST.
READ TABLE ITAB1 WITH KEY PLNBEZ = ITAB_ZCOST-PLNBEZ.
IF SY-SUBRC = 0.
ITAB1-ZUCOST = ITAB_ZCOST-Z_COST / ITAB_ZCOST-LOSGR. "GET產出成本單價
ITAB1-ZCOST = ITAB1-ZUCOST * ITAB1-IGMNG. "GET 產出成本
ITAB1-ZMCOST = ( ITAB_ZCOST-Z_COST - ITAB_ZCOST-ZMC_COST ) /
ITAB_ZCOST-LOSGR * ITAB1-IGMNG. "GET 產出材料成本
MODIFY ITAB1 INDEX SY-TABIX.
ENDIF.
ENDLOOP.
PERFORM READ_COSS. "產獲得內表ITAB_COSS
SORT ITAB_COSS BY OBJNR.
LOOP AT ITAB_COSS.
**( Price Variance )
WKVAL1 = 0.
IF ITAB_COSS-WRTTP = '04'
AND ITAB_COSS-VRGNG = 'RKLN'.
PERFORM GET_LABOR_VALUE USING WKVAL1 CHANGING WKVAL1.
IF WPBUKRS = 'TWHH'.
WKVAL1 = WKVAL1 * 100.
ENDIF.
IF ITAB_COSS-BEKNZ = 'H'.
WKVAL1 = WKVAL1 * -1.
ENDIF.
ENDIF.
WKVAL2 = 0.
IF ITAB_COSS-WRTTP = '04'
AND ITAB_COSS-VRGNG = 'RKL'.
PERFORM GET_LABOR_VALUE USING WKVAL2 CHANGING WKVAL2.
IF WPBUKRS = 'TWHH'.
WKVAL2 = WKVAL2 * 100.
ENDIF.
IF ITAB_COSS-BEKNZ = 'H'.
WKVAL2 = WKVAL2 * -1.
ENDIF.
ENDIF.
ENDLOOP.
PERFORM GET_SLCOST. "獲取半成品工費成本
LOOP AT ITAB3.
ENDLOOP.
LOOP AT ITAB2.
READ TABLE ITAB1 WITH KEY AUFNR = ITAB2-AUFNR.
IF SY-SUBRC = 0.
IF ITAB2-PEINH <> 0.
ITAB1-PMCOST = ITAB1-PMCOST + ITAB2-BDMNG * ITAB2-GPREIS / ITAB2-PEINH.
ENDIF.
ITAB1-AMCOST = ITAB1-AMCOST + ITAB2-ENWRT - ITAB2-SLCOST.
ITAB1-ZSLCOST = ITAB1-ZSLCOST + ITAB2-SLCOST.
MODIFY ITAB1 INDEX SY-TABIX.
ENDIF.
ENDLOOP.
LOOP AT ITAB1.
ITAB1-ACOST = ITAB1-AMCOST + ITAB1-ALCOST.
ITAB1-ZLCOST = ITAB1-ZCOST - ITAB1-ZMCOST.
ITAB1-VLCOST = ITAB1-ALCOST - ITAB1-ZLCOST.
ITAB1-VCOST = ITAB1-ACOST - ITAB1-ZCOST.
ITAB1-VMCOST = ITAB1-AMCOST - ITAB1-ZMCOST.
ITAB1-MATVRC = ITAB1-PMCOST - ITAB1-AMCOST.
ITAB1-FSCP = ITAB1-GASMG * ITAB1-ZUCOST.
ITAB1-MATWST = ITAB1-VMCOST - ITAB1-MATVRC - ITAB1-FSCP.
MODIFY ITAB1.
ENDLOOP.
ENDFORM.
*----------------------------------------------------------------------*
* FORM GET_SLCOST *
*----------------------------------------------------------------------*
FORM GET_SLCOST.
DATA: WLZPERC LIKE ZCONSGS04-STPRS.
DATA: WLSTATUS(01) TYPE C.
DATA: WLPRCTR LIKE MARC-PRCTR,
WLNCOST LIKE MARC-NCOST.
LOOP AT ITAB2.
REFRESH: ITAB_MBEW.
SELECT MATNR BWKEY BWTAR LBKUM SALK3 VPRSV VERPR STPRS PEINH BWTTY
KALN1
FROM MBEW
APPENDING TABLE ITAB_MBEW
WHERE MATNR EQ ITAB2-MATNR
AND BWKEY = werks1
AND BWTAR = SPACE.
SORT ITAB_MBEW BY MATNR.
LOOP AT ITAB_MBEW.
CLEAR: WLPRCTR, WLNCOST.
SELECT SINGLE PRCTR NCOST FROM MARC
INTO (WLPRCTR, WLNCOST)
WHERE MATNR = ITAB_MBEW-MATNR
AND WERKS = ITAB_MBEW-BWKEY.
IF WLNCOST = 'X'.
CONTINUE.
ENDIF.
***** READ COST ESTIMATE DATA
SELECT SINGLE * FROM KEKO
WHERE BZOBJ = '0'
AND KALNR = ITAB_MBEW-KALN1
AND KALKA = '01'
AND KADKY = WKKADKY2
AND TVERS = '01'
AND BWVAR = '001'
AND KKZMA = SPACE
AND MATNR = ITAB_MBEW-MATNR
AND BWKEY = ITAB_MBEW-BWKEY.
***** DO NOT DO COST ESTIMATE BY VALUATION TYPE
IF SY-SUBRC <> 0.
CONTINUE.
ENDIF.
IF KEKO-FEH_STA = 'KA' OR KEKO-FEH_STA = 'VO' OR
KEKO-FEH_STA = 'FR'.
WLSTATUS = 'X'.
ENDIF.
CLEAR: ITAB_ZCONSGS04.
MOVE-CORRESPONDING ITAB_MBEW TO ITAB_ZCONSGS04.
ITAB_ZCONSGS04-BWTAR = KEKO-BWTAR.
IF ITAB_MBEW-VPRSV = 'V'.
ITAB_ZCONSGS04-STPRS = ITAB_MBEW-VERPR.
ENDIF.
ITAB_ZCONSGS04-FEH_STA = KEKO-FEH_STA.
ITAB_ZCONSGS04-PRCTR = WLPRCTR.
***** CALCULATE COST - ASSIGN PERIOD
IF WLSTATUS = 'X'.
PERFORM CAL_ASSIGN_PERIOD_COST.
ENDIF.
ITAB_ZCONSGS04-WAERS = WKWAERS.
APPEND ITAB_ZCONSGS04.
ENDLOOP.
ENDLOOP.
LOOP AT ITAB2.
READ TABLE ITAB_ZCONSGS04 WITH KEY MATNR = ITAB2-MATNR.
ITAB2-SLCOST = ITAB_ZCONSGS04-ZCOOH.
ENDLOOP.
ENDFORM.
*----------------------------------------------------------------------*
* FORM CAL_ASSIGN_PERIOD_COST *
*----------------------------------------------------------------------*
FORM CAL_ASSIGN_PERIOD_COST.
PERFORM READ_CKIS.
LOOP AT ITAB_CKIS.
CASE ITAB_CKIS-TYPPS.
WHEN 'M' OR 'I'.
ITAB_ZCONSGS04-ZCORM = ITAB_ZCONSGS04-ZCORM + ITAB_CKIS-WRTFW_KPF -
ITAB_CKIS-WRTFW_KFX.
ITAB_ZCONSGS04-ZCOOH = ITAB_ZCONSGS04-ZCOOH + ITAB_CKIS-WRTFW_KFX.
WHEN 'E'.
IF ITAB_CKIS-LSTAR = WKLSTAR.
ITAB_ZCONSGS04-ZCORO = ITAB_ZCONSGS04-ZCORO
+ ITAB_CKIS-WRTFW_KFX.
ELSE.
ITAB_ZCONSGS04-ZCOOH = ITAB_ZCONSGS04-ZCOOH +
ITAB_CKIS-WRTFW_KFX.
ENDIF.
WHEN OTHERS.
ITAB_ZCONSGS04-ZCOOH = ITAB_ZCONSGS04-ZCOOH +
ITAB_CKIS-WRTFW_KPF.
ENDCASE.
ENDLOOP.
ENDFORM.
*----------------------------------------------------------------------*
* FORM READ_CKIS *
*----------------------------------------------------------------------*
FORM READ_CKIS.
REFRESH: ITAB_CKIS.
SELECT LEDNR BZOBJ KALNR KALKA KADKY TVERS BWVAR KKZMA POSNR TYPPS
KSTAR WERKS MATNR WRTFW_KPF WRTFW_KFX MENGE MEEHT LSTAR
ARBID KOSTL
FROM CKIS
APPENDING TABLE ITAB_CKIS
WHERE LEDNR = '00'
AND BZOBJ = KEKO-BZOBJ
AND KALNR = KEKO-KALNR
AND KALKA = KEKO-KALKA
AND KADKY = KEKO-KADKY
AND TVERS = KEKO-TVERS
AND BWVAR = KEKO-BWVAR
AND KKZMA = KEKO-KKZMA.
ENDFORM.
*----------------------------------------------------------------------*
* FORM GET_ZCOST *
*----------------------------------------------------------------------*
FORM GET_ZCOST. "GET 產出成本
DATA: COST_DAT LIKE SY-DATUM.
DATA: C_DAY(2).
DATA: TLOSGR LIKE KEKO-LOSGR,
TLAB_COST LIKE CKIS-WRTFW_KPF,
TMC_COST LIKE CKIS-WRTFW_KFX,
TKALNR LIKE KEKO-KALNR,
TTVERS LIKE KEKO-TVERS.
C_DAY = '01'.
CONCATENATE C_YEAR C_MON C_DAY INTO COST_DAT.
LOOP AT ITAB_ZCOST.
TKALNR = ' '.
TTVERS = ' '.
TLOSGR = '1'.
SELECT SINGLE KALNR TVERS LOSGR INTO (TKALNR, TTVERS, TLOSGR)
FROM KEKO
WHERE KADKY = COST_DAT
AND MATNR = ITAB_ZCOST-PLNBEZ
AND WERKS = WERKS1.
SELECT SUM( WRTFW_KPF ) SUM( WRTFW_KFX ) INTO (TLAB_COST, TMC_COST)
FROM CKIS
WHERE TVERS = TTVERS
AND KADKY = COST_DAT
AND KALNR = TKALNR.
IF SY-SUBRC = 0.
ITAB_ZCOST-Z_COST = TLAB_COST.
ITAB_ZCOST-ZMC_COST = TMC_COST.
ITAB_ZCOST-LOSGR = TLOSGR.
ELSE.
ITAB_ZCOST-Z_COST = 0.
ITAB_ZCOST-ZMC_COST = 0.
ITAB_ZCOST-LOSGR = 1.
ENDIF.
MODIFY ITAB_ZCOST.
ENDLOOP.
ENDFORM.
*----------------------------------------------------------------------*
* FORM READ_COSS *
*----------------------------------------------------------------------*
FORM READ_COSS.
DATA: WLOBJNR LIKE COSP-OBJNR. "物料號碼
PERFORM READ_AFKO.
REFRESH: R_OBJNR.
R_OBJNR-SIGN = 'I'.
R_OBJNR-OPTION = 'EQ'.
LOOP AT ITAB_AFKO.
CONCATENATE 'OR' ITAB_AFKO-AUFNR INTO WLOBJNR.
R_OBJNR-LOW = WLOBJNR.
APPEND R_OBJNR.
ENDLOOP.
REFRESH: ITAB_COSS.
SELECT *
FROM COSS
APPENDING TABLE ITAB_COSS
WHERE OBJNR IN R_OBJNR
AND WRTTP IN ('01','04')
AND VERSN = '000'
AND LEDNR = '00'
AND VRGNG IN ('RKL','RKLN','KPPS').
LOOP AT ITAB_COSS.
IF ITAB_COSS-USPOB+16(2) ='RO'.
DELETE ITAB_COSS.
CONTINUE.
ENDIF.
CLEAR: WKPONO.
MOVE ITAB_COSS-OBJNR+2(12) TO WKPONO.
IF WKPONO IN AUFNR1.
ELSE.
DELETE ITAB_COSS.
CONTINUE.
ENDIF.
ENDLOOP.
ENDFORM.
*----------------------------------------------------------------------*
* FORM READ_AFKO *
*----------------------------------------------------------------------*
FORM READ_AFKO.
REFRESH: ITAB_AFKO.
SELECT A~AUFNR FROM AFKO AS A INNER JOIN MARC AS B
ON A~PLNBEZ = B~MATNR
APPENDING TABLE ITAB_AFKO
WHERE A~PLNBEZ IN MATNR1
AND A~AUFNR IN AUFNR1
AND B~WERKS = WERKS1.
ENDFORM.
*----------------------------------------------------------------------*
* FORM GET_LABOR_VALUE *
*----------------------------------------------------------------------*
FORM GET_LABOR_VALUE USING WKVALX CHANGING WKVALY. "獲取工費成本
WKVALX = 0.
WKVALY = 0.
IF ITAB_COSS-GJAHR = C_YEAR.
IF C_MON = 01.
WKVALX = ITAB_COSS-WOG001.
ENDIF.
IF C_MON = 02.
WKVALX = ITAB_COSS-WOG001
+ ITAB_COSS-WOG002.
ENDIF.
IF C_MON = 03.
WKVALX = ITAB_COSS-WOG001
+ ITAB_COSS-WOG002
+ ITAB_COSS-WOG003.
ENDIF.
IF C_MON = 04.
WKVALX = ITAB_COSS-WOG001
+ ITAB_COSS-WOG002
+ ITAB_COSS-WOG003
+ ITAB_COSS-WOG004.
ENDIF.
IF C_MON = 05.
WKVALX = ITAB_COSS-WOG001
+ ITAB_COSS-WOG002
+ ITAB_COSS-WOG003
+ ITAB_COSS-WOG004
+ ITAB_COSS-WOG005.
ENDIF.
IF C_MON = 06.
WKVALX = ITAB_COSS-WOG001
+ ITAB_COSS-WOG002
+ ITAB_COSS-WOG003
+ ITAB_COSS-WOG004
+ ITAB_COSS-WOG005
+ ITAB_COSS-WOG006.
ENDIF.
IF C_MON = 07.
WKVALX = ITAB_COSS-WOG001
+ ITAB_COSS-WOG002
+ ITAB_COSS-WOG003
+ ITAB_COSS-WOG004
+ ITAB_COSS-WOG005
+ ITAB_COSS-WOG006
+ ITAB_COSS-WOG007.
ENDIF.
IF C_MON = 08.
WKVALX = ITAB_COSS-WOG001
+ ITAB_COSS-WOG002
+ ITAB_COSS-WOG003
+ ITAB_COSS-WOG004
+ ITAB_COSS-WOG005
+ ITAB_COSS-WOG006
+ ITAB_COSS-WOG007
+ ITAB_COSS-WOG008.
ENDIF.
IF C_MON = 09.
WKVALX = ITAB_COSS-WOG001
+ ITAB_COSS-WOG002
+ ITAB_COSS-WOG003
+ ITAB_COSS-WOG004
+ ITAB_COSS-WOG005
+ ITAB_COSS-WOG006
+ ITAB_COSS-WOG007
+ ITAB_COSS-WOG008
+ ITAB_COSS-WOG009.
ENDIF.
IF C_MON = 10.
WKVALX = ITAB_COSS-WOG001
+ ITAB_COSS-WOG002
+ ITAB_COSS-WOG003
+ ITAB_COSS-WOG004
+ ITAB_COSS-WOG005
+ ITAB_COSS-WOG006
+ ITAB_COSS-WOG007
+ ITAB_COSS-WOG008
+ ITAB_COSS-WOG009
+ ITAB_COSS-WOG010.
ENDIF.
IF C_MON = 11.
WKVALX = ITAB_COSS-WOG001
+ ITAB_COSS-WOG002
+ ITAB_COSS-WOG003
+ ITAB_COSS-WOG004
+ ITAB_COSS-WOG005
+ ITAB_COSS-WOG006
+ ITAB_COSS-WOG007
+ ITAB_COSS-WOG008
+ ITAB_COSS-WOG009
+ ITAB_COSS-WOG010
+ ITAB_COSS-WOG011.
ENDIF.
IF C_MON = 12.
WKVALX = ITAB_COSS-WOG001
+ ITAB_COSS-WOG002
+ ITAB_COSS-WOG003
+ ITAB_COSS-WOG004
+ ITAB_COSS-WOG005
+ ITAB_COSS-WOG006
+ ITAB_COSS-WOG007
+ ITAB_COSS-WOG008
+ ITAB_COSS-WOG009
+ ITAB_COSS-WOG010
+ ITAB_COSS-WOG011
+ ITAB_COSS-WOG012.
ENDIF.
ENDIF.
IF ITAB_COSS-GJAHR < C_YEAR.
WKVALX = ITAB_COSS-WOG001
+ ITAB_COSS-WOG002
+ ITAB_COSS-WOG003
+ ITAB_COSS-WOG004
+ ITAB_COSS-WOG005
+ ITAB_COSS-WOG006
+ ITAB_COSS-WOG007
+ ITAB_COSS-WOG008
+ ITAB_COSS-WOG009
+ ITAB_COSS-WOG010
+ ITAB_COSS-WOG011
+ ITAB_COSS-WOG012.
ENDIF.
WKVALY = WKVALX.
ENDFORM.
*----------------------------------------------------------------------*
* FORM FRM_WRITE_DATA *
*----------------------------------------------------------------------*
FORM FRM_WRITE_DATA.
CLEAR: FC_ALV.
REFRESH: FC_ALV.
perform append_fc_alv using:
'ITAB1' 'AUFNR' 'AFKO' 'AUFNR' '' '' '',
'ITAB1' 'PLNBEZ' 'AFKO' 'PLNBEZ' '' '' '',
'ITAB1' 'GAMNG' 'CAUFV' 'GAMNG' '' '' '',
'ITAB1' 'IGMNG' 'CAUFV' 'IGMNG' '' '' '',
'ITAB1' 'GASMG' 'CAUFV' 'GASMG' '' '' '',
'ITAB1' 'PMCOST' '' '' 'C' '13' 'Plan MatCost',
'ITAB1' 'ACOST' '' '' 'C' '15' 'Actual Cost',
'ITAB1' 'AMCOST' 'RESB' 'ENWRT' 'C' '15' 'Actual MatCost',
'ITAB1' 'ALCOST' 'RESB' 'ENWRT' 'C' '15' 'Actual LabCost',
'ITAB1' 'ZCOST' '' '' 'C' '13' 'Pro cost',
'ITAB1' 'ZUCOST' '' '' 'C' '15' 'Pro Unitcost',
'ITAB1' 'ZMCOST' '' '' 'C' '15' 'Pro Matcost',
'ITAB1' 'ZLCOST' '' '' 'C' '15' 'Pro Labcost',
'ITAB1' 'VCOST' '' '' 'C' '15' 'Variance',
'ITAB1' 'VLCOST' '' '' 'C' '15' 'LabVariance',
'ITAB1' 'VMCOST' '' '' 'C' '15' 'MatVariance',
'ITAB1' 'MATVRC' '' '' 'C' '15' 'Matshort',
'ITAB1' 'SEMISCP' '' '' 'C' '15' 'SemiScrap',
'ITAB1' 'FSCP' '' '' 'C' '15' 'FinScrap',
'ITAB1' 'MATWST' '' '' 'C' '15' 'MatWear'.
perform call_alv_for_list.
ENDFORM.
************************************************************************
* Form_id: APPEND_FC_ALV *
************************************************************************
form append_fc_alv using a b c d e f g.
move: a to fc_alv-tabname,
b to fc_alv-fieldname,
c to fc_alv-ref_tabname,
d to fc_alv-ref_fieldname.
if not e is initial.
move: e to fc_alv-inttype,
f to fc_alv-outputlen,
g to fc_alv-seltext_s, " SELTEXT.
g to fc_alv-seltext_m,
g to fc_alv-seltext_l.
endif.
case b.
when 'SALK3' or 'SALK3B' or 'VERPR'.
move 'WAERS' to fc_alv-cfieldname.
when 'MENGE' or 'MENGEB'.
move 'MEINS' to fc_alv-qfieldname.
when 'SALK3BNT' or 'SALK3NT'.
move 'WAERSNT' to fc_alv-cfieldname.
when others.
move space to fc_alv-cfieldname.
move space to fc_alv-qfieldname.
endcase.
append fc_alv. clear fc_alv.
endform.
************************************************************************
* Form_id: CALL_ALV_FOR_LIST *
************************************************************************
form call_alv_for_list .
data: i_sy-repid like sy-repid.
move: sy-repid to alv_variant-report,
alv_def to alv_variant-variant.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
i_callback_program = i_sy-repid
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
* IS_LAYOUT =
it_fieldcat = fc_alv[]
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
i_default = 'X'
i_save = 'A'
is_variant = alv_variant
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* I_HTML_HEIGHT_TOP =
* I_HTML_HEIGHT_END =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
tables
t_outtab = itab1[]
* EXCEPTIONS
* PROGRAM_ERROR = 1
* OTHERS = 2
.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endform. " CALL_ALV_FOR_LIST
3.設置斷點進行測試
4.測試出來的介面
|
|