Cancel Material Document is easy.
在SAP中物料凭证创建后,是不能删除的,如果做错了,可以冲销掉。前台事务代码是MBST。
对应的函数可以使用:MB_CANCEL_GOODS_MOVEMENT。今天我们一起来学习温故~
参数描述:
参数名称 | 关联类型 | 可选的 | 说明 |
BUDAT | MKPF-BUDAT | 必选 | 凭证中的过帐日期 |
MBLNR | MSEG-MBLNR | 可选 | 物料凭证编号 |
MJAHR | MSEG-MJAHR | 可选 | 物料凭证的年份 |
TCODE | SY-TCODE | 可选 | 事务码 |
CALLED_BY | CALLED_BY | 可选 | 调用者的唯一标识 |
VBELN | LIKP-VBELN | 可选 | 交货 |
返回导出
参数名称 | 关联类型 | 说明 |
ES_MKPF | MKPF | 抬头:物料凭证 |
如下是demo代码,作为HOT583.com的码农,多年前也是SAP ABAP beginners ,最开始学习会有些难度,
到处去找Tutorial for Constant。如下是详细代码:
*定义bapi相关参数
DATA:t_mkpf TYPE mkpf OCCURS 0 WITH HEADER LINE,
t_emseg TYPE TABLE OF emseg,
t_imseg TYPE TABLE OF imseg,
t_cmseg TYPE STANDARD TABLE OF mseg,
t_mblnr TYPE mbwo_mblnr_tab,
l_budat TYPE mkpf-budat.
START-OF-SELECTION.
SELECT * FROM mkpf INTO TABLE t_mkpf
WHERE mblnr IN r_mblnr
AND mjahr = p_mjahr.
LOOP AT t_mkpf.
“ Check if original document was posted by DUV
IF t_mkpf-tcode2 <> ‘CKMDUVMAT’.
DELETE t_mkpf.
ENDIF.
“ Check if document is already reversed
SELECT SINGLE * FROM m_mbmps
WHERE smbln = t_mkpf-mblnr
AND sjahr = t_mkpf-mjahr.
IF sy-subrc = 0.
DELETE t_mkpf.
ENDIF.
ENDLOOP.
LOOP AT t_mkpf.
REFRESH: t_emseg, t_imseg.
CLEAR: s_emkpf.
IF p_budat IS INITIAL.
l_budat = t_mkpf-budat.
ELSE.
l_budat = p_budat.
ENDIF.
IF p_gi1st IS INITIAL.
“ full document reversal
CALL FUNCTION ‘MB_CANCEL_GOODS_MOVEMENT’
EXPORTING
budat = l_budat
mblnr = t_mkpf-mblnr
mjahr = t_mkpf-mjahr
tcode = ‘CKMDUVMAT’ “checked with T158 (M7066)
IMPORTING
emkpf = s_emkpf
TABLES
emseg = t_emseg
imseg = t_imseg.
LOOP AT t_cmseg INTO s_cmseg.
MOVE-CORRESPONDING s_cmseg TO s_mblnr.
IF s_cmseg-shkzg = ‘S’.
APPEND s_mblnr TO t_mblnr.
ELSE.
INSERT s_mblnr INTO t_mblnr INDEX 1.
ENDIF.
ENDLOOP.
ENDIF.
ENDLOOP.
本文链接 :http://www.hot583.com/2022/05/20/mb_cancel_goods_movement/
本文为作者原创,如果这篇文章对您有用,欢迎转载,
转载请务必注明来源《今日热点在看》http://www.hot583.com/
我的微信公众号【 hot583 】 或者在这个链接联系我
微信原文《全文完》