TABLES
:MARA
,marc
,mvke
,ckmlprkeph
,AUFK
.
TABLES : CKMLKEPH , CKMLCR .
data : BEGIN OF G_T_RESULT OCCURS 0 ,
MATNR LIKE MSEG -MATNR ,
MVGR2 LIKE MVKE -MVGR2 ,
MVGR3 LIKE MVKE -MVGR3 ,
NTGEW LIKE MARA -NTGEW ,
MENGE LIKE MSEG -MENGE ,
kst001 TYPE ckmlkeph -kst001 , "标准成本-主要材料
kst002 TYPE ckmlkeph -kst002 , "标准成本-包材
kst003 TYPE ckmlkeph -kst003 , "标准成本-制造费用
kst004 TYPE ckmlkeph -kst004 , "标准成本-半成品
maktx LIKE makt -maktx , "产品名称
bezei2 LIKE tvm2t -bezei , "大类
bezei3 LIKE tvm3t -bezei , "小类
END OF G_T_RESULT .
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE t1 .
SELECT-OPTIONS :s_werks FOR marc -werks . "公司代码
PARAMETERS :p_bdatj LIKE ckmlprkeph -bdatj DEFAULT sy -datum+0 ( 4 ) . "会计年度
SELECT-OPTIONS :s_poper FOR ckmlprkeph -poper NO -EXTENSION DEFAULT sy -datum+4 ( 2 ) , "会计期间 NO INTERVALS
s_matnr FOR mvke -matnr , "物料编码
s_mvgr1 FOR mvke -mvgr1 NO -DISPLAY , "品牌
s_mvgr2 FOR mvke -mvgr2 , "大类
s_mvgr3 FOR mvke -mvgr3 , "小类
s_mtart FOR mara -mtart DEFAULT 'FERT' NO -DISPLAY , "物料类型
s_auart FOR aufk -auart DEFAULT 'ZB01' NO -DISPLAY . "订单类型
* s_zcplx FOR zzt_mm_001-zcplx."产品分类
SELECTION-SCREEN END OF BLOCK blk1 .
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_werks -low .
PERFORM frm_onf4_werks USING 'S_WERKS-LOW' .
START-OF-SELECTION .
PERFORM frm_auth_check .
* PERFORM frm_select_data.
PERFORM frm_select_data1 .
PERFORM FRM_ADDED .
END-OF-SELECTION .
PERFORM frm_output_data .
*&---------------------------------------------------------------------*
*& Form FRM_SELECT_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_SELECT_DATA .
data : BEGIN OF L_T_MARA OCCURS 0 ,
MATNR LIKE MARA -MATNR ,
* WERKS LIKE MARA-WERKS,
NTGEW LIKE MARA -NTGEW ,
MVGR1 LIKE MVKE -MVGR1 ,
MVGR2 LIKE MVKE -MVGR2 ,
MVGR3 LIKE MVKE -MVGR3 ,
KALNR LIKE CKMLHD -KALNR ,
BWKEY LIKE CKMLHD -BWKEY ,
END OF L_T_MARA .
data : BEGIN OF L_T_AUFK OCCURS 0 ,
aufnr TYPE AUFK -AUFNR , "订单
auart TYPE aufk -auart , "订单类型
* txt "订单类型描述
werks TYPE afpo -dwerk , "工厂
* name1 "工厂描述
matnr TYPE afpo -matnr , "物料
* maktx "物料描述
* aufpl , "工序工艺路线
ablad TYPE afpo -WEMPF , "卸货点
wempf TYPE afpo -WEMPF , "收货方
END OF L_T_AUFK .
data : BEGIN OF L_T_MSEG OCCURS 0 ,
MBLNR LIKE MSEG -MBLNR ,
MJAHR LIKE MSEG -MJAHR ,
ZEILE LIKE MSEG -ZEILE ,
BWART LIKE MSEG -BWART ,
MATNR LIKE MSEG -MATNR ,
WERKS LIKE MSEG -WERKS ,
LGORT LIKE MSEG -LGORT ,
CHARG LIKE MSEG -CHARG ,
SHKZG LIKE MSEG -SHKZG ,
MENGE LIKE MSEG -MENGE ,
AUFNR LIKE MSEG -AUFNR ,
END OF L_T_MSEG .
data : BEGIN OF L_T_MKPF OCCURS 0 ,
MBLNR LIKE MKPF -MBLNR ,
MJAHR LIKE MKPF -MJAHR ,
BUDAT LIKE MKPF -BUDAT ,
END OF L_T_MKPF .
"用来计算选择屏幕年度和月份的第一天和最后一天
DATA :l_V_date1 TYPE sy -datum .
DATA :l_V_date2 TYPE sy -datum .
DATA :l_V_date3 TYPE sy -datum .
data : BEGIN OF L_T_TABLE1 OCCURS 0 ,
MATNR LIKE MSEG -MATNR ,
MENGE LIKE MSEG -MENGE ,
POPER like CKMLCR -POPER ,
KALNR LIKE CKMLHD -KALNR ,
MVGR2 LIKE MVKE -MVGR2 ,
MVGR3 LIKE MVKE -MVGR3 ,
NTGEW LIKE MARA -NTGEW ,
kst001 TYPE ckmlkeph -kst001 , "标准成本-主要材料
kst001_v TYPE ckmlkeph -kst001 , "实际成本-主要材料
kst002 TYPE ckmlkeph -kst002 , "标准成本-直接制造费用
kst002_v TYPE ckmlkeph -kst002 , "实际成本-直接制造费用
kst003 TYPE ckmlkeph -kst003 , "标准成本-包材
kst003_v TYPE ckmlkeph -kst003 , "实际成本-包材
kst005 TYPE ckmlkeph -kst005 , "标准成本-直接人工
kst005_v TYPE ckmlkeph -kst005 , "实际成本-直接人工
kst007 TYPE ckmlkeph -kst007 , "标准成本-间接制造费用
kst007_v TYPE ckmlkeph -kst007 , "实际成本-间接制造费用
END OF L_T_TABLE1 .
DATA :lt_ckmlprkeph TYPE TABLE OF ckmlprkeph WITH HEADER LINE .
DATA :lt_CKMLKEPH TYPE TABLE OF CKMLKEPH WITH HEADER LINE .
**********************************************************************`
SELECT
a ~matnr
a ~ntgew
k ~mvgr1
k ~mvgr2
k ~mvgr3
h ~kalnr "成本估算编号
h ~bwkey
INTO CORRESPONDING FIELDS OF TABLE L_T_MARA
FROM mara AS a INNER JOIN mvke AS k ON a ~matnr = k ~matnr
INNER JOIN ckmlhd AS h ON a ~matnr = h ~matnr
INNER JOIN tvko AS t ON k ~vkorg = t ~vkorg AND h ~bwkey = t ~bukrs
WHERE a ~matnr IN s_matnr AND
a ~mtart IN s_mtart AND
k ~mvgr1 IN s_mvgr1 AND
k ~mvgr2 IN s_mvgr2 AND
k ~mvgr3 IN s_mvgr3 AND
h ~bwkey IN s_werks
* AND k~mvgr2 <> ''
.
**********************************************************************
SELECT
t01 ~aufnr "订单
t01 ~auart "订单类型
* t07~txt "订单类型描述
t03 ~dwerk AS werks "工厂
* t05~name1 "工厂描述
t03 ~matnr "物料
* t06~maktx "物料描述
* t02~aufpl "工序工艺路线
t03 ~ablad "卸货点
t03 ~wempf "收货方
FROM aufk AS t01
* INNER JOIN afko AS t02 ON t01~aufnr = t02~aufnr
INNER JOIN afpo AS t03 ON t01 ~aufnr = t03 ~aufnr
INNER JOIN mara AS t04 ON t03 ~matnr = t04 ~matnr
* INNER JOIN t001w AS t05 ON t03~dwerk = t05~werks
* INNER JOIN makt AS t06 ON t03~matnr = t06~matnr AND t06~spras = '1'
* INNER JOIN t003p AS t07 ON t01~auart = t07~auart AND t07~spras = '1'
INTO CORRESPONDING FIELDS OF TABLE L_T_AUFK
WHERE
( t01 ~auart IN s_auart or t01 ~auart in ( 'ZB01' , 'ZB07' ) )
* AND t01~aufnr IN s_aufnr
AND t03 ~dwerk IN s_werks
AND t03 ~matnr IN s_matnr
AND t04 ~mtart IN s_mtart .
IF L_T_AUFK[] IS NOT INITIAL .
SELECT
MBLNR
MJAHR
ZEILE
BWART
MATNR
WERKS
LGORT
CHARG
SHKZG
MENGE
AUFNR
FROM mseg
INTO CORRESPONDING FIELDS OF TABLE L_T_MSEG
FOR ALL ENTRIES IN L_T_AUFK
WHERE MJAHR = p_bdatj
AND bwart IN ( '101' , '102' )
AND aufnr = L_T_AUFK -aufnr
* AND smbln = ''
.
IF L_T_MSEG[] IS NOT INITIAL .
SELECT
MBLNR
MJAHR
BUDAT
FROM mkpf
INTO CORRESPONDING FIELDS OF TABLE L_T_MKPF
FOR ALL ENTRIES IN L_T_MSEG
WHERE mblnr = L_T_MSEG -mblnr
AND mjahr = L_T_MSEG -mjahr .
ENDIF .
ENDIF .
DATA l_month ( 3 ) TYPE c .
l_month = s_poper -low .
SHIFT l_month LEFT DELETING LEADING '0' .
IF l_month < 10 .
CONCATENATE '0' l_month INTO l_month .
ENDIF .
"第一天
CONCATENATE p_bdatj l_month '01' INTO l_v_date1 .
IF s_poper -HIGH EQ '000' . ".IS NOT INITIAL.
"最后一天
CALL FUNCTION 'FIMA_DATE_CREATE'
EXPORTING
i_date = l_v_date1
i_flg_end_of_month = ' '
i_calendar_days = 0
i_set_last_day_of_month = 'X'
IMPORTING
e_date = l_v_date2 .
ELSE .
l_month = s_poper -HIGH .
SHIFT l_month LEFT DELETING LEADING '0' .
IF l_month < 10 .
CONCATENATE '0' l_month INTO l_month .
ENDIF .
CONCATENATE p_bdatj l_month '01' INTO l_v_date2 .
"最后一天
CALL FUNCTION 'FIMA_DATE_CREATE'
EXPORTING
i_date = l_v_date2
i_flg_end_of_month = ' '
i_calendar_days = 0
i_set_last_day_of_month = 'X'
IMPORTING
e_date = l_v_date2 .
ENDIF .
LOOP AT L_T_MSEG .
READ TABLE L_T_MARA WITH KEY MATNR = L_T_MSEG -MATNR .
IF SY -SUBRC NE 0 .
DELETE L_T_MSEG .
ENDIF .
ENDLOOP .
DELETE L_T_MKPF WHERE BUDAT NOT BETWEEN l_v_date1 AND l_v_date2 .
SORT L_T_MKPF BY MBLNR MJAHR .
LOOP AT L_T_MSEG .
READ TABLE L_T_MKPF WITH KEY MBLNR = L_T_MSEG -MBLNR MJAHR = L_T_MSEG -MJAHR BINARY SEARCH .
IF SY -SUBRC = 0 .
IF L_T_MSEG -SHKZG = 'H' .
L_T_TABLE1 -MATNR = L_T_MSEG -MATNR .
L_T_TABLE1 -MENGE = 0 - L_T_MSEG -MENGE .
L_T_TABLE1 -POPER = L_T_MKPF -BUDAT+4 ( 2 ) .
COLLECT L_T_TABLE1 .
CLEAR L_T_TABLE1 .
ELSE .
L_T_TABLE1 -MATNR = L_T_MSEG -MATNR .
L_T_TABLE1 -MENGE = L_T_MSEG -MENGE .
L_T_TABLE1 -POPER = L_T_MKPF -BUDAT+4 ( 2 ) .
COLLECT L_T_TABLE1 .
CLEAR L_T_TABLE1 .
ENDIF .
ENDIF .
ENDLOOP .
**********************************************************************成本取数
SORT l_t_table1 by matnr .
loop at L_T_MARA .
READ TABLE l_t_table1 WITH KEY matnr = L_T_MARA -matnr BINARY SEARCH .
if sy -subrc ne 0 .
delete L_T_MARA .
else .
* L_T_TABLE1-KALNR = L_T_MARA-KALNR.
* L_T_TABLE1-MVGR2 = L_T_MARA-MVGR2.
* L_T_TABLE1-MVGR3 = L_T_MARA-MVGR3.
* L_T_TABLE1-NTGEW = L_T_MARA-NTGEW.
* MODIFY l_t_table1 INDEX sy-tabix TRANSPORTING KALNR MVGR2 MVGR3 NTGEW.
endif .
ENDLOOP .
*loop at l_t_table1.
* READ TABLE L_T_MARA WITH KEY matnr = l_t_table1-matnr.
* if sy-subrc = 0.
* L_T_TABLE1-KALNR = L_T_MARA-KALNR.
* L_T_TABLE1-MVGR2 = L_T_MARA-MVGR2.
* L_T_TABLE1-MVGR3 = L_T_MARA-MVGR3.
* L_T_TABLE1-NTGEW = L_T_MARA-NTGEW.
* MODIFY l_t_table1 INDEX sy-tabix TRANSPORTING KALNR MVGR2 MVGR3 NTGEW.
* endif.
*endloop.
* SELECT t01~matnr"物料号
* t01~bwkey "评估范围
* t01~kalnr "没有数量结构的成本估算的成本估算编号
* t01~bwtar "评估类型
* t02~maktx "物料描述
* t03~mtart "物料类型
* t03~meins"单位
* INTO CORRESPONDING FIELDS OF TABLE lt_ckmlhd
* FROM ckmlhd AS t01
* INNER JOIN makt AS t02 ON t01~matnr = t02~matnr AND t02~spras = '1'
* INNER JOIN mara AS t03 ON t01~matnr = t03~matnr
* WHERE t01~matnr IN s_matnr
* AND t01~bwkey = p_werks
* AND t03~mtart IN s_mtart.
IF L_T_MARA[] IS NOT INITIAL .
* SELECT *
* INTO CORRESPONDING FIELDS OF TABLE lt_ckmlprkeph
* FROM ckmlprkeph "物料分类帐: 价格的成本组件分割 (要素0
* FOR ALL ENTRIES IN L_T_MARA
* WHERE kalnr = L_T_MARA-kalnr
* AND bdatj = p_bdatj "年度
* AND poper in s_poper "期间
* AND curtp = '10'
* AND prtyp = 'V'
* AND kkzst = space.
CLEAR lt_ckmlprkeph[] .
l_V_date3 = l_v_date1 - 1 .
SELECT *
INTO CORRESPONDING FIELDS OF TABLE lt_ckmlprkeph
FROM ckmlprkeph "物料分类帐: 价格的成本组件分割 (要素0
FOR ALL ENTRIES IN L_T_MARA
WHERE kalnr = L_T_MARA -kalnr
AND bdatj = l_V_date3+0 ( 4 ) "年度
AND poper = l_V_date3+4 ( 2 ) "期间
AND curtp = '10'
AND prtyp = 'S'
AND KKZST = space .
* SELECT *
* INTO CORRESPONDING FIELDS OF TABLE lt_CKMLKEPH
* FROM CKMLKEPH "物料分类帐; 成本组件分割 (要素)
* FOR ALL ENTRIES IN L_T_MARA
* WHERE kalnr = L_T_MARA-kalnr
* AND bdatj = l_V_date1+0(4) "年度
* AND poper = l_V_date1+4(2) "期间
* AND CATEG = 'ZU'
* AND PTYP = space
* AND kkzst = space.
** MLCCT = 'M'.
SELECT *
INTO CORRESPONDING FIELDS OF TABLE lt_CKMLKEPH
FROM CKMLKEPH "物料分类帐; 成本组件分割 (要素)
FOR ALL ENTRIES IN L_T_MARA
WHERE kalnr = L_T_MARA -kalnr
AND bdatj = l_V_date1+0 ( 4 ) "年度
AND poper = l_V_date1+4 ( 2 ) "期间
AND CATEG = 'ZU'
* AND MLCCT = 'E' 'M'
AND PTYP = 'BF'
AND kkzst = space .
* MLCCT = 'M'.
endif .
* CONCATENATE p_bdatj p_poper INTO l_now.
* LOOP AT lt_ckmlprkeph_s.
* CONCATENATE lt_ckmlprkeph_s-bdatj lt_ckmlprkeph_s-poper INTO l_cur.
* IF l_cur > l_now."如果大于查询期间,则删除
* DELETE lt_ckmlprkeph_s INDEX sy-tabix.
* ENDIF.
* ENDLOOP.
SORT lt_ckmlprkeph BY poper DESCENDING . "按年月排序倒序
loop at l_t_table1 .
READ TABLE L_T_MARA WITH KEY matnr = l_t_table1 -matnr .
if sy -subrc = 0 .
L_T_TABLE1 -KALNR = L_T_MARA -KALNR .
L_T_TABLE1 -MVGR2 = L_T_MARA -MVGR2 .
L_T_TABLE1 -MVGR3 = L_T_MARA -MVGR3 .
L_T_TABLE1 -NTGEW = L_T_MARA -NTGEW .
endif .
* READ TABLE lt_ckmlprkeph WITH KEY KALNR = L_T_TABLE1-KALNR poper = l_t_table1-POPER prtyp = 'V'.
READ TABLE lt_ckmlprkeph WITH KEY KALNR = L_T_TABLE1 -KALNR prtyp = 'S' .
IF SY -SUBRC = 0 .
L_T_TABLE1 -kst001_v = lt_ckmlprkeph -kst001 .
L_T_TABLE1 -kst002_v = lt_ckmlprkeph -kst002 .
L_T_TABLE1 -kst003_v = lt_ckmlprkeph -kst003 .
L_T_TABLE1 -kst005_v = lt_ckmlprkeph -kst005 .
L_T_TABLE1 -kst007_v = lt_ckmlprkeph -kst007 .
SELECT SINGLE * FROM CKMLCR WHERE kalnr = L_T_MARA -kalnr AND bdatj = l_V_date1+0 ( 4 ) AND poper = l_V_date1+4 ( 2 ) AND VPRSV = 'S' .
IF SY -SUBRC = 0 .
SELECT SINGLE
kst001
kst002
kst003
kst005
kst007
INTO (L_T_TABLE1 -kst001_v , L_T_TABLE1 -kst002_v , L_T_TABLE1 -kst003_v , L_T_TABLE1 -kst005_v , L_T_TABLE1 -kst007_v )
FROM ckmlprkeph
WHERE kalnr = L_T_MARA -kalnr
AND bdatj = l_V_date1+0 ( 4 ) "年度
AND poper = l_V_date1+4 ( 2 ) "期间
AND curtp = '10'
AND prtyp = 'S'
AND KKZST = space .
ENDIF .
modify L_T_TABLE1 TRANSPORTING kst001_v kst002_v kst003_v kst005_v kst007_v KALNR MVGR2 MVGR3 NTGEW .
ENDIF .
endloop .
LOOP AT L_T_TABLE1 .
G_T_RESULT -MATNR = L_T_TABLE1 -MATNR .
G_T_RESULT -MVGR2 = L_T_TABLE1 -MVGR2 .
G_T_RESULT -MVGR3 = L_T_TABLE1 -MVGR3 .
G_T_RESULT -NTGEW = L_T_TABLE1 -NTGEW * L_T_TABLE1 -MENGE .
G_T_RESULT -MENGE = L_T_TABLE1 -MENGE .
G_T_RESULT -KST001 = ( L_T_TABLE1 -kst001_v ) * G_T_RESULT -MENGE .
G_T_RESULT -KST002 = ( L_T_TABLE1 -kst003_v ) * G_T_RESULT -MENGE .
G_T_RESULT -KST003 = ( L_T_TABLE1 -kst002_v + L_T_TABLE1 -kst005_v + L_T_TABLE1 -kst007_v ) * G_T_RESULT -MENGE .
READ TABLE lt_CKMLKEPH WITH KEY KALNR = L_T_TABLE1 -KALNR POPER = L_T_TABLE1 -POPER MLCCT = 'E' .
IF SY -SUBRC = 0 .
G_T_RESULT -KST001 = ( L_T_TABLE1 -kst001_v ) * G_T_RESULT -MENGE + lt_CKMLKEPH -kst001 .
G_T_RESULT -KST002 = ( L_T_TABLE1 -kst003_v ) * G_T_RESULT -MENGE + lt_CKMLKEPH -kst003 .
G_T_RESULT -KST003 = G_T_RESULT -KST003 + ( lt_CKMLKEPH -kst002 + lt_CKMLKEPH -kst005 + lt_CKMLKEPH -kst007 ) .
ENDIF .
READ TABLE lt_CKMLKEPH WITH KEY KALNR = L_T_TABLE1 -KALNR POPER = L_T_TABLE1 -POPER MLCCT = 'M' .
IF SY -SUBRC = 0 .
G_T_RESULT -KST001 = G_T_RESULT -KST001 + lt_CKMLKEPH -kst001 .
G_T_RESULT -KST002 = G_T_RESULT -KST002 + lt_CKMLKEPH -kst003 .
G_T_RESULT -KST003 = G_T_RESULT -KST003 + ( lt_CKMLKEPH -kst002 + lt_CKMLKEPH -kst005 + lt_CKMLKEPH -kst007 ) .
ENDIF .
COLLECT G_T_RESULT .
CLEAR G_T_RESULT .
ENDLOOP .
DELETE G_T_RESULT WHERE MENGE = 0 .
LOOP AT G_T_RESULT .
G_T_RESULT -NTGEW = G_T_RESULT -NTGEW / G_T_RESULT -MENGE .
G_T_RESULT -KST001 = G_T_RESULT -KST001 . "* G_T_RESULT-MENGE.
G_T_RESULT -KST002 = G_T_RESULT -KST002 . "* G_T_RESULT-MENGE.
G_T_RESULT -KST003 = G_T_RESULT -KST003 . "* G_T_RESULT-MENGE.
SELECT SINGLE maktx INTO G_T_RESULT -maktx FROM makt WHERE matnr = G_T_RESULT -matnr .
SELECT SINGLE bezei INTO G_T_RESULT -bezei2 FROM tvm2t WHERE spras = sy -langu AND mvgr2 = G_T_RESULT -mvgr2 .
SELECT SINGLE bezei INTO G_T_RESULT -bezei3 FROM tvm3t WHERE spras = sy -langu AND mvgr3 = G_T_RESULT -mvgr3 .
modify G_T_RESULT . "TRANSPORTING maktx bezei2 bezei3
ENDLOOP .
ENDFORM . " FRM_SELECT_DATA
*&---------------------------------------------------------------------*
*& 包括 ZFIR_0017F01
*&---------------------------------------------------------------------*
FORM frm_onf4_werks USING p_field .
TYPES : BEGIN OF ty_t001w ,
werks TYPE t001w -werks ,
name1 TYPE t001w -name1 ,
END OF ty_t001w .
DATA :lt_t001w TYPE TABLE OF ty_t001w WITH HEADER LINE .
SELECT
werks
name1
FROM t001w
INTO TABLE lt_t001w
WHERE werks LIKE '10%'
AND spras = sy -langu .
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
* DDIC_STRUCTURE = ' '
retfield = 'WERKS' "预选值要填入的字段名
* PVALKEY = ' '
dynpprog = sy -repid
dynpnr = sy -dynnr
dynprofield = p_field " 此屏幕字段参数
value_org = 'S'
* multiple_choice = 'X'
callback_program = sy -repid
TABLES
value_tab = lt_t001w[] " 存放预选值清单的内表
* FIELD_TAB =
* DYNPFLD_MAPPING =
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3 .
ENDFORM . " frm_onf4_bukrs
*&---------------------------------------------------------------------*
*& Form FRM_AUTH_CHECK
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_AUTH_CHECK .
DATA lt_t001w LIKE TABLE OF t001w WITH HEADER LINE .
SELECT
werks
INTO CORRESPONDING FIELDS OF TABLE lt_t001w
FROM t001w
WHERE werks IN s_werks .
LOOP AT lt_t001w .
CALL FUNCTION 'ZZ_CHECK_REPAUTH'
EXPORTING
i_module = 'PP'
* i_bukrs = s_werks
i_werks = lt_t001w -werks
EXCEPTIONS
not_authorized = 1
no_module = 2
OTHERS = 3 .
IF sy -subrc <> 0 .
MESSAGE ID sy -msgid TYPE sy -msgty NUMBER sy -msgno
WITH sy -msgv1 sy -msgv2 sy -msgv3 sy -msgv4 .
ENDIF .
ENDLOOP .
ENDFORM . " FRM_AUTH_CHECK
*&---------------------------------------------------------------------*
*& Form FRM_OUTPUT_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_OUTPUT_DATA .
DATA : progname LIKE sy -repid ,
title ( 70 ) .
progname = sy -repid .
title = '生产成本明细表' .
DATA : gt_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE ,
gs_layout TYPE slis_layout_alv ,
* usercommand TYPE slis_fieldname VALUE 'USERCOMMAND1',
gt_sort TYPE slis_t_sortinfo_alv .
gs_layout -zebra = 'X' . "设置每行的背景颜色交错 显示。
gs_layout -colwidth_optimize = 'X' . "ALV输出时候自动优化宽 度
gs_layout -detail_popup = 'X' .
GT_FIELDCAT -FIELDNAME = 'MATNR' . GT_FIELDCAT -SELTEXT_M = '物料编号' . GT_FIELDCAT -NO_ZERO = 'X' . APPEND GT_FIELDCAT . CLEAR GT_FIELDCAT .
GT_FIELDCAT -FIELDNAME = 'MAKTX' . GT_FIELDCAT -SELTEXT_M = '产品名称' . APPEND GT_FIELDCAT . CLEAR GT_FIELDCAT .
GT_FIELDCAT -FIELDNAME = 'BEZEI2' . GT_FIELDCAT -SELTEXT_M = '类别' . APPEND GT_FIELDCAT . CLEAR GT_FIELDCAT .
GT_FIELDCAT -FIELDNAME = 'BEZEI3' . GT_FIELDCAT -SELTEXT_M = '剂型' . APPEND GT_FIELDCAT . CLEAR GT_FIELDCAT .
GT_FIELDCAT -FIELDNAME = 'MENGE' . GT_FIELDCAT -SELTEXT_M = '生产数量(件)' . APPEND GT_FIELDCAT . CLEAR GT_FIELDCAT .
GT_FIELDCAT -FIELDNAME = 'NTGEW' . GT_FIELDCAT -SELTEXT_M = '重量(千克)' . APPEND GT_FIELDCAT . CLEAR GT_FIELDCAT .
GT_FIELDCAT -FIELDNAME = 'KST001' . GT_FIELDCAT -SELTEXT_M = '原料' . APPEND GT_FIELDCAT . CLEAR GT_FIELDCAT .
GT_FIELDCAT -FIELDNAME = 'KST002' . GT_FIELDCAT -SELTEXT_M = '包装' . APPEND GT_FIELDCAT . CLEAR GT_FIELDCAT .
GT_FIELDCAT -FIELDNAME = 'KST004' . GT_FIELDCAT -SELTEXT_M = '半成品' . APPEND GT_FIELDCAT . CLEAR GT_FIELDCAT .
GT_FIELDCAT -FIELDNAME = 'KST003' . GT_FIELDCAT -SELTEXT_M = '制造费用' . APPEND GT_FIELDCAT . CLEAR GT_FIELDCAT .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = progname
is_layout = gs_layout
it_fieldcat = gt_fieldcat[]
i_grid_title = title
* i_callback_pf_status_set = 'PF_STATUS_SET1'
* i_callback_user_command = usercommand
* i_save = 'A'
TABLES
t_outtab = G_T_RESULT
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 . " FRM_OUTPUT_DATA
*&---------------------------------------------------------------------*
*& Form FRM_ADDED
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_ADDED .
DATA WT_TEMP LIKE ZZT_FI_005 .
WT_TEMP -DATUM = SY -DATUM .
WT_TEMP -UZEIT = SY -UZEIT .
WT_TEMP -UNAME = SY -UNAME .
WT_TEMP -TCODE = SY -TCODE .
WT_TEMP -CPROG = SY -CPROG .
WT_TEMP -BATCH = SY -BATCH .
WT_TEMP -CALLD = SY -CALLD .
CONCATENATE 'werks:' s_werks -LOW ',' s_werks -HIGH ';bdatj:' p_bdatj ';poper:' s_poper -LOW ',' s_poper -HIGH
';matnr:' s_matnr -LOW ',' s_matnr -HIGH ';mvgr2:' s_mvgr2 -LOW ',' s_mvgr2 -HIGH INTO WT_TEMP - TITLE .
MODIFY ZZT_FI_005 FROM WT_TEMP .
IF SY -SUBRC = 0 .
* IF sy-subrc <> 0.
* ROLLBACK WORK.
* ELSE.
COMMIT WORK .
ENDIF .
ENDFORM . " FRM_ADDED
*&---------------------------------------------------------------------*
*& Form FRM_SELECT_DATA1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_SELECT_DATA1 .
data : BEGIN OF L_T_MARA OCCURS 0 ,
MATNR LIKE MARA -MATNR ,
* WERKS LIKE MARA-WERKS,
NTGEW LIKE MARA -NTGEW ,
MVGR1 LIKE MVKE -MVGR1 ,
MVGR2 LIKE MVKE -MVGR2 ,
MVGR3 LIKE MVKE -MVGR3 ,
KALNR LIKE CKMLHD -KALNR ,
BWKEY LIKE CKMLHD -BWKEY ,
END OF L_T_MARA .
*data:BEGIN OF L_T_AUFK OCCURS 0,
* aufnr TYPE AUFK-AUFNR,"订单
* auart TYPE aufk-auart,"订单类型
** txt "订单类型描述
* werks TYPE afpo-dwerk,"工厂
** name1 "工厂描述
* matnr TYPE afpo-matnr,"物料
** maktx "物料描述
** aufpl , "工序工艺路线
* ablad TYPE afpo-WEMPF, "卸货点
* wempf TYPE afpo-WEMPF,"收货方
*
*END OF L_T_AUFK.
data : BEGIN OF L_T_MSEG OCCURS 0 ,
MBLNR LIKE MSEG -MBLNR ,
MJAHR LIKE MSEG -MJAHR ,
ZEILE LIKE MSEG -ZEILE ,
BWART LIKE MSEG -BWART ,
MATNR LIKE MSEG -MATNR ,
WERKS LIKE MSEG -WERKS ,
LGORT LIKE MSEG -LGORT ,
CHARG LIKE MSEG -CHARG ,
SHKZG LIKE MSEG -SHKZG ,
MENGE LIKE MSEG -MENGE ,
AUFNR LIKE MSEG -AUFNR ,
END OF L_T_MSEG .
data : BEGIN OF L_T_MKPF OCCURS 0 ,
MBLNR LIKE MKPF -MBLNR ,
MJAHR LIKE MKPF -MJAHR ,
BUDAT LIKE MKPF -BUDAT ,
END OF L_T_MKPF .
"用来计算选择屏幕年度和月份的第一天和最后一天
DATA :l_V_date1 TYPE sy -datum .
DATA :l_V_date2 TYPE sy -datum .
DATA l_month ( 3 ) TYPE c .
DATA :l_V_date3 TYPE sy -datum .
data : BEGIN OF L_T_TABLE1 OCCURS 0 ,
MATNR LIKE MSEG -MATNR ,
BDATJ LIKE CKMLCR -BDATJ , "记帐日期 YYYY
MENGE LIKE MSEG -MENGE ,
POPER like CKMLCR -POPER ,
KALNR LIKE CKMLHD -KALNR ,
MVGR2 LIKE MVKE -MVGR2 ,
MVGR3 LIKE MVKE -MVGR3 ,
NTGEW LIKE MARA -NTGEW ,
kst001 TYPE ckmlkeph -kst001 , "标准成本-主要材料
kst001_v TYPE ckmlkeph -kst001 , "实际成本-主要材料
kst002 TYPE ckmlkeph -kst002 , "标准成本-直接制造费用
kst002_v TYPE ckmlkeph -kst002 , "实际成本-直接制造费用
kst003 TYPE ckmlkeph -kst003 , "标准成本-包材
kst003_v TYPE ckmlkeph -kst003 , "实际成本-包材
kst005 TYPE ckmlkeph -kst005 , "标准成本-直接人工
kst005_v TYPE ckmlkeph -kst005 , "实际成本-直接人工
kst007 TYPE ckmlkeph -kst007 , "标准成本-间接制造费用
kst007_v TYPE ckmlkeph -kst007 , "实际成本-间接制造费用
END OF L_T_TABLE1 .
data L_T_TABLE2 like TABLE OF L_T_TABLE1 WITH HEADER LINE .
DATA :lt_ckmlprkeph TYPE TABLE OF ckmlprkeph WITH HEADER LINE .
DATA :lt_CKMLKEPH TYPE TABLE OF CKMLKEPH WITH HEADER LINE .
DATA :lt_CKMLPP TYPE TABLE OF CKMLPP WITH HEADER LINE .
**********************************************************************`
SELECT
a ~matnr
a ~ntgew
k ~mvgr1
k ~mvgr2
k ~mvgr3
h ~kalnr "成本估算编号
h ~bwkey
INTO CORRESPONDING FIELDS OF TABLE L_T_MARA
FROM mara AS a INNER JOIN mvke AS k ON a ~matnr = k ~matnr
INNER JOIN ckmlhd AS h ON a ~matnr = h ~matnr
INNER JOIN tvko AS t ON k ~vkorg = t ~vkorg AND h ~bwkey = t ~bukrs
WHERE a ~matnr IN s_matnr AND
a ~mtart IN s_mtart AND
k ~mvgr1 IN s_mvgr1 AND
k ~mvgr2 IN s_mvgr2 AND
k ~mvgr3 IN s_mvgr3 AND
h ~bwkey IN s_werks
* AND k~mvgr2 <> ''
.
* SELECT *
* INTO CORRESPONDING FIELDS OF TABLE lt_ckmlprkeph
* FROM ckmlprkeph "物料分类帐: 价格的成本组件分割 (要素0
* FOR ALL ENTRIES IN L_T_MARA
* WHERE kalnr = L_T_MARA-kalnr
* AND bdatj = p_bdatj "年度
* AND poper in s_poper "期间
* AND curtp = '10'
* AND prtyp = 'S'
* AND kkzst = space.
*
* DATA l_month(3) TYPE c.
* l_month = s_poper-low.
* SHIFT l_month LEFT DELETING LEADING '0'.
*
* IF l_month < 10.
* CONCATENATE '0' l_month INTO l_month.
* ENDIF.
* "第一天
* CONCATENATE p_bdatj l_month '01' INTO l_v_date1.
*
* l_v_date2 = l_v_date1 - 1.
* SELECT *
* APPENDING CORRESPONDING FIELDS OF TABLE lt_ckmlprkeph
* FROM ckmlprkeph "物料分类帐: 价格的成本组件分割 (要素0
* FOR ALL ENTRIES IN L_T_MARA
* WHERE kalnr = L_T_MARA-kalnr
* AND bdatj = l_V_date3+0(4) "年度
* AND poper = l_V_date3+4(2) "期间
* AND curtp = '10'
* AND prtyp = 'S'
* AND KKZST = space.
SELECT *
INTO CORRESPONDING FIELDS OF TABLE lt_CKMLPP
FROM CKMLPP
FOR ALL ENTRIES IN L_T_MARA
WHERE kalnr = L_T_MARA -kalnr
AND bdatj = p_bdatj "年度
AND poper in s_poper . "期间.
loop at lt_CKMLPP .
READ TABLE L_T_MARA WITH KEY kalnr = lt_CKMLPP -kalnr .
if sy -subrc = 0 .
L_T_TABLE1 -MATNR = L_T_MARA -MATNR .
L_T_TABLE1 -BDATJ = lt_CKMLPP -BDATJ .
L_T_TABLE1 -POPER = lt_CKMLPP -POPER .
L_T_TABLE1 -MENGE = lt_CKMLPP -ZUKUMO - lt_CKMLPP -EKKUMO .
L_T_TABLE1 -KALNR = L_T_MARA -KALNR .
L_T_TABLE1 -MVGR2 = L_T_MARA -MVGR2 .
L_T_TABLE1 -MVGR3 = L_T_MARA -MVGR3 .
L_T_TABLE1 -NTGEW = L_T_MARA -NTGEW .
append L_T_TABLE1 .
clear L_T_TABLE1 .
endif .
ENDLOOP .
delete L_T_TABLE1 WHERE menge = 0 .
loop at L_T_TABLE1 .
CLEAR ckmlprkeph .
SELECT SINGLE * FROM CKMLCR WHERE kalnr = L_T_TABLE1 -kalnr AND bdatj = L_T_TABLE1 -BDATJ AND poper = L_T_TABLE1 -POPER AND VPRSV = 'S' .
IF SY -SUBRC = 0 .
SELECT SINGLE * FROM ckmlprkeph WHERE kalnr = L_T_TABLE1 -kalnr AND bdatj = L_T_TABLE1 -BDATJ AND poper = L_T_TABLE1 -POPER AND curtp = '10' AND prtyp = 'S' AND KKZST = space .
ELSE .
l_month = L_T_TABLE1 -POPER .
SHIFT l_month LEFT DELETING LEADING '0' .
IF l_month < 10 .
CONCATENATE '0' l_month INTO l_month .
ENDIF .
"第一天
CONCATENATE L_T_TABLE1 -BDATJ l_month '01' INTO l_v_date1 .
l_v_date2 = l_v_date1 - 1 .
SELECT SINGLE * FROM ckmlprkeph WHERE kalnr = L_T_TABLE1 -kalnr AND bdatj = l_V_date2+0 ( 4 ) AND poper = l_V_date2+4 ( 2 ) AND curtp = '10' AND prtyp = 'S' AND KKZST = 'X' .
IF SY -SUBRC = 0 .
CLEAR ckmlprkeph .
SELECT SINGLE * FROM ckmlprkeph WHERE kalnr = L_T_TABLE1 -kalnr AND bdatj = l_V_date2+0 ( 4 ) AND poper = l_V_date2+4 ( 2 ) AND curtp = '10' AND prtyp = 'S' AND KKZST = space .
ELSE .
CLEAR ckmlprkeph .
SELECT SINGLE * FROM ckmlprkeph WHERE kalnr = L_T_TABLE1 -kalnr AND bdatj = L_T_TABLE1 -BDATJ AND poper = L_T_TABLE1 -POPER AND curtp = '10' AND prtyp = 'S' AND KKZST = space .
ENDIF .
ENDIF .
L_T_TABLE1 -kst001 = ckmlprkeph -kst001 * L_T_TABLE1 -MENGE .
L_T_TABLE1 -kst002 = ckmlprkeph -kst002 * L_T_TABLE1 -MENGE .
L_T_TABLE1 -kst003 = ckmlprkeph -kst003 * L_T_TABLE1 -MENGE .
L_T_TABLE1 -kst005 = ckmlprkeph -kst005 * L_T_TABLE1 -MENGE .
L_T_TABLE1 -kst007 = ckmlprkeph -kst007 * L_T_TABLE1 -MENGE .
L_T_TABLE1 -kst001_V = L_T_TABLE1 -kst001 .
L_T_TABLE1 -kst002_V = L_T_TABLE1 -kst002 .
L_T_TABLE1 -kst003_V = L_T_TABLE1 -kst003 .
L_T_TABLE1 -kst005_V = L_T_TABLE1 -kst005 .
L_T_TABLE1 -kst007_V = L_T_TABLE1 -kst007 .
SELECT SINGLE * FROM CKMLKEPH WHERE KALNR = L_T_TABLE1 -KALNR AND POPER = L_T_TABLE1 -POPER AND CATEG = 'ZU' AND PTYP = 'BF' AND MLCCT = 'E' AND kkzst = space .
IF SY -SUBRC = 0 .
L_T_TABLE1 -kst001_V = L_T_TABLE1 -kst001_V + CKMLKEPH -kst001 .
L_T_TABLE1 -kst002_V = L_T_TABLE1 -kst002_V + CKMLKEPH -kst002 .
L_T_TABLE1 -kst003_V = L_T_TABLE1 -kst003_V + CKMLKEPH -kst003 .
L_T_TABLE1 -kst005_V = L_T_TABLE1 -kst005_V + CKMLKEPH -kst005 .
L_T_TABLE1 -kst007_V = L_T_TABLE1 -kst007_V + CKMLKEPH -kst007 .
ENDIF .
SELECT SINGLE * FROM CKMLKEPH WHERE KALNR = L_T_TABLE1 -KALNR AND POPER = L_T_TABLE1 -POPER AND CATEG = 'ZU' AND PTYP = 'BF' AND MLCCT = 'M' AND kkzst = space .
IF SY -SUBRC = 0 .
L_T_TABLE1 -kst001_V = L_T_TABLE1 -kst001_V + CKMLKEPH -kst001 .
L_T_TABLE1 -kst002_V = L_T_TABLE1 -kst002_V + CKMLKEPH -kst002 .
L_T_TABLE1 -kst003_V = L_T_TABLE1 -kst003_V + CKMLKEPH -kst003 .
L_T_TABLE1 -kst005_V = L_T_TABLE1 -kst005_V + CKMLKEPH -kst005 .
L_T_TABLE1 -kst007_V = L_T_TABLE1 -kst007_V + CKMLKEPH -kst007 .
ENDIF .
G_T_RESULT -MATNR = L_T_TABLE1 -MATNR .
G_T_RESULT -MVGR2 = L_T_TABLE1 -MVGR2 .
G_T_RESULT -MVGR3 = L_T_TABLE1 -MVGR3 .
G_T_RESULT -MENGE = L_T_TABLE1 -MENGE .
G_T_RESULT -NTGEW = L_T_TABLE1 -NTGEW * L_T_TABLE1 -MENGE .
G_T_RESULT -KST001 = L_T_TABLE1 -kst001_V .
G_T_RESULT -KST002 = L_T_TABLE1 -kst003_V .
G_T_RESULT -KST003 = L_T_TABLE1 -kst002_V + L_T_TABLE1 -kst005_V + L_T_TABLE1 -kst007_V .
COLLECT G_T_RESULT .
CLEAR G_T_RESULT .
MODIFY L_T_TABLE1 .
CLEAR L_T_TABLE1 .
ENDLOOP .
LOOP AT G_T_RESULT .
G_T_RESULT -NTGEW = G_T_RESULT -NTGEW / G_T_RESULT -MENGE .
SELECT SINGLE maktx INTO G_T_RESULT -maktx FROM makt WHERE matnr = G_T_RESULT -matnr .
SELECT SINGLE bezei INTO G_T_RESULT -bezei2 FROM tvm2t WHERE spras = sy -langu AND mvgr2 = G_T_RESULT -mvgr2 .
SELECT SINGLE bezei INTO G_T_RESULT -bezei3 FROM tvm3t WHERE spras = sy -langu AND mvgr3 = G_T_RESULT -mvgr3 .
modify G_T_RESULT . "TRANSPORTING maktx bezei2 bezei3
ENDLOOP .
ENDFORM .
TABLES : CKMLKEPH , CKMLCR .
data : BEGIN OF G_T_RESULT OCCURS 0 ,
MATNR LIKE MSEG -MATNR ,
MVGR2 LIKE MVKE -MVGR2 ,
MVGR3 LIKE MVKE -MVGR3 ,
NTGEW LIKE MARA -NTGEW ,
MENGE LIKE MSEG -MENGE ,
kst001 TYPE ckmlkeph -kst001 , "标准成本-主要材料
kst002 TYPE ckmlkeph -kst002 , "标准成本-包材
kst003 TYPE ckmlkeph -kst003 , "标准成本-制造费用
kst004 TYPE ckmlkeph -kst004 , "标准成本-半成品
maktx LIKE makt -maktx , "产品名称
bezei2 LIKE tvm2t -bezei , "大类
bezei3 LIKE tvm3t -bezei , "小类
END OF G_T_RESULT .
SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE t1 .
SELECT-OPTIONS :s_werks FOR marc -werks . "公司代码
PARAMETERS :p_bdatj LIKE ckmlprkeph -bdatj DEFAULT sy -datum+0 ( 4 ) . "会计年度
SELECT-OPTIONS :s_poper FOR ckmlprkeph -poper NO -EXTENSION DEFAULT sy -datum+4 ( 2 ) , "会计期间 NO INTERVALS
s_matnr FOR mvke -matnr , "物料编码
s_mvgr1 FOR mvke -mvgr1 NO -DISPLAY , "品牌
s_mvgr2 FOR mvke -mvgr2 , "大类
s_mvgr3 FOR mvke -mvgr3 , "小类
s_mtart FOR mara -mtart DEFAULT 'FERT' NO -DISPLAY , "物料类型
s_auart FOR aufk -auart DEFAULT 'ZB01' NO -DISPLAY . "订单类型
* s_zcplx FOR zzt_mm_001-zcplx."产品分类
SELECTION-SCREEN END OF BLOCK blk1 .
AT SELECTION-SCREEN ON VALUE-REQUEST FOR s_werks -low .
PERFORM frm_onf4_werks USING 'S_WERKS-LOW' .
START-OF-SELECTION .
PERFORM frm_auth_check .
* PERFORM frm_select_data.
PERFORM frm_select_data1 .
PERFORM FRM_ADDED .
END-OF-SELECTION .
PERFORM frm_output_data .
*&---------------------------------------------------------------------*
*& Form FRM_SELECT_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_SELECT_DATA .
data : BEGIN OF L_T_MARA OCCURS 0 ,
MATNR LIKE MARA -MATNR ,
* WERKS LIKE MARA-WERKS,
NTGEW LIKE MARA -NTGEW ,
MVGR1 LIKE MVKE -MVGR1 ,
MVGR2 LIKE MVKE -MVGR2 ,
MVGR3 LIKE MVKE -MVGR3 ,
KALNR LIKE CKMLHD -KALNR ,
BWKEY LIKE CKMLHD -BWKEY ,
END OF L_T_MARA .
data : BEGIN OF L_T_AUFK OCCURS 0 ,
aufnr TYPE AUFK -AUFNR , "订单
auart TYPE aufk -auart , "订单类型
* txt "订单类型描述
werks TYPE afpo -dwerk , "工厂
* name1 "工厂描述
matnr TYPE afpo -matnr , "物料
* maktx "物料描述
* aufpl , "工序工艺路线
ablad TYPE afpo -WEMPF , "卸货点
wempf TYPE afpo -WEMPF , "收货方
END OF L_T_AUFK .
data : BEGIN OF L_T_MSEG OCCURS 0 ,
MBLNR LIKE MSEG -MBLNR ,
MJAHR LIKE MSEG -MJAHR ,
ZEILE LIKE MSEG -ZEILE ,
BWART LIKE MSEG -BWART ,
MATNR LIKE MSEG -MATNR ,
WERKS LIKE MSEG -WERKS ,
LGORT LIKE MSEG -LGORT ,
CHARG LIKE MSEG -CHARG ,
SHKZG LIKE MSEG -SHKZG ,
MENGE LIKE MSEG -MENGE ,
AUFNR LIKE MSEG -AUFNR ,
END OF L_T_MSEG .
data : BEGIN OF L_T_MKPF OCCURS 0 ,
MBLNR LIKE MKPF -MBLNR ,
MJAHR LIKE MKPF -MJAHR ,
BUDAT LIKE MKPF -BUDAT ,
END OF L_T_MKPF .
"用来计算选择屏幕年度和月份的第一天和最后一天
DATA :l_V_date1 TYPE sy -datum .
DATA :l_V_date2 TYPE sy -datum .
DATA :l_V_date3 TYPE sy -datum .
data : BEGIN OF L_T_TABLE1 OCCURS 0 ,
MATNR LIKE MSEG -MATNR ,
MENGE LIKE MSEG -MENGE ,
POPER like CKMLCR -POPER ,
KALNR LIKE CKMLHD -KALNR ,
MVGR2 LIKE MVKE -MVGR2 ,
MVGR3 LIKE MVKE -MVGR3 ,
NTGEW LIKE MARA -NTGEW ,
kst001 TYPE ckmlkeph -kst001 , "标准成本-主要材料
kst001_v TYPE ckmlkeph -kst001 , "实际成本-主要材料
kst002 TYPE ckmlkeph -kst002 , "标准成本-直接制造费用
kst002_v TYPE ckmlkeph -kst002 , "实际成本-直接制造费用
kst003 TYPE ckmlkeph -kst003 , "标准成本-包材
kst003_v TYPE ckmlkeph -kst003 , "实际成本-包材
kst005 TYPE ckmlkeph -kst005 , "标准成本-直接人工
kst005_v TYPE ckmlkeph -kst005 , "实际成本-直接人工
kst007 TYPE ckmlkeph -kst007 , "标准成本-间接制造费用
kst007_v TYPE ckmlkeph -kst007 , "实际成本-间接制造费用
END OF L_T_TABLE1 .
DATA :lt_ckmlprkeph TYPE TABLE OF ckmlprkeph WITH HEADER LINE .
DATA :lt_CKMLKEPH TYPE TABLE OF CKMLKEPH WITH HEADER LINE .
**********************************************************************`
SELECT
a ~matnr
a ~ntgew
k ~mvgr1
k ~mvgr2
k ~mvgr3
h ~kalnr "成本估算编号
h ~bwkey
INTO CORRESPONDING FIELDS OF TABLE L_T_MARA
FROM mara AS a INNER JOIN mvke AS k ON a ~matnr = k ~matnr
INNER JOIN ckmlhd AS h ON a ~matnr = h ~matnr
INNER JOIN tvko AS t ON k ~vkorg = t ~vkorg AND h ~bwkey = t ~bukrs
WHERE a ~matnr IN s_matnr AND
a ~mtart IN s_mtart AND
k ~mvgr1 IN s_mvgr1 AND
k ~mvgr2 IN s_mvgr2 AND
k ~mvgr3 IN s_mvgr3 AND
h ~bwkey IN s_werks
* AND k~mvgr2 <> ''
.
**********************************************************************
SELECT
t01 ~aufnr "订单
t01 ~auart "订单类型
* t07~txt "订单类型描述
t03 ~dwerk AS werks "工厂
* t05~name1 "工厂描述
t03 ~matnr "物料
* t06~maktx "物料描述
* t02~aufpl "工序工艺路线
t03 ~ablad "卸货点
t03 ~wempf "收货方
FROM aufk AS t01
* INNER JOIN afko AS t02 ON t01~aufnr = t02~aufnr
INNER JOIN afpo AS t03 ON t01 ~aufnr = t03 ~aufnr
INNER JOIN mara AS t04 ON t03 ~matnr = t04 ~matnr
* INNER JOIN t001w AS t05 ON t03~dwerk = t05~werks
* INNER JOIN makt AS t06 ON t03~matnr = t06~matnr AND t06~spras = '1'
* INNER JOIN t003p AS t07 ON t01~auart = t07~auart AND t07~spras = '1'
INTO CORRESPONDING FIELDS OF TABLE L_T_AUFK
WHERE
( t01 ~auart IN s_auart or t01 ~auart in ( 'ZB01' , 'ZB07' ) )
* AND t01~aufnr IN s_aufnr
AND t03 ~dwerk IN s_werks
AND t03 ~matnr IN s_matnr
AND t04 ~mtart IN s_mtart .
IF L_T_AUFK[] IS NOT INITIAL .
SELECT
MBLNR
MJAHR
ZEILE
BWART
MATNR
WERKS
LGORT
CHARG
SHKZG
MENGE
AUFNR
FROM mseg
INTO CORRESPONDING FIELDS OF TABLE L_T_MSEG
FOR ALL ENTRIES IN L_T_AUFK
WHERE MJAHR = p_bdatj
AND bwart IN ( '101' , '102' )
AND aufnr = L_T_AUFK -aufnr
* AND smbln = ''
.
IF L_T_MSEG[] IS NOT INITIAL .
SELECT
MBLNR
MJAHR
BUDAT
FROM mkpf
INTO CORRESPONDING FIELDS OF TABLE L_T_MKPF
FOR ALL ENTRIES IN L_T_MSEG
WHERE mblnr = L_T_MSEG -mblnr
AND mjahr = L_T_MSEG -mjahr .
ENDIF .
ENDIF .
DATA l_month ( 3 ) TYPE c .
l_month = s_poper -low .
SHIFT l_month LEFT DELETING LEADING '0' .
IF l_month < 10 .
CONCATENATE '0' l_month INTO l_month .
ENDIF .
"第一天
CONCATENATE p_bdatj l_month '01' INTO l_v_date1 .
IF s_poper -HIGH EQ '000' . ".IS NOT INITIAL.
"最后一天
CALL FUNCTION 'FIMA_DATE_CREATE'
EXPORTING
i_date = l_v_date1
i_flg_end_of_month = ' '
i_calendar_days = 0
i_set_last_day_of_month = 'X'
IMPORTING
e_date = l_v_date2 .
ELSE .
l_month = s_poper -HIGH .
SHIFT l_month LEFT DELETING LEADING '0' .
IF l_month < 10 .
CONCATENATE '0' l_month INTO l_month .
ENDIF .
CONCATENATE p_bdatj l_month '01' INTO l_v_date2 .
"最后一天
CALL FUNCTION 'FIMA_DATE_CREATE'
EXPORTING
i_date = l_v_date2
i_flg_end_of_month = ' '
i_calendar_days = 0
i_set_last_day_of_month = 'X'
IMPORTING
e_date = l_v_date2 .
ENDIF .
LOOP AT L_T_MSEG .
READ TABLE L_T_MARA WITH KEY MATNR = L_T_MSEG -MATNR .
IF SY -SUBRC NE 0 .
DELETE L_T_MSEG .
ENDIF .
ENDLOOP .
DELETE L_T_MKPF WHERE BUDAT NOT BETWEEN l_v_date1 AND l_v_date2 .
SORT L_T_MKPF BY MBLNR MJAHR .
LOOP AT L_T_MSEG .
READ TABLE L_T_MKPF WITH KEY MBLNR = L_T_MSEG -MBLNR MJAHR = L_T_MSEG -MJAHR BINARY SEARCH .
IF SY -SUBRC = 0 .
IF L_T_MSEG -SHKZG = 'H' .
L_T_TABLE1 -MATNR = L_T_MSEG -MATNR .
L_T_TABLE1 -MENGE = 0 - L_T_MSEG -MENGE .
L_T_TABLE1 -POPER = L_T_MKPF -BUDAT+4 ( 2 ) .
COLLECT L_T_TABLE1 .
CLEAR L_T_TABLE1 .
ELSE .
L_T_TABLE1 -MATNR = L_T_MSEG -MATNR .
L_T_TABLE1 -MENGE = L_T_MSEG -MENGE .
L_T_TABLE1 -POPER = L_T_MKPF -BUDAT+4 ( 2 ) .
COLLECT L_T_TABLE1 .
CLEAR L_T_TABLE1 .
ENDIF .
ENDIF .
ENDLOOP .
**********************************************************************成本取数
SORT l_t_table1 by matnr .
loop at L_T_MARA .
READ TABLE l_t_table1 WITH KEY matnr = L_T_MARA -matnr BINARY SEARCH .
if sy -subrc ne 0 .
delete L_T_MARA .
else .
* L_T_TABLE1-KALNR = L_T_MARA-KALNR.
* L_T_TABLE1-MVGR2 = L_T_MARA-MVGR2.
* L_T_TABLE1-MVGR3 = L_T_MARA-MVGR3.
* L_T_TABLE1-NTGEW = L_T_MARA-NTGEW.
* MODIFY l_t_table1 INDEX sy-tabix TRANSPORTING KALNR MVGR2 MVGR3 NTGEW.
endif .
ENDLOOP .
*loop at l_t_table1.
* READ TABLE L_T_MARA WITH KEY matnr = l_t_table1-matnr.
* if sy-subrc = 0.
* L_T_TABLE1-KALNR = L_T_MARA-KALNR.
* L_T_TABLE1-MVGR2 = L_T_MARA-MVGR2.
* L_T_TABLE1-MVGR3 = L_T_MARA-MVGR3.
* L_T_TABLE1-NTGEW = L_T_MARA-NTGEW.
* MODIFY l_t_table1 INDEX sy-tabix TRANSPORTING KALNR MVGR2 MVGR3 NTGEW.
* endif.
*endloop.
* SELECT t01~matnr"物料号
* t01~bwkey "评估范围
* t01~kalnr "没有数量结构的成本估算的成本估算编号
* t01~bwtar "评估类型
* t02~maktx "物料描述
* t03~mtart "物料类型
* t03~meins"单位
* INTO CORRESPONDING FIELDS OF TABLE lt_ckmlhd
* FROM ckmlhd AS t01
* INNER JOIN makt AS t02 ON t01~matnr = t02~matnr AND t02~spras = '1'
* INNER JOIN mara AS t03 ON t01~matnr = t03~matnr
* WHERE t01~matnr IN s_matnr
* AND t01~bwkey = p_werks
* AND t03~mtart IN s_mtart.
IF L_T_MARA[] IS NOT INITIAL .
* SELECT *
* INTO CORRESPONDING FIELDS OF TABLE lt_ckmlprkeph
* FROM ckmlprkeph "物料分类帐: 价格的成本组件分割 (要素0
* FOR ALL ENTRIES IN L_T_MARA
* WHERE kalnr = L_T_MARA-kalnr
* AND bdatj = p_bdatj "年度
* AND poper in s_poper "期间
* AND curtp = '10'
* AND prtyp = 'V'
* AND kkzst = space.
CLEAR lt_ckmlprkeph[] .
l_V_date3 = l_v_date1 - 1 .
SELECT *
INTO CORRESPONDING FIELDS OF TABLE lt_ckmlprkeph
FROM ckmlprkeph "物料分类帐: 价格的成本组件分割 (要素0
FOR ALL ENTRIES IN L_T_MARA
WHERE kalnr = L_T_MARA -kalnr
AND bdatj = l_V_date3+0 ( 4 ) "年度
AND poper = l_V_date3+4 ( 2 ) "期间
AND curtp = '10'
AND prtyp = 'S'
AND KKZST = space .
* SELECT *
* INTO CORRESPONDING FIELDS OF TABLE lt_CKMLKEPH
* FROM CKMLKEPH "物料分类帐; 成本组件分割 (要素)
* FOR ALL ENTRIES IN L_T_MARA
* WHERE kalnr = L_T_MARA-kalnr
* AND bdatj = l_V_date1+0(4) "年度
* AND poper = l_V_date1+4(2) "期间
* AND CATEG = 'ZU'
* AND PTYP = space
* AND kkzst = space.
** MLCCT = 'M'.
SELECT *
INTO CORRESPONDING FIELDS OF TABLE lt_CKMLKEPH
FROM CKMLKEPH "物料分类帐; 成本组件分割 (要素)
FOR ALL ENTRIES IN L_T_MARA
WHERE kalnr = L_T_MARA -kalnr
AND bdatj = l_V_date1+0 ( 4 ) "年度
AND poper = l_V_date1+4 ( 2 ) "期间
AND CATEG = 'ZU'
* AND MLCCT = 'E' 'M'
AND PTYP = 'BF'
AND kkzst = space .
* MLCCT = 'M'.
endif .
* CONCATENATE p_bdatj p_poper INTO l_now.
* LOOP AT lt_ckmlprkeph_s.
* CONCATENATE lt_ckmlprkeph_s-bdatj lt_ckmlprkeph_s-poper INTO l_cur.
* IF l_cur > l_now."如果大于查询期间,则删除
* DELETE lt_ckmlprkeph_s INDEX sy-tabix.
* ENDIF.
* ENDLOOP.
SORT lt_ckmlprkeph BY poper DESCENDING . "按年月排序倒序
loop at l_t_table1 .
READ TABLE L_T_MARA WITH KEY matnr = l_t_table1 -matnr .
if sy -subrc = 0 .
L_T_TABLE1 -KALNR = L_T_MARA -KALNR .
L_T_TABLE1 -MVGR2 = L_T_MARA -MVGR2 .
L_T_TABLE1 -MVGR3 = L_T_MARA -MVGR3 .
L_T_TABLE1 -NTGEW = L_T_MARA -NTGEW .
endif .
* READ TABLE lt_ckmlprkeph WITH KEY KALNR = L_T_TABLE1-KALNR poper = l_t_table1-POPER prtyp = 'V'.
READ TABLE lt_ckmlprkeph WITH KEY KALNR = L_T_TABLE1 -KALNR prtyp = 'S' .
IF SY -SUBRC = 0 .
L_T_TABLE1 -kst001_v = lt_ckmlprkeph -kst001 .
L_T_TABLE1 -kst002_v = lt_ckmlprkeph -kst002 .
L_T_TABLE1 -kst003_v = lt_ckmlprkeph -kst003 .
L_T_TABLE1 -kst005_v = lt_ckmlprkeph -kst005 .
L_T_TABLE1 -kst007_v = lt_ckmlprkeph -kst007 .
SELECT SINGLE * FROM CKMLCR WHERE kalnr = L_T_MARA -kalnr AND bdatj = l_V_date1+0 ( 4 ) AND poper = l_V_date1+4 ( 2 ) AND VPRSV = 'S' .
IF SY -SUBRC = 0 .
SELECT SINGLE
kst001
kst002
kst003
kst005
kst007
INTO (L_T_TABLE1 -kst001_v , L_T_TABLE1 -kst002_v , L_T_TABLE1 -kst003_v , L_T_TABLE1 -kst005_v , L_T_TABLE1 -kst007_v )
FROM ckmlprkeph
WHERE kalnr = L_T_MARA -kalnr
AND bdatj = l_V_date1+0 ( 4 ) "年度
AND poper = l_V_date1+4 ( 2 ) "期间
AND curtp = '10'
AND prtyp = 'S'
AND KKZST = space .
ENDIF .
modify L_T_TABLE1 TRANSPORTING kst001_v kst002_v kst003_v kst005_v kst007_v KALNR MVGR2 MVGR3 NTGEW .
ENDIF .
endloop .
LOOP AT L_T_TABLE1 .
G_T_RESULT -MATNR = L_T_TABLE1 -MATNR .
G_T_RESULT -MVGR2 = L_T_TABLE1 -MVGR2 .
G_T_RESULT -MVGR3 = L_T_TABLE1 -MVGR3 .
G_T_RESULT -NTGEW = L_T_TABLE1 -NTGEW * L_T_TABLE1 -MENGE .
G_T_RESULT -MENGE = L_T_TABLE1 -MENGE .
G_T_RESULT -KST001 = ( L_T_TABLE1 -kst001_v ) * G_T_RESULT -MENGE .
G_T_RESULT -KST002 = ( L_T_TABLE1 -kst003_v ) * G_T_RESULT -MENGE .
G_T_RESULT -KST003 = ( L_T_TABLE1 -kst002_v + L_T_TABLE1 -kst005_v + L_T_TABLE1 -kst007_v ) * G_T_RESULT -MENGE .
READ TABLE lt_CKMLKEPH WITH KEY KALNR = L_T_TABLE1 -KALNR POPER = L_T_TABLE1 -POPER MLCCT = 'E' .
IF SY -SUBRC = 0 .
G_T_RESULT -KST001 = ( L_T_TABLE1 -kst001_v ) * G_T_RESULT -MENGE + lt_CKMLKEPH -kst001 .
G_T_RESULT -KST002 = ( L_T_TABLE1 -kst003_v ) * G_T_RESULT -MENGE + lt_CKMLKEPH -kst003 .
G_T_RESULT -KST003 = G_T_RESULT -KST003 + ( lt_CKMLKEPH -kst002 + lt_CKMLKEPH -kst005 + lt_CKMLKEPH -kst007 ) .
ENDIF .
READ TABLE lt_CKMLKEPH WITH KEY KALNR = L_T_TABLE1 -KALNR POPER = L_T_TABLE1 -POPER MLCCT = 'M' .
IF SY -SUBRC = 0 .
G_T_RESULT -KST001 = G_T_RESULT -KST001 + lt_CKMLKEPH -kst001 .
G_T_RESULT -KST002 = G_T_RESULT -KST002 + lt_CKMLKEPH -kst003 .
G_T_RESULT -KST003 = G_T_RESULT -KST003 + ( lt_CKMLKEPH -kst002 + lt_CKMLKEPH -kst005 + lt_CKMLKEPH -kst007 ) .
ENDIF .
COLLECT G_T_RESULT .
CLEAR G_T_RESULT .
ENDLOOP .
DELETE G_T_RESULT WHERE MENGE = 0 .
LOOP AT G_T_RESULT .
G_T_RESULT -NTGEW = G_T_RESULT -NTGEW / G_T_RESULT -MENGE .
G_T_RESULT -KST001 = G_T_RESULT -KST001 . "* G_T_RESULT-MENGE.
G_T_RESULT -KST002 = G_T_RESULT -KST002 . "* G_T_RESULT-MENGE.
G_T_RESULT -KST003 = G_T_RESULT -KST003 . "* G_T_RESULT-MENGE.
SELECT SINGLE maktx INTO G_T_RESULT -maktx FROM makt WHERE matnr = G_T_RESULT -matnr .
SELECT SINGLE bezei INTO G_T_RESULT -bezei2 FROM tvm2t WHERE spras = sy -langu AND mvgr2 = G_T_RESULT -mvgr2 .
SELECT SINGLE bezei INTO G_T_RESULT -bezei3 FROM tvm3t WHERE spras = sy -langu AND mvgr3 = G_T_RESULT -mvgr3 .
modify G_T_RESULT . "TRANSPORTING maktx bezei2 bezei3
ENDLOOP .
ENDFORM . " FRM_SELECT_DATA
*&---------------------------------------------------------------------*
*& 包括 ZFIR_0017F01
*&---------------------------------------------------------------------*
FORM frm_onf4_werks USING p_field .
TYPES : BEGIN OF ty_t001w ,
werks TYPE t001w -werks ,
name1 TYPE t001w -name1 ,
END OF ty_t001w .
DATA :lt_t001w TYPE TABLE OF ty_t001w WITH HEADER LINE .
SELECT
werks
name1
FROM t001w
INTO TABLE lt_t001w
WHERE werks LIKE '10%'
AND spras = sy -langu .
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
* DDIC_STRUCTURE = ' '
retfield = 'WERKS' "预选值要填入的字段名
* PVALKEY = ' '
dynpprog = sy -repid
dynpnr = sy -dynnr
dynprofield = p_field " 此屏幕字段参数
value_org = 'S'
* multiple_choice = 'X'
callback_program = sy -repid
TABLES
value_tab = lt_t001w[] " 存放预选值清单的内表
* FIELD_TAB =
* DYNPFLD_MAPPING =
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3 .
ENDFORM . " frm_onf4_bukrs
*&---------------------------------------------------------------------*
*& Form FRM_AUTH_CHECK
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_AUTH_CHECK .
DATA lt_t001w LIKE TABLE OF t001w WITH HEADER LINE .
SELECT
werks
INTO CORRESPONDING FIELDS OF TABLE lt_t001w
FROM t001w
WHERE werks IN s_werks .
LOOP AT lt_t001w .
CALL FUNCTION 'ZZ_CHECK_REPAUTH'
EXPORTING
i_module = 'PP'
* i_bukrs = s_werks
i_werks = lt_t001w -werks
EXCEPTIONS
not_authorized = 1
no_module = 2
OTHERS = 3 .
IF sy -subrc <> 0 .
MESSAGE ID sy -msgid TYPE sy -msgty NUMBER sy -msgno
WITH sy -msgv1 sy -msgv2 sy -msgv3 sy -msgv4 .
ENDIF .
ENDLOOP .
ENDFORM . " FRM_AUTH_CHECK
*&---------------------------------------------------------------------*
*& Form FRM_OUTPUT_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_OUTPUT_DATA .
DATA : progname LIKE sy -repid ,
title ( 70 ) .
progname = sy -repid .
title = '生产成本明细表' .
DATA : gt_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE ,
gs_layout TYPE slis_layout_alv ,
* usercommand TYPE slis_fieldname VALUE 'USERCOMMAND1',
gt_sort TYPE slis_t_sortinfo_alv .
gs_layout -zebra = 'X' . "设置每行的背景颜色交错 显示。
gs_layout -colwidth_optimize = 'X' . "ALV输出时候自动优化宽 度
gs_layout -detail_popup = 'X' .
GT_FIELDCAT -FIELDNAME = 'MATNR' . GT_FIELDCAT -SELTEXT_M = '物料编号' . GT_FIELDCAT -NO_ZERO = 'X' . APPEND GT_FIELDCAT . CLEAR GT_FIELDCAT .
GT_FIELDCAT -FIELDNAME = 'MAKTX' . GT_FIELDCAT -SELTEXT_M = '产品名称' . APPEND GT_FIELDCAT . CLEAR GT_FIELDCAT .
GT_FIELDCAT -FIELDNAME = 'BEZEI2' . GT_FIELDCAT -SELTEXT_M = '类别' . APPEND GT_FIELDCAT . CLEAR GT_FIELDCAT .
GT_FIELDCAT -FIELDNAME = 'BEZEI3' . GT_FIELDCAT -SELTEXT_M = '剂型' . APPEND GT_FIELDCAT . CLEAR GT_FIELDCAT .
GT_FIELDCAT -FIELDNAME = 'MENGE' . GT_FIELDCAT -SELTEXT_M = '生产数量(件)' . APPEND GT_FIELDCAT . CLEAR GT_FIELDCAT .
GT_FIELDCAT -FIELDNAME = 'NTGEW' . GT_FIELDCAT -SELTEXT_M = '重量(千克)' . APPEND GT_FIELDCAT . CLEAR GT_FIELDCAT .
GT_FIELDCAT -FIELDNAME = 'KST001' . GT_FIELDCAT -SELTEXT_M = '原料' . APPEND GT_FIELDCAT . CLEAR GT_FIELDCAT .
GT_FIELDCAT -FIELDNAME = 'KST002' . GT_FIELDCAT -SELTEXT_M = '包装' . APPEND GT_FIELDCAT . CLEAR GT_FIELDCAT .
GT_FIELDCAT -FIELDNAME = 'KST004' . GT_FIELDCAT -SELTEXT_M = '半成品' . APPEND GT_FIELDCAT . CLEAR GT_FIELDCAT .
GT_FIELDCAT -FIELDNAME = 'KST003' . GT_FIELDCAT -SELTEXT_M = '制造费用' . APPEND GT_FIELDCAT . CLEAR GT_FIELDCAT .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = progname
is_layout = gs_layout
it_fieldcat = gt_fieldcat[]
i_grid_title = title
* i_callback_pf_status_set = 'PF_STATUS_SET1'
* i_callback_user_command = usercommand
* i_save = 'A'
TABLES
t_outtab = G_T_RESULT
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 . " FRM_OUTPUT_DATA
*&---------------------------------------------------------------------*
*& Form FRM_ADDED
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_ADDED .
DATA WT_TEMP LIKE ZZT_FI_005 .
WT_TEMP -DATUM = SY -DATUM .
WT_TEMP -UZEIT = SY -UZEIT .
WT_TEMP -UNAME = SY -UNAME .
WT_TEMP -TCODE = SY -TCODE .
WT_TEMP -CPROG = SY -CPROG .
WT_TEMP -BATCH = SY -BATCH .
WT_TEMP -CALLD = SY -CALLD .
CONCATENATE 'werks:' s_werks -LOW ',' s_werks -HIGH ';bdatj:' p_bdatj ';poper:' s_poper -LOW ',' s_poper -HIGH
';matnr:' s_matnr -LOW ',' s_matnr -HIGH ';mvgr2:' s_mvgr2 -LOW ',' s_mvgr2 -HIGH INTO WT_TEMP - TITLE .
MODIFY ZZT_FI_005 FROM WT_TEMP .
IF SY -SUBRC = 0 .
* IF sy-subrc <> 0.
* ROLLBACK WORK.
* ELSE.
COMMIT WORK .
ENDIF .
ENDFORM . " FRM_ADDED
*&---------------------------------------------------------------------*
*& Form FRM_SELECT_DATA1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_SELECT_DATA1 .
data : BEGIN OF L_T_MARA OCCURS 0 ,
MATNR LIKE MARA -MATNR ,
* WERKS LIKE MARA-WERKS,
NTGEW LIKE MARA -NTGEW ,
MVGR1 LIKE MVKE -MVGR1 ,
MVGR2 LIKE MVKE -MVGR2 ,
MVGR3 LIKE MVKE -MVGR3 ,
KALNR LIKE CKMLHD -KALNR ,
BWKEY LIKE CKMLHD -BWKEY ,
END OF L_T_MARA .
*data:BEGIN OF L_T_AUFK OCCURS 0,
* aufnr TYPE AUFK-AUFNR,"订单
* auart TYPE aufk-auart,"订单类型
** txt "订单类型描述
* werks TYPE afpo-dwerk,"工厂
** name1 "工厂描述
* matnr TYPE afpo-matnr,"物料
** maktx "物料描述
** aufpl , "工序工艺路线
* ablad TYPE afpo-WEMPF, "卸货点
* wempf TYPE afpo-WEMPF,"收货方
*
*END OF L_T_AUFK.
data : BEGIN OF L_T_MSEG OCCURS 0 ,
MBLNR LIKE MSEG -MBLNR ,
MJAHR LIKE MSEG -MJAHR ,
ZEILE LIKE MSEG -ZEILE ,
BWART LIKE MSEG -BWART ,
MATNR LIKE MSEG -MATNR ,
WERKS LIKE MSEG -WERKS ,
LGORT LIKE MSEG -LGORT ,
CHARG LIKE MSEG -CHARG ,
SHKZG LIKE MSEG -SHKZG ,
MENGE LIKE MSEG -MENGE ,
AUFNR LIKE MSEG -AUFNR ,
END OF L_T_MSEG .
data : BEGIN OF L_T_MKPF OCCURS 0 ,
MBLNR LIKE MKPF -MBLNR ,
MJAHR LIKE MKPF -MJAHR ,
BUDAT LIKE MKPF -BUDAT ,
END OF L_T_MKPF .
"用来计算选择屏幕年度和月份的第一天和最后一天
DATA :l_V_date1 TYPE sy -datum .
DATA :l_V_date2 TYPE sy -datum .
DATA l_month ( 3 ) TYPE c .
DATA :l_V_date3 TYPE sy -datum .
data : BEGIN OF L_T_TABLE1 OCCURS 0 ,
MATNR LIKE MSEG -MATNR ,
BDATJ LIKE CKMLCR -BDATJ , "记帐日期 YYYY
MENGE LIKE MSEG -MENGE ,
POPER like CKMLCR -POPER ,
KALNR LIKE CKMLHD -KALNR ,
MVGR2 LIKE MVKE -MVGR2 ,
MVGR3 LIKE MVKE -MVGR3 ,
NTGEW LIKE MARA -NTGEW ,
kst001 TYPE ckmlkeph -kst001 , "标准成本-主要材料
kst001_v TYPE ckmlkeph -kst001 , "实际成本-主要材料
kst002 TYPE ckmlkeph -kst002 , "标准成本-直接制造费用
kst002_v TYPE ckmlkeph -kst002 , "实际成本-直接制造费用
kst003 TYPE ckmlkeph -kst003 , "标准成本-包材
kst003_v TYPE ckmlkeph -kst003 , "实际成本-包材
kst005 TYPE ckmlkeph -kst005 , "标准成本-直接人工
kst005_v TYPE ckmlkeph -kst005 , "实际成本-直接人工
kst007 TYPE ckmlkeph -kst007 , "标准成本-间接制造费用
kst007_v TYPE ckmlkeph -kst007 , "实际成本-间接制造费用
END OF L_T_TABLE1 .
data L_T_TABLE2 like TABLE OF L_T_TABLE1 WITH HEADER LINE .
DATA :lt_ckmlprkeph TYPE TABLE OF ckmlprkeph WITH HEADER LINE .
DATA :lt_CKMLKEPH TYPE TABLE OF CKMLKEPH WITH HEADER LINE .
DATA :lt_CKMLPP TYPE TABLE OF CKMLPP WITH HEADER LINE .
**********************************************************************`
SELECT
a ~matnr
a ~ntgew
k ~mvgr1
k ~mvgr2
k ~mvgr3
h ~kalnr "成本估算编号
h ~bwkey
INTO CORRESPONDING FIELDS OF TABLE L_T_MARA
FROM mara AS a INNER JOIN mvke AS k ON a ~matnr = k ~matnr
INNER JOIN ckmlhd AS h ON a ~matnr = h ~matnr
INNER JOIN tvko AS t ON k ~vkorg = t ~vkorg AND h ~bwkey = t ~bukrs
WHERE a ~matnr IN s_matnr AND
a ~mtart IN s_mtart AND
k ~mvgr1 IN s_mvgr1 AND
k ~mvgr2 IN s_mvgr2 AND
k ~mvgr3 IN s_mvgr3 AND
h ~bwkey IN s_werks
* AND k~mvgr2 <> ''
.
* SELECT *
* INTO CORRESPONDING FIELDS OF TABLE lt_ckmlprkeph
* FROM ckmlprkeph "物料分类帐: 价格的成本组件分割 (要素0
* FOR ALL ENTRIES IN L_T_MARA
* WHERE kalnr = L_T_MARA-kalnr
* AND bdatj = p_bdatj "年度
* AND poper in s_poper "期间
* AND curtp = '10'
* AND prtyp = 'S'
* AND kkzst = space.
*
* DATA l_month(3) TYPE c.
* l_month = s_poper-low.
* SHIFT l_month LEFT DELETING LEADING '0'.
*
* IF l_month < 10.
* CONCATENATE '0' l_month INTO l_month.
* ENDIF.
* "第一天
* CONCATENATE p_bdatj l_month '01' INTO l_v_date1.
*
* l_v_date2 = l_v_date1 - 1.
* SELECT *
* APPENDING CORRESPONDING FIELDS OF TABLE lt_ckmlprkeph
* FROM ckmlprkeph "物料分类帐: 价格的成本组件分割 (要素0
* FOR ALL ENTRIES IN L_T_MARA
* WHERE kalnr = L_T_MARA-kalnr
* AND bdatj = l_V_date3+0(4) "年度
* AND poper = l_V_date3+4(2) "期间
* AND curtp = '10'
* AND prtyp = 'S'
* AND KKZST = space.
SELECT *
INTO CORRESPONDING FIELDS OF TABLE lt_CKMLPP
FROM CKMLPP
FOR ALL ENTRIES IN L_T_MARA
WHERE kalnr = L_T_MARA -kalnr
AND bdatj = p_bdatj "年度
AND poper in s_poper . "期间.
loop at lt_CKMLPP .
READ TABLE L_T_MARA WITH KEY kalnr = lt_CKMLPP -kalnr .
if sy -subrc = 0 .
L_T_TABLE1 -MATNR = L_T_MARA -MATNR .
L_T_TABLE1 -BDATJ = lt_CKMLPP -BDATJ .
L_T_TABLE1 -POPER = lt_CKMLPP -POPER .
L_T_TABLE1 -MENGE = lt_CKMLPP -ZUKUMO - lt_CKMLPP -EKKUMO .
L_T_TABLE1 -KALNR = L_T_MARA -KALNR .
L_T_TABLE1 -MVGR2 = L_T_MARA -MVGR2 .
L_T_TABLE1 -MVGR3 = L_T_MARA -MVGR3 .
L_T_TABLE1 -NTGEW = L_T_MARA -NTGEW .
append L_T_TABLE1 .
clear L_T_TABLE1 .
endif .
ENDLOOP .
delete L_T_TABLE1 WHERE menge = 0 .
loop at L_T_TABLE1 .
CLEAR ckmlprkeph .
SELECT SINGLE * FROM CKMLCR WHERE kalnr = L_T_TABLE1 -kalnr AND bdatj = L_T_TABLE1 -BDATJ AND poper = L_T_TABLE1 -POPER AND VPRSV = 'S' .
IF SY -SUBRC = 0 .
SELECT SINGLE * FROM ckmlprkeph WHERE kalnr = L_T_TABLE1 -kalnr AND bdatj = L_T_TABLE1 -BDATJ AND poper = L_T_TABLE1 -POPER AND curtp = '10' AND prtyp = 'S' AND KKZST = space .
ELSE .
l_month = L_T_TABLE1 -POPER .
SHIFT l_month LEFT DELETING LEADING '0' .
IF l_month < 10 .
CONCATENATE '0' l_month INTO l_month .
ENDIF .
"第一天
CONCATENATE L_T_TABLE1 -BDATJ l_month '01' INTO l_v_date1 .
l_v_date2 = l_v_date1 - 1 .
SELECT SINGLE * FROM ckmlprkeph WHERE kalnr = L_T_TABLE1 -kalnr AND bdatj = l_V_date2+0 ( 4 ) AND poper = l_V_date2+4 ( 2 ) AND curtp = '10' AND prtyp = 'S' AND KKZST = 'X' .
IF SY -SUBRC = 0 .
CLEAR ckmlprkeph .
SELECT SINGLE * FROM ckmlprkeph WHERE kalnr = L_T_TABLE1 -kalnr AND bdatj = l_V_date2+0 ( 4 ) AND poper = l_V_date2+4 ( 2 ) AND curtp = '10' AND prtyp = 'S' AND KKZST = space .
ELSE .
CLEAR ckmlprkeph .
SELECT SINGLE * FROM ckmlprkeph WHERE kalnr = L_T_TABLE1 -kalnr AND bdatj = L_T_TABLE1 -BDATJ AND poper = L_T_TABLE1 -POPER AND curtp = '10' AND prtyp = 'S' AND KKZST = space .
ENDIF .
ENDIF .
L_T_TABLE1 -kst001 = ckmlprkeph -kst001 * L_T_TABLE1 -MENGE .
L_T_TABLE1 -kst002 = ckmlprkeph -kst002 * L_T_TABLE1 -MENGE .
L_T_TABLE1 -kst003 = ckmlprkeph -kst003 * L_T_TABLE1 -MENGE .
L_T_TABLE1 -kst005 = ckmlprkeph -kst005 * L_T_TABLE1 -MENGE .
L_T_TABLE1 -kst007 = ckmlprkeph -kst007 * L_T_TABLE1 -MENGE .
L_T_TABLE1 -kst001_V = L_T_TABLE1 -kst001 .
L_T_TABLE1 -kst002_V = L_T_TABLE1 -kst002 .
L_T_TABLE1 -kst003_V = L_T_TABLE1 -kst003 .
L_T_TABLE1 -kst005_V = L_T_TABLE1 -kst005 .
L_T_TABLE1 -kst007_V = L_T_TABLE1 -kst007 .
SELECT SINGLE * FROM CKMLKEPH WHERE KALNR = L_T_TABLE1 -KALNR AND POPER = L_T_TABLE1 -POPER AND CATEG = 'ZU' AND PTYP = 'BF' AND MLCCT = 'E' AND kkzst = space .
IF SY -SUBRC = 0 .
L_T_TABLE1 -kst001_V = L_T_TABLE1 -kst001_V + CKMLKEPH -kst001 .
L_T_TABLE1 -kst002_V = L_T_TABLE1 -kst002_V + CKMLKEPH -kst002 .
L_T_TABLE1 -kst003_V = L_T_TABLE1 -kst003_V + CKMLKEPH -kst003 .
L_T_TABLE1 -kst005_V = L_T_TABLE1 -kst005_V + CKMLKEPH -kst005 .
L_T_TABLE1 -kst007_V = L_T_TABLE1 -kst007_V + CKMLKEPH -kst007 .
ENDIF .
SELECT SINGLE * FROM CKMLKEPH WHERE KALNR = L_T_TABLE1 -KALNR AND POPER = L_T_TABLE1 -POPER AND CATEG = 'ZU' AND PTYP = 'BF' AND MLCCT = 'M' AND kkzst = space .
IF SY -SUBRC = 0 .
L_T_TABLE1 -kst001_V = L_T_TABLE1 -kst001_V + CKMLKEPH -kst001 .
L_T_TABLE1 -kst002_V = L_T_TABLE1 -kst002_V + CKMLKEPH -kst002 .
L_T_TABLE1 -kst003_V = L_T_TABLE1 -kst003_V + CKMLKEPH -kst003 .
L_T_TABLE1 -kst005_V = L_T_TABLE1 -kst005_V + CKMLKEPH -kst005 .
L_T_TABLE1 -kst007_V = L_T_TABLE1 -kst007_V + CKMLKEPH -kst007 .
ENDIF .
G_T_RESULT -MATNR = L_T_TABLE1 -MATNR .
G_T_RESULT -MVGR2 = L_T_TABLE1 -MVGR2 .
G_T_RESULT -MVGR3 = L_T_TABLE1 -MVGR3 .
G_T_RESULT -MENGE = L_T_TABLE1 -MENGE .
G_T_RESULT -NTGEW = L_T_TABLE1 -NTGEW * L_T_TABLE1 -MENGE .
G_T_RESULT -KST001 = L_T_TABLE1 -kst001_V .
G_T_RESULT -KST002 = L_T_TABLE1 -kst003_V .
G_T_RESULT -KST003 = L_T_TABLE1 -kst002_V + L_T_TABLE1 -kst005_V + L_T_TABLE1 -kst007_V .
COLLECT G_T_RESULT .
CLEAR G_T_RESULT .
MODIFY L_T_TABLE1 .
CLEAR L_T_TABLE1 .
ENDLOOP .
LOOP AT G_T_RESULT .
G_T_RESULT -NTGEW = G_T_RESULT -NTGEW / G_T_RESULT -MENGE .
SELECT SINGLE maktx INTO G_T_RESULT -maktx FROM makt WHERE matnr = G_T_RESULT -matnr .
SELECT SINGLE bezei INTO G_T_RESULT -bezei2 FROM tvm2t WHERE spras = sy -langu AND mvgr2 = G_T_RESULT -mvgr2 .
SELECT SINGLE bezei INTO G_T_RESULT -bezei3 FROM tvm3t WHERE spras = sy -langu AND mvgr3 = G_T_RESULT -mvgr3 .
modify G_T_RESULT . "TRANSPORTING maktx bezei2 bezei3
ENDLOOP .
ENDFORM .