点击此处---> 群内免费提供SAP练习系统(在群公告中)
加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)
物料凭证生成前,会执行一个BADI
请注意SE37:MB_POST_GOODS_MOVEMENT
中
CALL FUNCTION 'MB_CREATE_MATERIAL_DOCUMENT_UT'
EXCEPTIONS
error_message = 4.
ERROR_MESSAGE 决定了所有的message 会从此函数中抛出,并在如下代码中用Xmessage 报出,dump!
* As soon as we have started to put things into UPDATE TASK, we must
* ensure that errors definitely terminate the transaction.
* MESSAGE A is not sufficient because it can be catched from
* external callers which COMMIT WORK afterwards, resulting in
* incomplete updates. Read note 385830 for the full story.
IF NOT sy-subrc IS INITIAL.
MESSAGE ID sy-msgid TYPE x NUMBER sy-msgno WITH "385830
sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
* MESSAGE A263.
ENDIF.
此处可以分析出X-message 与A-message的区别。
而BADI (SE18):MB_DOCUMENT_BADI藏于MB_CREATE_MATERIAL_DOCUMENT_UT
请注意如上BADI已经迁移至增强点:MB_GOODSMOVEMENT
里面的任何message 将导致X-message的报错。导致系统dump!
有的项目在此限制了物料凭证的移动类型,例如不能超过2个。
顺便研究一下附加的东西
MB_DOCUMENT_BADI 有连个方法,第一个实在更新前
第二个是在更新后,MB_DOCUMENT_UPDATE 在function:MB_UPDATE_TASKS(Update function)
在这里面有两个增强可以用
第一个就是BADI:MB_DOCUMENT_UPDATE
第二个是SMOD:MB_CF001 (CMOD 激活)也同样能实现相同的功能!
另外:MB_POST_GOODS_MOVEMENT 这个函数挺有意思
请看代码
IF NOT xblnr_sd IS INITIAL.
xmkpf-xblnr = xblnr_sd.
xmkpf-le_vbeln = xblnr_sd. "XAN-SPM
MODIFY xmkpf INDEX 1.
ls_mseg_sd-vbeln_im = xblnr_sd. "1673670
MODIFY xmseg FROM ls_mseg_sd TRANSPORTING vbeln_im "1673670
WHERE vbelp_im IS NOT INITIAL. "1673670
* when a goods movement for an inbound or outbound delivery is posted
* directly from VL31N/ VL01N, XBLNR is not yet known when we call
* CKMV_AC_DOCUMENT_CREATE, but the number is supposed to be stored in
* BKPF as well. There is no other way to forward XBLNR to FI as not
* every document is posted by MB_CREATE -> a new function module in
* MBWL for transferring the information, called by FI, meant to load
* the complete function group for all MBxx postings when this isn't
* required (Performance). Would be the better way to transport the
* information after switching off MBxx in later release.
* corresponding IMPORT ... FROM MEMORY ... can be found in
* AC_DOCUMENT_POST (FORM FI_DOCUMENT_PREPARE (LFACIF5D))
l_mem_id = 'MKPF-XBLNR'. " 641365
EXPORT xblnr = xblnr_sd TO MEMORY ID l_mem_id. " 641365
ELSE. "1245374
l_mem_id = 'MKPF-XBLNR'. "1245374
FREE MEMORY ID l_mem_id. "1245374
ENDIF.
IF xmkpf-xabln IS INITIAL. "note 434093
CALL FUNCTION 'MB_XAB_NUMBER_GET'. "note 434093
ENDIF. "note 434093
由于产生的物料凭证的单据在SD中 只有交货单发货过账,
故xmkpf-xblnr 和 xmkpf-le_vbeln 存放的一定是交货单
mseg-vbeln_im 存放的也是交货单编码
还有
* Would be the better way to transport the
* information after switching off MBxx in later release.
* corresponding IMPORT ... FROM MEMORY ... can be found in
* AC_DOCUMENT_POST (FORM FI_DOCUMENT_PREPARE (LFACIF5D))
也是值得回味的!!
2016-11-29
S4 1510 HANA中,
交货单产生物料凭证的function 已经发生改变
MB_POST_GOODS_MOVEMENT 变成了MB_CREATE_GOODS_MOVEMENT
但是其中MB_DOCUMENT_BADI 还是存在的
请注意,MB_DOCUMENT_BADI 只能使用SE18 "BADI名称"选项做 增强 ,做的实施会自动添加进MB_GOODSMOVEMENT
使用MB_GOODSMOVEMENT 是迁移,是无法创建MB_DOCUMENT_BADI 的实施, 代码如下: