mb02保存时调用了MB_CHANGE_DOCUMENT修改物料凭证
MB_CHANGE_DOCUMENT中调用了badi的方法if_mb_document_badi_sap->mb_document_change
可以看到这里调用了BADI mb_document_badi_sap,但是这个badi仅供sap内部使用。
所以使用隐式增强,由于函数MB_CHANGE_DOCUMENT是在update task中调用的,所以在程序MM07MFF0_FCODE_BEARBEITEN的form fcode_bearbeiten开头增强。
代码:(FI_DOCUMENT_CHANGE不好用,使用CHANGE_DOCUMENT)
*修改抬头文本时修改对应的会计凭证文本
data :
lv_bktxt type mkpf-bktxt,
lv_awkey type bkpf-awkey,
ls_bkpf2 type bkpf,
lv_msg(255).
DATA: lt_bkdf TYPE TABLE OF bkdf,
lt_bkpf TYPE TABLE OF bkpf,
ls_bkpf TYPE bkpf,
lt_bsec TYPE TABLE OF bsec,
lt_bsed TYPE TABLE OF bsed,
lt_bseg TYPE TABLE OF bseg,
lt_bset TYPE TABLE OF bset.
if sy-tcode = 'MB02' and ( mseg-werks = '2300' or mseg-werks = '2330' ) and sy-ucomm = 'BU'.
select single bktxt
into lv_bktxt
from mkpf
where mblnr = mkpf-mblnr and mjahr = mkpf-mjahr.
lv_awkey = mkpf-mblnr && '%'.
if sy-subrc = 0 and lv_bktxt ne mkpf-bktxt.
select single bukrs belnr gjahr
into corresponding fields of ls_bkpf2
from bkpf
where awkey like lv_awkey and bukrs = mseg-werks and gjahr = mkpf-mjahr.
if sy-subrc = 0.
ls_bkpf-mandt = sy-mandt.
ls_bkpf-bukrs = ls_bkpf2-bukrs.
ls_bkpf-gjahr = ls_bkpf2-gjahr.
ls_bkpf-belnr = ls_bkpf2-belnr.
ls_bkpf-bktxt = mkpf-bktxt.
APPEND ls_bkpf TO lt_bkpf.
CALL FUNCTION 'CHANGE_DOCUMENT'
TABLES
t_bkdf = lt_bkdf
t_bkpf = lt_bkpf
t_bsec = lt_bsec
t_bsed = lt_bsed
t_bseg = lt_bseg
t_bset = lt_bset
.
commit work and wait.
endif.
endif.
endif.