其实这个报表没有含金亮,只是在写这个报表的时候没有注意2点.1),取汇率的时候没有使用标准的函数去取,所以自己取的时候总是出现问题. 2),表TCURR 中有个"逆算日期"的问题,这2个问题搞得自己有些运乎晕乎的了!~还好最后解决了!~~
代码语言:javascript复制*&---------------------------------------------------------------------*
*& Report ZPPR0035 *
*& Create By: Chouer
*& Create date:2007.11.15
*& Description: 成品原料销售成本分析
*&---------------------------------------------------------------------*
*&M O D I F I C A T I O N L O G
*&---------------------------------------------------------------------*
**
**
************************************************************************
**CHANGEDATE POGRAMMER REQUEST DESCRIPTION
**============= ============== ================== =====================
**
**
*&---------------------------------------------------------------------*
REPORT ZPPR0035.
TABLES: MKPF,
MSEG,CRHD.
**---Initial table it_mkpf
TYPES: BEGIN OF STR_MKPF,
MBLNR LIKE MKPF-MBLNR, "物料凭证编号
MJAHR LIKE MKPF-MJAHR, "物料凭证年度
BUDAT LIKE MKPF-BUDAT, "凭证中的记帐日期
END OF STR_MKPF.
DATA: WA_MKPF TYPE STR_MKPF,
IT_MKPF TYPE TABLE OF STR_MKPF.
**---Initial table it_mseg
TYPES: BEGIN OF STR_MSEG,
MBLNR LIKE MSEG-MBLNR, "物料凭证编号
ZEILE LIKE MSEG-ZEILE,
MJAHR LIKE MSEG-MJAHR, "物料凭证年度
SGTXT LIKE MSEG-SGTXT, "项目文本
AUFNR LIKE MSEG-AUFNR, "订单编码
MATNR LIKE MSEG-MATNR, "物料号
MENGE LIKE MSEG-MENGE, "数量
MEINS LIKE MSEG-MEINS, "基本计量单位
BWART LIKE MSEG-BWART, "移动类型 (库存管理)
WAERS LIKE MSEG-WAERS, "货币代码
CHARG LIKE MSEG-CHARG,
END OF STR_MSEG.
DATA: WA_MSEG TYPE STR_MSEG,
IT_MSEG TYPE TABLE OF STR_MSEG.
DATA: WA_MSEG2 TYPE STR_MSEG,
IT_MSEG2 TYPE TABLE OF STR_MSEG.
**---Initial table it_afpo
TYPES: BEGIN OF STR_AFPO,
AUFNR LIKE AFPO-AUFNR, "订单编码
KDAUF LIKE AFPO-KDAUF, "销售订单号
KDPOS LIKE AFPO-KDPOS, "销售订单行项
WEMNG LIKE AFPO-WEMNG, "此订单项的收货数量
MEINS LIKE AFPO-MEINS, "
END OF STR_AFPO.
DATA: WA_AFPO TYPE STR_AFPO,
IT_AFPO TYPE TABLE OF STR_AFPO.
**---Initial table it_aufm
TYPES: BEGIN OF STR_AUFM,
AUFNR LIKE AUFM-AUFNR, "订单编码
MATNR LIKE AUFM-MATNR, "物料号
BWART LIKE AUFM-BWART, "移动类型 (库存管理)
MENGE LIKE AUFM-MENGE, "数量
MEINS LIKE AUFM-MEINS, "基本计量单位
WERKS LIKE AUFM-WERKS, "plant
BUDAT LIKE AUFM-BUDAT,
MBLNR LIKE AUFM-MBLNR,
MJAHR LIKE AUFM-MJAHR,
ZEILE LIKE AUFM-ZEILE,
END OF STR_AUFM.
DATA: WA_AUFM TYPE STR_AUFM,
IT_AUFM TYPE TABLE OF STR_AUFM.
**---Initial table it_mbew
TYPES: BEGIN OF STR_MBEW,
MATNR LIKE MBEW-MATNR, "物料号
STPRS LIKE MBEW-STPRS, "标准价格
END OF STR_MBEW.
DATA: WA_MBEW TYPE STR_MBEW,
IT_MBEW TYPE TABLE OF STR_MBEW.
**---Initial table it_mbewh
TYPES: BEGIN OF STR_MBEWH,
MATNR LIKE MBEWH-MATNR, "物料号
LFGJA LIKE MBEWH-LFGJA,
LFMON LIKE MBEWH-LFMON,
BWKEY LIKE MBEWH-BWKEY,
STPRS LIKE MBEWH-STPRS, "标准价格
END OF STR_MBEWH.
DATA: WA_MBEWH TYPE STR_MBEWH,
IT_MBEWH TYPE TABLE OF STR_MBEWH.
**---Initial table it_abap
TYPES: BEGIN OF STR_VBAP,
VBELN LIKE VBAP-VBELN, "销售凭证
POSNR LIKE VBAP-POSNR, "销售凭证 Item
UMVKN LIKE VBAP-UMVKN, "销售量转换为SKU的值(除数)
UMVKZ LIKE VBAP-UMVKZ, "销售数量转换成SKU的分子(因子)
VRKME LIKE VBAP-VRKME, "销售单位
GEWEI LIKE VBAP-GEWEI, "重量单位
KWMENG LIKE VBAP-KWMENG, "定单重量
NETWR LIKE VBAP-NETWR, "净价值
WAERK LIKE VBAP-WAERK, "SD 凭证货币
KNUMV LIKE VBAK-KNUMV,
END OF STR_VBAP.
DATA: WA_VBAP TYPE STR_VBAP,
IT_VBAP TYPE TABLE OF STR_VBAP.
**---Initial table it_vbak
TYPES: BEGIN OF STR_VBAK,
KNUMV LIKE VBAK-KNUMV,
VBELN LIKE VBAK-VBELN,
END OF STR_VBAK.
DATA: WA_VBAK TYPE STR_VBAK,
IT_VBAK TYPE TABLE OF STR_VBAK.
**---initial table it_vbkd
TYPES: BEGIN OF STR_VBKD,
VBELN LIKE VBKD-VBELN, "销售凭证
POSNR LIKE VBKD-POSNR, "销售凭证 Item
PRSDT LIKE VBKD-PRSDT, "定价日期
KURSK LIKE VBKD-KURSK, "汇率
END OF STR_VBKD.
DATA: WA_VBKD TYPE STR_VBKD,
IT_VBKD TYPE TABLE OF STR_VBKD.
**---Initial table it_konv
TYPES: BEGIN OF STR_KONV,
KNUMV LIKE KONV-KNUMV, "单据条件数
KBETR LIKE KONV-KBETR, "金额
WAERS LIKE KONV-WAERS, "货币代码
KPOSN LIKE KONV-KPOSN,
END OF STR_KONV.
DATA: WA_KONV TYPE STR_KONV,
IT_KONV TYPE TABLE OF STR_KONV.
DATA: WA_KONV2 TYPE STR_KONV,
IT_KONV2 TYPE TABLE OF STR_KONV.
**---Initial table it_tab
TYPES: BEGIN OF STR_TAB,
BUDAT LIKE MKPF-BUDAT, "凭证中的记帐日期
ZEILE LIKE AUFM-ZEILE,
WERKS LIKE AUFM-WERKS, "plant
MBLNR LIKE MSEG-MBLNR, "物料凭证编号
MJAHR LIKE MSEG-MJAHR, "物料凭证年度
SGTXT LIKE MSEG-SGTXT, "项目文本
* AUFNR LIKE MSEG-AUFNR, "订单编码
MATNR LIKE MSEG-MATNR, "物料号
MENGE LIKE MSEG-MENGE, "数量
MEINS LIKE MSEG-MEINS, "基本计量单位
BWART LIKE MSEG-BWART, "移动类型 (库存管理)
WAERS LIKE MSEG-WAERS, "货币代码
KDAUF LIKE AFPO-KDAUF, "销售订单号
KDPOS LIKE AFPO-KDPOS, "销售订单行项
WEMNG LIKE AFPO-WEMNG, "此订单项的收货数量
AUFNR LIKE AUFM-AUFNR, "订单编码
MATNR_M LIKE AUFM-MATNR, "物料号
MENGE_M LIKE AUFM-MENGE, "数量
MEINS_M LIKE AUFM-MEINS, "基本计量单位
STPRS LIKE MBEW-STPRS, "标准价格
UMVKN LIKE VBAP-UMVKN, "销售量转换为SKU的值(除数)
UMVKZ LIKE VBAP-UMVKZ, "销售数量转换成SKU的分子(因子)
VRKME LIKE VBAP-VRKME, "销售单位
GEWEI LIKE VBAP-GEWEI, "重量单位
KWMENG LIKE VBAP-KWMENG, "定单重量
NETWR LIKE VBAP-NETWR, "净价值
WAERK LIKE VBAP-WAERK, "SD 凭证货币
KSCHL LIKE KONV-KSCHL, "条件类型
KBETR LIKE KONV-KBETR, "金额
WAERS_S LIKE KONV-WAERS, "货币代码
KURSK LIKE VBKD-KURSK, "汇率
XSDDJ TYPE P DECIMALS 3, "销售单单价
BZ TYPE P DECIMALS 3,
BZJE TYPE P DECIMALS 3,
CPJE TYPE P DECIMALS 3,
END OF STR_TAB.
DATA: WA_TAB TYPE STR_TAB,
IT_TAB TYPE TABLE OF STR_TAB.
DATA: WA_TAB2 TYPE STR_TAB,
IT_TAB2 TYPE TABLE OF STR_TAB.
DATA: WA_TAB3 TYPE STR_TAB,
IT_TAB3 TYPE TABLE OF STR_TAB.
DATA: DAT_L LIKE MKPF-BUDAT.
DATA: MY_UKURS LIKE TCURR-UKURS.
DATA: MY_GDATU LIKE TCURR-GDATU.
DATA: DAT1(4),
DAT2(2).
* Type-pools
TYPE-POOLS: SLIS.
TYPE-POOLS: IBXX, IBCO2.
TYPES: IBCO2_VALUE_REC LIKE IBVALUE0.
TYPES: IBCO2_VALUE_TAB TYPE IBCO2_VALUE_REC OCCURS 0.
DATA: V_SAVE(1) TYPE C,
V_EXIT(1) TYPE C,
V_VARIANT1 LIKE DISVARIANT,
V_VARIANT2 LIKE DISVARIANT.
DATA C_PROG LIKE SY-REPID.
DATA:FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
FIELDCAT_LN LIKE LINE OF FIELDCAT,
SORTCAT TYPE SLIS_T_SORTINFO_ALV,
LS_SORT TYPE SLIS_SORTINFO_ALV,
GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER,
GS_LAYOUT TYPE SLIS_LAYOUT_ALV,
GT_EVENTS TYPE SLIS_T_EVENT,
G_REPID LIKE SY-REPID .
DATA: SC_TITLE(70) TYPE C.
*&---------------------------------------------------------------------*
**Selection-screen
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: S_BUDAT FOR MKPF-BUDAT OBLIGATORY NO-EXTENSION,
S_ARBPL FOR CRHD-ARBPL OBLIGATORY .
* S_SGTXT FOR MSEG-SGTXT.
SELECTION-SCREEN END OF BLOCK B1.
SELECTION-SCREEN BEGIN OF BLOCK B3 WITH FRAME TITLE TEXT-004.
PARAMETERS: P_GR1 RADIOBUTTON GROUP G1,
P_GR2 RADIOBUTTON GROUP G1 DEFAULT 'X'.
SELECTION-SCREEN END OF BLOCK B3.
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-003.
PARAMETERS: P_VARIN LIKE DISVARIANT-VARIANT.
SELECTION-SCREEN END OF BLOCK B2.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_VARIN.
PERFORM F4_FOR_VARIANT.
*&---------------------------------------------------------------------*
**Start-of-selection
*&---------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM SELECT_DATA.
PERFORM SELECT_DATA_MATERIAL.
PERFORM GET_DATA.
PERFORM GET_LAST_DATA.
**---显示汇总报表
IF P_GR2 = 'X'.
PERFORM GET_TOTAL_DATA.
ENDIF.
**---得到标题
PERFORM GET_TITLE.
*&---------------------------------------------------------------------*
*&End-of-selection
*&---------------------------------------------------------------------*
END-OF-SELECTION.
C_PROG = SY-REPID.
PERFORM INITIALIZE_VARIANT.
IF P_GR2 = 'X'.
PERFORM SUB_FIELD_OUT_ALV2 CHANGING FIELDCAT.
ELSE.
PERFORM SUB_FIELD_OUT_ALV CHANGING FIELDCAT.
ENDIF.
PERFORM SUB_LAYOUT_OUT_ALV CHANGING GS_LAYOUT.
PERFORM CALL_ALV_DATA_OUTPUT.
*&---------------------------------------------------------------------*
*& Form Select_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM SELECT_DATA .
SELECT MBLNR MJAHR BUDAT
INTO CORRESPONDING FIELDS OF TABLE IT_MKPF
FROM MKPF
WHERE BUDAT IN S_BUDAT.
IF NOT IT_MKPF IS INITIAL.
SELECT MBLNR MJAHR ZEILE SGTXT AUFNR MATNR MENGE MEINS BWART WAERS
CHARG
INTO CORRESPONDING FIELDS OF TABLE IT_MSEG
FROM MSEG
FOR ALL ENTRIES IN IT_MKPF
WHERE MBLNR = IT_MKPF-MBLNR
AND MJAHR = IT_MKPF-MJAHR
AND ( BWART = '101' OR BWART = '102' )
* OR BWART = 'Z31' OR BWART = 'Z32'
* OR BWART = '531' OR BWART = '532')
AND SGTXT LIKE 'S%'.
ENDIF.
LOOP AT IT_MSEG INTO WA_MSEG.
**---取SGTXT前3位作为机台号
WA_MSEG-SGTXT = WA_MSEG-SGTXT 0(3).
**---移动类型为102 数量取负
IF WA_MSEG-BWART = '102'.
WA_MSEG-MENGE = 0 - WA_MSEG-MENGE.
ENDIF.
MODIFY IT_MSEG FROM WA_MSEG.
CLEAR WA_MSEG.
ENDLOOP.
**--删除不符合条件的机台号
DELETE IT_MSEG WHERE NOT SGTXT IN S_ARBPL.
***---合并生产定单中的数量
REFRESH IT_MSEG2.
* IT_MSEG2[] = IT_MSEG[].
LOOP AT IT_MSEG INTO WA_MSEG.
MOVE: WA_MSEG-SGTXT TO WA_MSEG2-SGTXT,
WA_MSEG-AUFNR TO WA_MSEG2-AUFNR,
WA_MSEG-MATNR TO WA_MSEG2-MATNR,
WA_MSEG-MENGE TO WA_MSEG2-MENGE,
WA_MSEG-MEINS TO WA_MSEG2-MEINS,
WA_MSEG-WAERS TO WA_MSEG2-WAERS.
COLLECT WA_MSEG2 INTO IT_MSEG2.
CLEAR:WA_MSEG,WA_MSEG2.
ENDLOOP.
ENDFORM. " Select_data
*&---------------------------------------------------------------------*
*& Form select_data_material
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM SELECT_DATA_MATERIAL .
IF NOT IT_MSEG2 IS INITIAL.
SELECT AUFNR KDAUF KDPOS WEMNG
INTO CORRESPONDING FIELDS OF TABLE IT_AFPO
FROM AFPO
FOR ALL ENTRIES IN IT_MSEG2
WHERE AUFNR = IT_MSEG2-AUFNR.
SELECT AUFNR MATNR BWART MENGE MEINS BUDAT MBLNR MJAHR ZEILE WERKS
INTO CORRESPONDING FIELDS OF TABLE IT_AUFM
FROM AUFM
FOR ALL ENTRIES IN IT_MSEG2
WHERE AUFNR = IT_MSEG2-AUFNR
AND ( BWART = '261' OR BWART = '262'
* ).
OR BWART = 'Z31' OR BWART = 'Z32').
IF NOT IT_AUFM IS INITIAL.
SELECT MATNR STPRS
INTO CORRESPONDING FIELDS OF TABLE IT_MBEW
FROM MBEW
FOR ALL ENTRIES IN IT_AUFM
WHERE MATNR = IT_AUFM-MATNR
AND BWKEY = IT_AUFM-WERKS.
ENDIF.
IF NOT IT_AFPO IS INITIAL.
SELECT VBELN POSNR UMVKN UMVKZ VRKME
GEWEI KWMENG NETWR WAERK
INTO CORRESPONDING FIELDS OF TABLE IT_VBAP
FROM VBAP
FOR ALL ENTRIES IN IT_AFPO
WHERE VBELN = IT_AFPO-KDAUF
AND POSNR = IT_AFPO-KDPOS.
SELECT VBELN KNUMV
INTO CORRESPONDING FIELDS OF TABLE IT_VBAK
FROM VBAK
FOR ALL ENTRIES IN IT_AFPO
WHERE VBELN = IT_AFPO-KDAUF.
SELECT VBELN POSNR PRSDT KURSK
INTO CORRESPONDING FIELDS OF TABLE IT_VBKD
FROM VBKD
FOR ALL ENTRIES IN IT_AFPO
WHERE VBELN = IT_AFPO-KDAUF.
ENDIF.
LOOP AT IT_VBAP INTO WA_VBAP.
READ TABLE IT_VBAK INTO WA_VBAK WITH KEY VBELN = WA_VBAP-VBELN.
IF SY-SUBRC = 0.
MOVE WA_VBAK-KNUMV TO WA_VBAP-KNUMV.
MODIFY IT_VBAP FROM WA_VBAP TRANSPORTING KNUMV.
ENDIF.
ENDLOOP.
IF NOT IT_VBAP IS INITIAL.
SELECT KNUMV KSCHL KBETR WAERS KPOSN
INTO CORRESPONDING FIELDS OF TABLE IT_KONV
FROM KONV
FOR ALL ENTRIES IN IT_VBAP
WHERE KNUMV = IT_VBAP-KNUMV
AND KPOSN = IT_VBAP-POSNR
AND ( KSCHL = 'ZVA1' OR KSCHL = 'ZKF0' ).
ENDIF.
ENDIF.
LOOP AT IT_VBKD INTO WA_VBKD.
IF WA_VBKD-KURSK = '1.00000'.
**---计算输入日期的最后一天
CALL FUNCTION 'LAST_DAY_OF_MONTHS'
EXPORTING
DAY_IN = WA_VBKD-PRSDT
IMPORTING
LAST_DAY_OF_MONTH = WA_VBKD-PRSDT
EXCEPTIONS
DAY_IN_NO_DATE = 1
OTHERS = 2.
**--从汇率表中重新取汇率,取该月月末的汇率
CALL FUNCTION 'READ_EXCHANGE_RATE'
EXPORTING
DATE = WA_VBKD-PRSDT
FOREIGN_CURRENCY = 'USD'
LOCAL_CURRENCY = 'CNY'
TYPE_OF_RATE = 'M'
IMPORTING
EXCHANGE_RATE = MY_UKURS
EXCEPTIONS
NO_RATE_FOUND = 1
NO_FACTORS_FOUND = 2
NO_SPREAD_FOUND = 3
DERIVED_2_TIMES = 4
OVERFLOW = 5
ZERO_RATE = 6
OTHERS = 7.
MOVE MY_UKURS TO WA_VBKD-KURSK.
MODIFY IT_VBKD FROM WA_VBKD TRANSPORTING KURSK.
CLEAR WA_VBKD.
ENDIF.
ENDLOOP.
ENDFORM. " select_data_material
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* 整理数据
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_DATA .
**---运费+印花税
REFRESH IT_KONV2.
LOOP AT IT_KONV INTO WA_KONV.
MOVE-CORRESPONDING WA_KONV TO WA_KONV2.
COLLECT WA_KONV2 INTO IT_KONV2.
CLEAR: WA_KONV2, WA_KONV.
ENDLOOP.
REFRESH IT_TAB.
SORT IT_AUFM BY AUFNR.
LOOP AT IT_AUFM INTO WA_AUFM.
MOVE: WA_AUFM-AUFNR TO WA_TAB-AUFNR,
WA_AUFM-MATNR TO WA_TAB-MATNR_M,
WA_AUFM-MEINS TO WA_TAB-MEINS_M.
* WA_AUFM-BUDAT TO WA_TAB-BUDAT,
* WA_AUFM-MBLNR TO WA_TAB-MBLNR,
* WA_AUFM-MJAHR TO WA_TAB-MJAHR,
* WA_AUFM-ZEILE TO WA_TAB-ZEILE.
IF WA_AUFM-BWART = '262' OR WA_AUFM-BWART = 'Z31'.
WA_TAB-MENGE_M = 0 - WA_AUFM-MENGE.
ELSE.
MOVE: WA_AUFM-MENGE TO WA_TAB-MENGE_M.
ENDIF.
**----计算物料的标准价格
PERFORM GET_BZJG_HISTORY USING WA_AUFM-BUDAT
WA_AUFM-MATNR
WA_AUFM-WERKS
CHANGING WA_TAB-STPRS.
**---如果价格为空,就去当月的标准价格
IF WA_TAB-STPRS = ''.
READ TABLE IT_MBEW INTO WA_MBEW WITH KEY MATNR = WA_TAB-MATNR_M.
IF SY-SUBRC = 0.
MOVE: WA_MBEW-STPRS TO WA_TAB-STPRS.
ENDIF.
ENDIF.
APPEND WA_TAB TO IT_TAB.
CLEAR: WA_TAB,WA_AUFM.
ENDLOOP.
LOOP AT IT_TAB INTO WA_TAB.
READ TABLE IT_AFPO INTO WA_AFPO WITH KEY AUFNR = WA_TAB-AUFNR.
IF SY-SUBRC = 0.
MOVE: WA_AFPO-KDAUF TO WA_TAB-KDAUF,
WA_AFPO-KDPOS TO WA_TAB-KDPOS,
WA_AFPO-WEMNG TO WA_TAB-WEMNG.
READ TABLE IT_VBAP INTO WA_VBAP WITH KEY VBELN = WA_AFPO-KDAUF
POSNR = WA_AFPO-KDPOS.
IF SY-SUBRC = 0.
MOVE:WA_VBAP-UMVKN TO WA_TAB-UMVKN,
WA_VBAP-UMVKZ TO WA_TAB-UMVKZ,
WA_VBAP-VRKME TO WA_TAB-VRKME,
WA_VBAP-GEWEI TO WA_TAB-GEWEI,
WA_VBAP-KWMENG TO WA_TAB-KWMENG,
WA_VBAP-NETWR TO WA_TAB-NETWR,
WA_VBAP-WAERK TO WA_TAB-WAERK.
ENDIF.
**---取汇率
READ TABLE IT_VBKD INTO WA_VBKD WITH KEY VBELN = WA_AFPO-KDAUF.
IF SY-SUBRC = 0.
MOVE: WA_VBKD-KURSK TO WA_TAB-KURSK.
ENDIF.
**---取运输费和印花税
READ TABLE IT_VBAP INTO WA_VBAP WITH KEY VBELN = WA_AFPO-KDAUF
POSNR = WA_AFPO-KDPOS.
IF SY-SUBRC = 0.
READ TABLE IT_KONV2 INTO WA_KONV2
WITH KEY KNUMV = WA_VBAP-KNUMV.
IF SY-SUBRC = 0.
MOVE: WA_KONV2-KBETR TO WA_TAB-KBETR,
WA_KONV2-WAERS TO WA_TAB-WAERS_S.
ENDIF.
ENDIF.
ENDIF.
READ TABLE IT_MSEG2 INTO WA_MSEG2 WITH KEY AUFNR = WA_TAB-AUFNR.
IF SY-SUBRC = 0.
MOVE:WA_MSEG2-SGTXT TO WA_TAB-SGTXT,
WA_MSEG2-MATNR TO WA_TAB-MATNR,
WA_MSEG2-MENGE TO WA_TAB-MENGE,
WA_MSEG2-MEINS TO WA_TAB-MEINS,
WA_MSEG2-BWART TO WA_TAB-BWART,
WA_MSEG2-WAERS TO WA_TAB-WAERS.
ENDIF.
**---计算成品数量/已交货数量*单个原料的数量
IF WA_TAB-WEMNG = 0.
* MESSAGE '已交货数量不能为0' TYPE 'E'.
* STOP.
ELSE.
WA_TAB-BZ = WA_TAB-MENGE / WA_TAB-WEMNG * WA_TAB-MENGE_M.
ENDIF.
MODIFY IT_TAB FROM WA_TAB.
CLEAR: WA_TAB,WA_AFPO,WA_MBEW,WA_MSEG2.
ENDLOOP.
ENDFORM. " GET_DATA
*&---------------------------------------------------------------------*
*& Form GET_LAST_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_LAST_DATA .
LOOP AT IT_TAB INTO WA_TAB.
**---若单位为'EA'的,成品的单价为0
IF WA_TAB-VRKME = 'EA'.
WA_TAB-XSDDJ = 0.
ELSE.
**---计算单价
IF WA_TAB-KWMENG = 0.
* MESSAGE '销售定单的数量不能为0' TYPE 'E'.
* STOP.
ELSE.
WA_TAB-XSDDJ = WA_TAB-NETWR / WA_TAB-KWMENG.
ENDIF.
**---减去运费和印花税
WA_TAB-XSDDJ = WA_TAB-XSDDJ - WA_TAB-KBETR.
**---转换成人民币/KG
IF WA_TAB-WAERK = 'USD'.
WA_TAB-XSDDJ = WA_TAB-XSDDJ * WA_TAB-KURSK
/ ( WA_TAB-UMVKZ / WA_TAB-UMVKN ).
ELSEIF WA_TAB-WAERK = 'CNY'.
WA_TAB-XSDDJ = WA_TAB-XSDDJ
/ ( WA_TAB-UMVKZ / WA_TAB-UMVKN ).
ELSEIF WA_TAB-WAERK = ''.
WA_TAB-XSDDJ = 0.
ENDIF.
ENDIF.
**---去掉工单和销售单前面的0
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = WA_TAB-AUFNR
IMPORTING
OUTPUT = WA_TAB-AUFNR.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
INPUT = WA_TAB-KDAUF
IMPORTING
OUTPUT = WA_TAB-KDAUF.
**---计算比例原料的金额
WA_TAB-BZJE = WA_TAB-BZ * WA_TAB-STPRS.
MODIFY IT_TAB FROM WA_TAB.
CLEAR WA_TAB.
ENDLOOP.
LOOP AT IT_TAB INTO WA_TAB.
MOVE: WA_TAB-AUFNR TO WA_TAB3-AUFNR,
WA_TAB-MATNR_M TO WA_TAB3-MATNR_M,
WA_TAB-MENGE_M TO WA_TAB3-MENGE_M,
WA_TAB-MEINS_M TO WA_TAB3-MEINS_M,
WA_TAB-BZ TO WA_TAB3-BZ,
WA_TAB-BZJE TO WA_TAB3-BZJE.
COLLECT WA_TAB3 INTO IT_TAB3.
CLEAR: WA_TAB,WA_TAB3.
ENDLOOP.
LOOP AT IT_TAB3 INTO WA_TAB3.
READ TABLE IT_TAB INTO WA_TAB WITH KEY AUFNR = WA_TAB3-AUFNR
MATNR_M = WA_TAB3-MATNR_M.
IF SY-SUBRC = 0.
MOVE: WA_TAB-SGTXT TO WA_TAB3-SGTXT,
WA_TAB-MENGE TO WA_TAB3-MENGE,
WA_TAB-MEINS TO WA_TAB3-MEINS,
WA_TAB-XSDDJ TO WA_TAB3-XSDDJ,
WA_TAB-KDAUF TO WA_TAB3-KDAUF,
WA_TAB-KDPOS TO WA_TAB3-KDPOS,
WA_TAB-MATNR TO WA_TAB3-MATNR,
WA_TAB-STPRS TO WA_TAB3-STPRS,
WA_TAB-KURSK TO WA_TAB3-KURSK.
ENDIF.
MODIFY IT_TAB3 FROM WA_TAB3.
CLEAR: WA_TAB,WA_TAB3.
ENDLOOP.
REFRESH IT_TAB.
IT_TAB[] = IT_TAB3[].
ENDFORM. " GET_LAST_DATA
*&---------------------------------------------------------------------*
*& Form INITIALIZE_VARIANT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM INITIALIZE_VARIANT .
CLEAR V_VARIANT1.
V_SAVE = 'A'.
V_VARIANT1-REPORT = C_PROG.
V_VARIANT2 = V_VARIANT1.
CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
EXPORTING
I_SAVE = V_SAVE
CHANGING
CS_VARIANT = V_VARIANT2
EXCEPTIONS
NOT_FOUND = 2.
IF SY-SUBRC = 0.
P_VARIN = V_VARIANT2-VARIANT.
ENDIF.
ENDFORM. " INITIALIZE_VARIANT
*&---------------------------------------------------------------------*
*& Form SUB_FIELD_OUT_ALV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_FIELDCAT text
*----------------------------------------------------------------------*
FORM SUB_FIELD_OUT_ALV CHANGING P_FIELDCAT.
* FIELDCAT_LN-FIELDNAME = 'BUDAT' .
* FIELDCAT_LN-KEY = 'X'.
* FIELDCAT_LN-SELTEXT_L = '记帐日期'.
* APPEND FIELDCAT_LN TO FIELDCAT.
*
* FIELDCAT_LN-FIELDNAME = 'MBLNR' .
* FIELDCAT_LN-KEY = 'X'.
* FIELDCAT_LN-SELTEXT_L = '物料凭证'.
* APPEND FIELDCAT_LN TO FIELDCAT.
*
* FIELDCAT_LN-FIELDNAME = 'MJAHR' .
* FIELDCAT_LN-KEY = 'X'.
* FIELDCAT_LN-SELTEXT_L = '年度'.
* APPEND FIELDCAT_LN TO FIELDCAT.
FIELDCAT_LN-FIELDNAME = 'SGTXT' .
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '机台'.
APPEND FIELDCAT_LN TO FIELDCAT.
FIELDCAT_LN-FIELDNAME = 'AUFNR' .
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '订单编码'.
APPEND FIELDCAT_LN TO FIELDCAT.
FIELDCAT_LN-FIELDNAME = 'MATNR' .
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '物料号码(成品)'.
APPEND FIELDCAT_LN TO FIELDCAT.
FIELDCAT_LN-FIELDNAME = 'MENGE' .
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '物料数量(成品)'.
APPEND FIELDCAT_LN TO FIELDCAT.
FIELDCAT_LN-FIELDNAME = 'MEINS' .
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '单位(成品)'.
APPEND FIELDCAT_LN TO FIELDCAT.
FIELDCAT_LN-FIELDNAME = 'XSDDJ' .
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '成品单价(RMB/KG)'.
APPEND FIELDCAT_LN TO FIELDCAT.
FIELDCAT_LN-FIELDNAME = 'KDAUF' .
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '销售订单号'.
APPEND FIELDCAT_LN TO FIELDCAT.
FIELDCAT_LN-FIELDNAME = 'KDPOS' .
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '销售订单行项'.
APPEND FIELDCAT_LN TO FIELDCAT.
FIELDCAT_LN-FIELDNAME = 'MATNR_M' .
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '物料号码(原料)'.
APPEND FIELDCAT_LN TO FIELDCAT.
FIELDCAT_LN-FIELDNAME = 'MENGE_M' .
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '物料数量(原料)'.
APPEND FIELDCAT_LN TO FIELDCAT.
FIELDCAT_LN-FIELDNAME = 'MEINS_M' .
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '单位(原料)'.
APPEND FIELDCAT_LN TO FIELDCAT.
FIELDCAT_LN-FIELDNAME = 'STPRS' .
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '标准单价(原料)'.
APPEND FIELDCAT_LN TO FIELDCAT.
FIELDCAT_LN-FIELDNAME = 'BZ' .
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '比例用量(原料)'.
APPEND FIELDCAT_LN TO FIELDCAT.
FIELDCAT_LN-FIELDNAME = 'BZJE' .
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '比例金额(原料)'.
APPEND FIELDCAT_LN TO FIELDCAT.
FIELDCAT_LN-FIELDNAME = 'KURSK' .
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '汇率'.
APPEND FIELDCAT_LN TO FIELDCAT.
ENDFORM. " SUB_FIELD_OUT_ALV
*&---------------------------------------------------------------------*
*& Form SUB_LAYOUT_OUT_ALV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_GS_LAYOUT text
*----------------------------------------------------------------------*
FORM SUB_LAYOUT_OUT_ALV CHANGING P_GS_LAYOUT.
GS_LAYOUT-ZEBRA = 'X'. " 斑马线表示
GS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'. " 最适合列宽
ENDFORM. " sub_layout_out_alv
*&---------------------------------------------------------------------*
*& Form CALL_ALV_DATA_OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CALL_ALV_DATA_OUTPUT .
IF P_GR2 = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = G_REPID
IS_LAYOUT = GS_LAYOUT
I_GRID_TITLE = SC_TITLE
IT_FIELDCAT = FIELDCAT
IT_SORT = SORTCAT
I_SAVE = 'A'
IS_VARIANT = V_VARIANT2
* IT_EVENTS = GT_EVENTS[]
TABLES
T_OUTTAB = IT_TAB2
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC NE 0.
WRITE: 'SY-SUBRC: ', SY-SUBRC,
'REUSE_ALV_GRID_DISPLAY'.
ENDIF.
ELSE.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = G_REPID
IS_LAYOUT = GS_LAYOUT
I_GRID_TITLE = SC_TITLE
IT_FIELDCAT = FIELDCAT
IT_SORT = SORTCAT
I_SAVE = 'A'
IS_VARIANT = V_VARIANT2
* IT_EVENTS = GT_EVENTS[]
TABLES
T_OUTTAB = IT_TAB
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC NE 0.
WRITE: 'SY-SUBRC: ', SY-SUBRC,
'REUSE_ALV_GRID_DISPLAY'.
ENDIF.
ENDIF.
ENDFORM. " CALL_ALV_DATA_OUTPUT
*&---------------------------------------------------------------------*
*& Form F4_FOR_VARIANT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM F4_FOR_VARIANT .
CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
EXPORTING
IS_VARIANT = V_VARIANT1
I_SAVE = V_SAVE
IMPORTING
E_EXIT = V_EXIT
ES_VARIANT = V_VARIANT2
EXCEPTIONS
NOT_FOUND = 2.
IF SY-SUBRC = 2.
MESSAGE ID SY-MSGID TYPE 'S' NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
IF V_EXIT = SPACE.
P_VARIN = V_VARIANT2-VARIANT.
ENDIF.
ENDIF.
ENDFORM. " F4_FOR_VARIANT
*&---------------------------------------------------------------------*
*& Form get_total_data
*&---------------------------------------------------------------------*
* 输出汇总的报表
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_TOTAL_DATA .
REFRESH IT_TAB2.
LOOP AT IT_TAB INTO WA_TAB.
MOVE:
* WA_TAB-MBLNR TO WA_TAB2-MBLNR,
* WA_TAB-MJAHR TO WA_TAB2-MJAHR,
WA_TAB-SGTXT TO WA_TAB2-SGTXT,
WA_TAB-MATNR TO WA_TAB2-MATNR,
WA_TAB-WAERS TO WA_TAB2-WAERS,
WA_TAB-KDAUF TO WA_TAB2-KDAUF,
WA_TAB-KDPOS TO WA_TAB2-KDPOS,
WA_TAB-AUFNR TO WA_TAB2-AUFNR,
WA_TAB-BZJE TO WA_TAB2-BZJE,
WA_TAB-MENGE_M TO WA_TAB2-MENGE_M,
WA_TAB-MEINS_M TO WA_TAB2-MEINS_M,
WA_TAB-BZ TO WA_TAB2-BZ.
COLLECT WA_TAB2 INTO IT_TAB2.
CLEAR: WA_TAB,WA_TAB2.
ENDLOOP.
LOOP AT IT_TAB2 INTO WA_TAB2.
READ TABLE IT_TAB INTO WA_TAB WITH KEY
* MBLNR = WA_TAB2-MBLNR
* MJAHR = WA_TAB2-MJAHR
SGTXT = WA_TAB2-SGTXT
AUFNR = WA_TAB2-AUFNR
MATNR = WA_TAB2-MATNR.
IF SY-SUBRC = 0.
**---计算成品的总金额
WA_TAB2-CPJE = WA_TAB-MENGE * WA_TAB-XSDDJ.
**---合并
MOVE:WA_TAB-MENGE TO WA_TAB2-MENGE,
WA_TAB-MEINS TO WA_TAB2-MEINS,
WA_TAB-XSDDJ TO WA_TAB2-XSDDJ,
WA_TAB-KURSK TO WA_TAB2-KURSK.
ENDIF.
MODIFY IT_TAB2 FROM WA_TAB2.
ENDLOOP.
ENDFORM. " get_total_data
*&---------------------------------------------------------------------*
*& Form SUB_FIELD_OUT_ALV2
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_FIELDCAT text
*----------------------------------------------------------------------*
FORM SUB_FIELD_OUT_ALV2 CHANGING P_FIELDCAT.
* FIELDCAT_LN-FIELDNAME = 'MBLNR' .
* FIELDCAT_LN-KEY = 'X'.
* FIELDCAT_LN-SELTEXT_L = '物料凭证'.
* APPEND FIELDCAT_LN TO FIELDCAT.
*
* FIELDCAT_LN-FIELDNAME = 'MJAHR' .
* FIELDCAT_LN-KEY = 'X'.
* FIELDCAT_LN-SELTEXT_L = '年度'.
* APPEND FIELDCAT_LN TO FIELDCAT.
FIELDCAT_LN-FIELDNAME = 'SGTXT' .
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '机台'.
APPEND FIELDCAT_LN TO FIELDCAT.
FIELDCAT_LN-FIELDNAME = 'AUFNR' .
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '订单编码'.
APPEND FIELDCAT_LN TO FIELDCAT.
FIELDCAT_LN-FIELDNAME = 'MATNR' .
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '物料号码(成品)'.
APPEND FIELDCAT_LN TO FIELDCAT.
FIELDCAT_LN-FIELDNAME = 'MENGE' .
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '物料数量(成品)'.
APPEND FIELDCAT_LN TO FIELDCAT.
FIELDCAT_LN-FIELDNAME = 'MEINS' .
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '单位(成品)'.
APPEND FIELDCAT_LN TO FIELDCAT.
FIELDCAT_LN-FIELDNAME = 'XSDDJ' .
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '成品单价(RMB/KG)'.
APPEND FIELDCAT_LN TO FIELDCAT.
FIELDCAT_LN-FIELDNAME = 'CPJE' .
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '成品总金额'.
APPEND FIELDCAT_LN TO FIELDCAT.
FIELDCAT_LN-FIELDNAME = 'KDAUF' .
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '销售订单号'.
APPEND FIELDCAT_LN TO FIELDCAT.
FIELDCAT_LN-FIELDNAME = 'KDPOS' .
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '销售订单行项'.
APPEND FIELDCAT_LN TO FIELDCAT.
* FIELDCAT_LN-FIELDNAME = 'MATNR_M' .
* FIELDCAT_LN-KEY = 'X'.
* FIELDCAT_LN-SELTEXT_L = '物料号码(原料)'.
* APPEND FIELDCAT_LN TO FIELDCAT.
FIELDCAT_LN-FIELDNAME = 'MENGE_M' .
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '物料数量(原料)'.
APPEND FIELDCAT_LN TO FIELDCAT.
FIELDCAT_LN-FIELDNAME = 'MEINS_M' .
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '单位(原料)'.
APPEND FIELDCAT_LN TO FIELDCAT.
* FIELDCAT_LN-FIELDNAME = 'STPRS' .
* FIELDCAT_LN-KEY = 'X'.
* FIELDCAT_LN-SELTEXT_L = '标准单价(原料)'.
* APPEND FIELDCAT_LN TO FIELDCAT.
FIELDCAT_LN-FIELDNAME = 'BZ' .
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '比例用量(原料)'.
APPEND FIELDCAT_LN TO FIELDCAT.
FIELDCAT_LN-FIELDNAME = 'BZJE' .
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '比例总金额(原料)'.
APPEND FIELDCAT_LN TO FIELDCAT.
FIELDCAT_LN-FIELDNAME = 'KURSK' .
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-SELTEXT_L = '汇率'.
ENDFORM. " SUB_FIELD_OUT_ALV2
*&---------------------------------------------------------------------*
*& Form GET_TITLE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GET_TITLE .
DATA: DAT(28) TYPE C,
JT(20).
IF S_BUDAT IS INITIAL.
CONCATENATE '记帐日期:' '全部日期'INTO DAT.
ELSEIF S_BUDAT-LOW <> '' AND S_BUDAT-HIGH = ''.
CONCATENATE '记帐日期:' S_BUDAT-LOW INTO DAT.
ELSEIF S_BUDAT-LOW <> '' AND S_BUDAT-HIGH <> ''.
CONCATENATE '记帐日期:' S_BUDAT-LOW '~' S_BUDAT-HIGH INTO DAT.
ELSEIF S_BUDAT-LOW = '' AND S_BUDAT-HIGH <> ''.
CONCATENATE '记帐日期:' '00000000 ' '~' S_BUDAT-HIGH INTO DAT.
ENDIF.
IF S_ARBPL IS INITIAL.
CONCATENATE '机台号码:' '全部日期'INTO JT.
ELSEIF S_ARBPL-LOW <> '' AND S_ARBPL-HIGH = ''.
CONCATENATE '机台号码:' S_ARBPL-LOW INTO JT.
ELSEIF S_ARBPL-LOW <> '' AND S_ARBPL-HIGH <> ''.
CONCATENATE '机台号码:' S_ARBPL-LOW '~' S_ARBPL-HIGH INTO JT.
ELSEIF S_ARBPL-LOW = '' AND S_ARBPL-HIGH <> ''.
CONCATENATE '机台号码:' '00000000 ' '~' S_ARBPL-HIGH INTO JT.
ENDIF.
**---合并日期与机台
CONCATENATE DAT ' ' JT INTO SC_TITLE(70).
ENDFORM. " GET_TITLE
*&---------------------------------------------------------------------*
*& Form GET_BZJG_HISTORY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_DAT text
* -->P_WA_TAB_MATNR_M text
* -->P_WA_TAB_WERKS text
* <--P_WA_TAB_STPRS text
*----------------------------------------------------------------------*
FORM GET_BZJG_HISTORY USING P_BUDAT LIKE AUFM-BUDAT
P_MATNR LIKE AUFM-MATNR
P_WERKS LIKE AUFM-WERKS
CHANGING P_STPRS LIKE MBEWH-STPRS.
**---计算输入日期的最后一天
CALL FUNCTION 'LAST_DAY_OF_MONTHS'
EXPORTING
DAY_IN = P_BUDAT
IMPORTING
LAST_DAY_OF_MONTH = DAT_L
EXCEPTIONS
DAY_IN_NO_DATE = 1
OTHERS = 2.
**---计算输入日期的下一个月
DAT_L = DAT_L 1.
DAT1 = DAT_L (4).
DAT2 = DAT_L 4(2).
**---取历史单价表里面的标准价格
SELECT SINGLE STPRS
INTO P_STPRS
FROM MBEWH
WHERE MATNR = P_MATNR
AND BWKEY = P_WERKS
AND LFGJA = DAT1
AND LFMON = DAT2.
ENDFORM. " GET_BZJG_HISTORY