'BAPI_GOODSMVT_CREATE可以实现物料凭证创建和部分冲销
全部冲销可以使用BAPI_GOODSMVT_CANCEL
FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
GOODSMVT_HEADER = GOODSMVT_HEADER
GOODSMVT_CODE = GOODSMVT_CODE
IMPORTING
MATERIALDOCUMENT = MATERIALDOCUMENT
MATDOCUMENTYEAR = MATDOCUMENTYEAR
TABLES
GOODSMVT_ITEM = GOODSMVT_ITEM[]
RETURN = RETURN[].
抬头部分给值:
GOODSMVT_HEADER-PSTNG_DATE = SY-DATUM.
GOODSMVT_HEADER-DOC_DATE = SY-DATUM.
GOODSMVT_HEADER-PR_UNAME = SY-UNAME.
GOODSMVT_HEADER-REF_DOC_NO = S_PBLNR-low.
GOODSMVT_HEADER-HEADER_TXT = 'Packing List Post'.
GOODSMVT_CODE = '04'.
行项目部分给值(根据移动类型有差异):
loop at gt_itab WHERE WERKS = GT_ITAB1-WERKS.
GOODSMVT_ITEM-MATERIAL = gt_itab-matnr.
GOODSMVT_ITEM-PLANT = gt_itab-werks.
GOODSMVT_ITEM-STGE_LOC = gt_itab-lgort.
GOODSMVT_ITEM-MOVE_TYPE = '311'.
GOODSMVT_ITEM-ENTRY_QNT = gt_itab-menge.
GOODSMVT_ITEM-ENTRY_UOM = gt_itab-meins.
GOODSMVT_ITEM-ITEM_TEXT = gt_itab-MBLNR.
GOODSMVT_ITEM-MOVE_PLANT = gt_itab-werks.
if gt_itab-lgort+0(1) = 'B'.
GOODSMVT_ITEM-MOVE_STLOC = 'B902'.
elseif gt_itab-lgort+0(1) = 'C'.
GOODSMVT_ITEM-MOVE_STLOC = 'C902'.
ENDIF.
append GOODSMVT_ITEM.
endloop.
冲销时与正常创建凭证一样,只是BAPI2017_GM_ITEM_CREATE-XSTOB = 'X'. "冲销标志 移动类型为正向,比如261发料,做262的冲销,移动类型仍给261,不需要修改,此处打叉即可
MBST冲销整个凭证:
CALL FUNCTION 'BAPI_GOODSMVT_CANCEL'
EXPORTING
materialdocument = gt_up-MBLNR
matdocumentyear = gt_up-MJAHR
IMPORTING
GOODSMVT_HEADRET = GOODSMVT_HEADRET
TABLES
RETURN = RETURN.
bapi_goodsmvt_create中goodsmvt_code对应值(T158G)
MB01
MB31
MB1A
MB1B
MB1C
MB11
MB04
BAPI2017_GM_ITEM_CREATE-mvt_ind(Domain:KZBEW) - Movement Indicator
Goods movement w/o reference
B - Goods movement for purchase order
F - Goods movement for production order
L - Goods movement for delivery note
K - Goods movement for kanban requirement (WM - internal only)
O - Subsequent adjustment of "material-provided" consumption
W - Subsequent adjustment of proportion/product unit material
参考:
http://hi.baidu.com/tktik/item/2b0b2017faa5ab21f7625c7d、
一个部分冲销的例子;
FORM bapi_process.
* SHIFT gii_tab-kdauf LEFT DELETING LEADING '0'.
* SHIFT GII_TAB-KDPOS LEFT DELETING LEADING '0'.
MOVE '313' TO gdsmt_item-move_type.
MOVE gii_tab-sobkz TO gdsmt_item-spec_stock.
MOVE gii_tab-matnr TO gdsmt_item-material. "物料
* MOVE gii_tab-lgort TO gdsmt_item-stge_loc.
* MOVE 'LW01' TO gdsmt_item-move_stloc.
MOVE 'X' TO gdsmt_item-xstob. "冲销标志
goodsmvt_header = gdsmt_header
goodsmvt_code = gdsmt_code
goodsmvt_item = gdsmt_item
return
MESSAGE
ENDFORM. "bapi_process
标签:BAPI,gt,item,CREATE,MOVE,itab,ITEM,GOODSMVT From: https://blog.51cto.com/u_15680210/5751442