BAPI_GOODSMVT_CANCEL 冲销物料凭证时有三点需要注意:
1.如果不传入行项目,则冲销整单凭证;
2.如果指定行项目,则冲销对应的行项目;
3.如果行项目是自动生成的,且指定了行项目参数,则自动产生的行项目必须要人工指定才会冲销,否则可能出现例如:物料号反冲了,自动生成的行(例如BOM组件)没有反冲的死循环。
ps.物料凭证不像会计凭证(会计凭证只能整张反冲),物料凭证可以反冲某个行次。
有些移动类型,例如301、309、641等是自动产生两个行项目的,而不是一个行项目上不同的字段标识物料移动的源头和目标,BAPI操作时一定要注意。有些操作在前台MIGO看起来理所当然,但BAPI就不一定,BAPI能做很多前台做不了的事情、当然也“很听话”!
如下分别举例整单反冲了指定行项目反冲:
1)指定行项目反冲:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
form mbst using ps_out type typ_out. data:ls_mkpf like bapi2017_gm_head_ret. data:gt_bapi_return type table of bapiret2, gs_bapi_return type bapiret2. data: lt_items_resv type table of bapi2017_gm_item_04 with header line. "冲销时应该把父行项目和他自动产生的行项目一起冲销. clear matdoc. select * from matdoc where mblnr = gt_out-mblnr and urzei = gt_out-zeile and cancelled ne 'X'. lt_items_resv-matdoc_item = matdoc-zeile . append lt_items_resv. endselect. call function 'BAPI_GOODSMVT_CANCEL' exporting materialdocument = gt_out-mblnr matdocumentyear = gt_out-budat(4) goodsmvt_pstng_date = gt_out-budat documentheader_text = gt_out-bktxt importing goodsmvt_headret = ls_mkpf tables goodsmvt_matdocitem = lt_items_resv return = gt_bapi_return. loop at gt_bapi_return into gs_bapi_return where type = 'E' or type = 'A' or type = 'X'. message e000 with gs_bapi_return-message. endloop. if sy-subrc <> 0. commit work and wait. message s000 with '冲销成功'. else. rollback work. message s000 with '冲销失败'. endif. endform. |
2)整单反冲
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
*整单冲销物料凭证. form mbst_wh using ps_out type typ_out. data:ls_mkpf like bapi2017_gm_head_ret. data:gt_bapi_return type table of bapiret2, gs_bapi_return type bapiret2. * data: lt_items_resv type table of bapi2017_gm_item_04 with header line. "冲销时应该把父行项目和他自动产生的行项目一起冲销. * clear matdoc. * select * from matdoc where mblnr = gt_out-mblnr and urzei = gt_out-zeile and cancelled ne 'X'. * lt_items_resv-matdoc_item = matdoc-zeile . * append lt_items_resv. * endselect. call function 'BAPI_GOODSMVT_CANCEL' exporting materialdocument = gt_out-mblnr matdocumentyear = gt_out-budat(4) goodsmvt_pstng_date = gt_out-budat documentheader_text = gt_out-bktxt importing goodsmvt_headret = ls_mkpf tables * goodsmvt_matdocitem = lt_items_resv "不指定行项目则整单冲销. return = gt_bapi_return. loop at gt_bapi_return into gs_bapi_return where type = 'E' or type = 'A' or type = 'X'. message e000 with gs_bapi_return-message. endloop. if sy-subrc <> 0. commit work and wait. message s000 with '整单冲销成功'. else. rollback work. message e000 with '整单冲销失败'. endif. endform. |
本文作者: GavinDong
版权属于: GavinDong博客
文章链接: https://gavindong.com/3131.html
如果使用过程中遇到问题,可 **点击此处** 交流沟通。
版权所有,转载时必须以链接形式注明作者和原始出处及本声明。
评论列表(3条)
您好,打扰了。向您请教一个问题,我今天用这个BAPI测试了一下,我在SE37新建了一个函数调用该BAPI,但是我发现按照您这个写法,筛选出来了的自动创建的行项目加进去以后,返回消息是这个自动创建的行项目不能冲销。但是我直接用该自动创建的行参照的初始行项目去执行这个BAPI,生成的物料凭证编号也会自动创建一个对应的冲销行。我测试的是309的移动类型。这是什么原因呢?是因为我们调用的位置不一样,还是SAP方面进行了维护?
有可能是SAP版本不同,我当时是在S4 1709里测试的。不同ABAP的版本BAPI会存在一些差异,我当时就是发现自动创建的行项目没有冲销才试着加上的。
非常感谢您的回复