点击此处---> 群内免费提供SAP练习系统(在群公告中)
加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)
http://www.itpub.net/thread-2091351-1-1.html
注意事项写在前面:
1.我做的这个增强有bug,比如:
a.价格改成 100 MRKO 开票
b.冲销411K 形成412K
c.价格改成200 对412K凭证 做MRKO 开冲销发票
这时正向发票与反向发票就不平了.
这里可以修改下代码:412K的凭证取对应411K的凭证的金额进行反向会计凭证生成.
由于最近比较忙,还没有做调整,财务凭证看起来就头疼.
2.寄售物料凭证冲销时是实时取的表[RKWA] 里面的金额,出口的地方不还原为411K凭证金额的话,去看412K对应的会计凭证会有惊喜.
说人话就是造成 411K 与 412K 的会计凭证不平
3.如果当月差异过大,进行平均分摊会造成成本失真,所以有必要让财务每月关注差异,并进行分摊操作.
SAP 寄售发票 正常流程说明:1.创建寄售采购订单:ME21N 订单上无价格
2.寄售转自有:MIGO 411K (需要寄售采购信息记录)
3.MRKO 对411K收货凭证,按照凭证收货金额形成会计凭证
4.如果寄售发票开错,需要冲销则需要MIGO: 取消对应411K凭证
5.MRKO 对冲销的412K凭证形成会计凭证
业务需求:
1.要求供应商送大量物资到生产现场,并要求不占用库存资金.
2.物资价格波动很大,客户不愿意每日维护寄售采购价格
3.每月会与供应商协商一个开票价格,对使用的原料进行开票处理
系统需求点:
1.MRKO开票时可以按照最新金额进行开票
2.开票可冲销,修改金额重新开
难点:
1.形成的差异不能进入物料分类账,只能进入主营业务成本.
实现过程:
1.创建自建表 [ZTMM_JSJG 寄售价格]
2.对MRKO做增强
a.增强查询显示:效果是,在MRKO选择显示进行查询时,总金额为 [凭证数量 * 自定义表单价]
SE38 输入程序:RMVKON00
在 FORM rkwa_partitionieren TABLES it_rkwa TYPE typ_tab_rkwa it_block TYPE typ_tab_block.
我的SAP版本是:461行
开始的位置增加显示增强
FORM rkwa_partitionieren TABLES it_rkwa TYPE typ_tab_rkwa
it_block TYPE typ_tab_block.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""$"$\SE:(1) Form RKWA_PARTITIONIEREN, Start A
*$*$-Start: (1)---------------------------------------------------------------------------------$*$*
ENHANCEMENT 1 ZEMM_RMVKON00. "active version
* MRKO 增强,在结算时,使用配置表中价格 替换物料移动凭证金额
DATA: lt_ztmm_jsjg TYPE STANDARD TABLE OF ztmm_jsjg INITIAL SIZE 0 WITH HEADER LINE,
lv_date TYPE datum.
FIELD-SYMBOLS: <fs_rkwa> TYPE rkwa.
lv_date = sy-datum.
LOOP AT it_rkwa ASSIGNING <fs_rkwa> .
REFRESH: lt_ztmm_jsjg.
SELECT * INTO TABLE lt_ztmm_jsjg
FROM ztmm_jsjg
WHERE matnr EQ <fs_rkwa>-matnr
AND lifnr EQ <fs_rkwa>-lifnr
AND werks EQ <fs_rkwa>-werks
AND datbi GE lv_date.
IF sy-subrc EQ 0.
SORT lt_ztmm_jsjg BY datab DESCENDING.
LOOP AT lt_ztmm_jsjg WHERE datab LE lv_date.
<fs_rkwa>-wrbtr = <fs_rkwa>-bstmg * lt_ztmm_jsjg-netpr.
EXIT.
ENDLOOP.
ENDIF.
ENDLOOP.
ENDENHANCEMENT.
*$*$-End: (1)---------------------------------------------------------------------------------$*$*
复制代码
b.增强凭证生成:效果是 物料凭证金额完全抵扣,同时将产生的差异写入主营业务成本科目中.并记录物料号,凭证号,供应商号,以便财务手工分摊差异
SMOD --> RMVKON00 --> EXIT_RMVKON00_001
IF sy-tcode = 'MRKO'.
CLEAR sdmbtr.
sbuzei = lines( t_bseg ).
*获取调整前 RKWA的值
SELECT * INTO CORRESPONDING FIELDS OF TABLE tm_rkwa FROM rkwa FOR ALL ENTRIES IN t_rkwa
WHERE mblnr = t_rkwa-mblnr
AND mjahr = t_rkwa-mjahr
AND zeile = t_rkwa-zeile.
LOOP AT tm_rkwa.
CLEAR:szuonr,t_bseg,sdmbtr,t_rkwa.
*读取内存表 t_rkwa 将显示值修改回凭证金额 否则冲销物料凭证时,将取该数量
READ TABLE t_rkwa WITH KEY mblnr = tm_rkwa-mblnr mjahr = tm_rkwa-mjahr zeile = tm_rkwa-zeile.
IF sy-subrc = 0 AND t_rkwa-wrbtr <> tm_rkwa-wrbtr.
"将rkwa 数量改回原值
t_rkwa-wrbtr = tm_rkwa-wrbtr.
MODIFY t_rkwa TRANSPORTING wrbtr
WHERE mblnr = tm_rkwa-mblnr
AND mjahr = tm_rkwa-mjahr
AND zeile = tm_rkwa-zeile.
CONCATENATE tm_rkwa-mblnr tm_rkwa-mjahr INTO szuonr.
READ TABLE t_bseg WITH KEY zuonr = szuonr.
IF sy-subrc = 0.
CASE tm_rkwa-shkzg.
WHEN 'H'."正向
sdmbtr = tm_rkwa-wrbtr - t_bseg-wrbtr .
t_bseg-wrbtr = tm_rkwa-wrbtr.
t_bseg-txbfw = tm_rkwa-wrbtr.
t_bseg-rewwr = tm_rkwa-wrbtr.
IF sdmbtr < 0 . "负: 50 H 正:40 S
MODIFY t_bseg TRANSPORTING wrbtr txbfw rewwr
WHERE bukrs = t_bseg-bukrs
AND belnr = t_bseg-belnr
AND gjahr = t_bseg-gjahr
AND buzei = t_bseg-buzei.
t_bseg-buzid = 'P'.
t_bseg-bschl = '40'.
t_bseg-shkzg = 'S'.
t_bseg-dmbtr = 0 - sdmbtr.
t_bseg-wrbtr = 0 - sdmbtr.
t_bseg-pswbt = 0 - sdmbtr.
t_bseg-txbfw = '0'.
t_bseg-ktosl = ''.
CONCATENATE 'MRKO差异结转 ' szuonr INTO t_bseg-sgtxt .
t_bseg-vorgn = 'RFBU'.
t_bseg-saknr = '6401990000'.
t_bseg-hkont = '6401990000'.
t_bseg-lifnr = tm_rkwa-lifnr.
t_bseg-bustw = ''.
t_bseg-rewwr = '0'.
sbuzei = sbuzei + 1 .
t_bseg-buzei = sbuzei.
APPEND t_bseg.
ENDIF.
IF sdmbtr > 0 . "负: 50 H 正:40 S
MODIFY t_bseg TRANSPORTING wrbtr txbfw rewwr
WHERE bukrs = t_bseg-bukrs
AND belnr = t_bseg-belnr
AND gjahr = t_bseg-gjahr
AND buzei = t_bseg-buzei.
t_bseg-buzid = 'P'.
t_bseg-bschl = '50'.
t_bseg-shkzg = 'H'.
t_bseg-dmbtr = sdmbtr.
t_bseg-wrbtr = sdmbtr.
t_bseg-pswbt = sdmbtr.
t_bseg-txbfw = '0'.
t_bseg-ktosl = ''.
CONCATENATE 'MRKO差异结转 ' szuonr INTO t_bseg-sgtxt .
t_bseg-vorgn = 'RFBU'.
t_bseg-saknr = '6401990000'.
t_bseg-hkont = '6401990000'.
t_bseg-lifnr = tm_rkwa-lifnr.
t_bseg-bustw = ''.
t_bseg-rewwr = '0'.
sbuzei = sbuzei + 1 .
t_bseg-buzei = sbuzei.
APPEND t_bseg.
ENDIF.
WHEN 'S'."逆向
sdmbtr = tm_rkwa-wrbtr - t_bseg-wrbtr.
t_bseg-wrbtr = tm_rkwa-wrbtr.
t_bseg-txbfw = tm_rkwa-wrbtr.
t_bseg-rewwr = tm_rkwa-wrbtr.
IF sdmbtr > 0 . "负: 50 H 正:40 S
MODIFY t_bseg TRANSPORTING wrbtr txbfw rewwr
WHERE bukrs = t_bseg-bukrs
AND belnr = t_bseg-belnr
AND gjahr = t_bseg-gjahr
AND buzei = t_bseg-buzei.
t_bseg-buzid = 'P'.
t_bseg-bschl = '40'.
t_bseg-shkzg = 'S'.
t_bseg-dmbtr = sdmbtr.
t_bseg-wrbtr = sdmbtr.
t_bseg-pswbt = sdmbtr.
t_bseg-txbfw = '0'.
t_bseg-ktosl = ''.
CONCATENATE 'MRKO差异结转 ' szuonr INTO t_bseg-sgtxt .
t_bseg-vorgn = 'RFBU'.
t_bseg-saknr = '6401990000'.
t_bseg-hkont = '6401990000'.
t_bseg-lifnr = tm_rkwa-lifnr.
t_bseg-bustw = ''.
t_bseg-rewwr = '0'.
sbuzei = sbuzei + 1 .
t_bseg-buzei = sbuzei.
APPEND t_bseg.
ENDIF.
IF sdmbtr < 0 . "负: 50 H 正:40 S
MODIFY t_bseg TRANSPORTING wrbtr txbfw rewwr
WHERE bukrs = t_bseg-bukrs
AND belnr = t_bseg-belnr
AND gjahr = t_bseg-gjahr
AND buzei = t_bseg-buzei.
t_bseg-buzid = 'P'.
t_bseg-bschl = '50'.
t_bseg-shkzg = 'H'.
t_bseg-dmbtr = 0 - sdmbtr.
t_bseg-wrbtr = 0 - sdmbtr.
t_bseg-pswbt = 0 - sdmbtr.
t_bseg-txbfw = '0'.
t_bseg-ktosl = ''.
CONCATENATE 'MRKO差异结转 ' szuonr INTO t_bseg-sgtxt .
t_bseg-vorgn = 'RFBU'.
t_bseg-saknr = '6401990000'.
t_bseg-hkont = '6401990000'.
t_bseg-lifnr = tm_rkwa-lifnr.
t_bseg-bustw = ''.
t_bseg-rewwr = '0'.
sbuzei = sbuzei + 1 .
t_bseg-buzei = sbuzei.
APPEND t_bseg.
ENDIF.
ENDCASE.
ENDIF.
ENDIF.
ENDLOOP.
ENDIF.
复制代码
c.退出前,将显示的内容改回物料凭证金额,否则冲销的时候,形成的会计凭证,会根据新的金额进行,会导致会计凭证不平.
SE38 --> RMVKON00 --> FORM user_exit001_aufrufen TABLES it_bkpf TYPE typ_tab_bkpf
我的SAP版本是:1687行
在结束的位置写入显示增强
FORM user_exit001_aufrufen TABLES it_bkpf TYPE typ_tab_bkpf
it_bseg TYPE typ_tab_bseg
it_bset TYPE typ_tab_bset
it_rkwa TYPE typ_tab_rkwa
USING bukrs LIKE bkpf-bukrs
lifnr LIKE bseg-lifnr
CHANGING x_fehler TYPE c
s_msg TYPE typ_msg
e_gjahr TYPE gjahr
e_monat TYPE monat.
DATA: tab_bset TYPE typ_tab_bset,
tab_rkwa TYPE typ_tab_rkwa.
DATA: f_gjahr TYPE gjahr,
f_monat TYPE monat.
DATA: s_bseg TYPE bseg, s_bkpf TYPE bkpf.
CLEAR: x_fehler,
tab_bset,
tab_rkwa.
tab_bset[] = it_bset[].
tab_rkwa[] = it_rkwa[].
DATA: s_bset TYPE bset.
DATA: f_bset_gjahr TYPE bset-gjahr.
IF NOT it_bset[] IS INITIAL.
READ TABLE it_bset INDEX 1 INTO s_bset.
f_bset_gjahr = s_bset-gjahr.
ENDIF.
sy-subrc = 0.
CALL CUSTOMER-FUNCTION '001'
EXPORTING
i_bukrs = bukrs
i_lifnr = lifnr
TABLES
t_bkpf = it_bkpf
t_bseg = it_bseg
t_bset = tab_bset
t_rkwa = tab_rkwa
EXCEPTIONS
error = 1.
IF ( sy-subrc <> 0 ).
PERFORM msg_fuellen_sysvar CHANGING s_msg.
x_fehler = x.
EXIT. "---------->
ENDIF.
READ TABLE it_bkpf INTO s_bkpf INDEX 1.
IF sy-subrc = 0.
IF NOT s_bkpf-bukrs IS INITIAL.
CALL FUNCTION 'FI_PERIOD_DETERMINE'
EXPORTING
i_budat = s_bkpf-budat
i_bukrs = s_bkpf-bukrs
i_monat = s_bkpf-monat
IMPORTING
e_gjahr = f_gjahr
e_monat = f_monat.
IF f_gjahr = s_bkpf-gjahr AND f_monat = s_bkpf-monat.
e_gjahr = f_gjahr.
e_monat = f_monat.
ELSE.
CLEAR s_msg.
s_msg-msgid = c_msgid_m8.
s_msg-msgty = c_msgty_error.
s_msg-msgno = '008'.
s_msg-msgv1 = 'user_exit001_aufrufen'.
x_fehler = x.
EXIT. "---------->
ENDIF.
LOOP AT it_bseg INTO s_bseg WHERE gjahr <> s_bkpf-gjahr.
ENDLOOP.
IF sy-subrc = 0.
CLEAR s_msg.
s_msg-msgid = c_msgid_m8.
s_msg-msgty = c_msgty_error.
s_msg-msgno = '008'.
s_msg-msgv1 = 'user_exit001_aufrufen'.
x_fehler = x.
EXIT.
ENDIF.
ENDIF.
ELSE.
CLEAR s_msg.
s_msg-msgid = c_msgid_m8.
s_msg-msgty = c_msgty_error.
s_msg-msgno = '008'.
s_msg-msgv1 = 'user_exit001_aufrufen'.
x_fehler = x.
EXIT.
ENDIF.
IF NOT it_bset[] IS INITIAL.
IF s_bkpf-gjahr <> f_bset_gjahr.
LOOP AT it_bset INTO s_bset.
s_bset-gjahr = s_bkpf-gjahr.
MODIFY it_bset FROM s_bset.
ENDLOOP.
ENDIF.
ENDIF.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""$"$\SE:(2) Form USER_EXIT001_AUFRUFEN, End A
*$*$-Start: (2)---------------------------------------------------------------------------------$*$*
ENHANCEMENT 2 ZEMM_RMVKON00. "active version
*
it_rkwa[] = tab_rkwa[].
ENDENHANCEMENT.
*$*$-End: (2)---------------------------------------------------------------------------------$*$*
ENDFORM. "user_exit001_aufrufen
复制代码
主要代码是:
ENHANCEMENT 2 ZEMM_RMVKON00. "active version
it_rkwa[] = tab_rkwa[].
ENDENHANCEMENT.
到这里全部增强做完了.
还是效果图: