BAPI冲销物料凭证BAPI_GOODSMVT_CANCEL
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. |
如若转载,请注明出处:https://www.gavindong.com/3131.html