BAPI_GOODSMVT_CREATE 移动类型201 CODE = '03' 代码
DATA: MAT_DOC LIKE BAPI2017_GM_HEAD_RET-MAT_DOC. "物料凭证编号
DATA: GMHEAD LIKE BAPI2017_GM_HEAD_01.
DATA: BEGIN OF GMCODE.
INCLUDE STRUCTURE BAPI2017_GM_CODE.
DATA: END OF GMCODE.
GMCODE-GM_CODE = '03'.
***********gmcode-gm_code取值含义*******
********01 MB01
********02 MB31
********03 MB1A
********04 MB1B
********05 MB1C
********06 MB11
********07 MB04
DATA: BEGIN OF MTHEAD.
INCLUDE STRUCTURE BAPI2017_GM_HEAD_RET.
DATA: END OF MTHEAD.
DATA: BEGIN OF ITAB OCCURS 100.
INCLUDE STRUCTURE BAPI2017_GM_ITEM_CREATE.
DATA: END OF ITAB.
DATA: BEGIN OF ERRMSG OCCURS 10.
INCLUDE STRUCTURE BAPIRET2.
DATA: END OF ERRMSG.
"CLEAR: MAT_DOC, GMHEAD, GMCODE, MTHEAD, ITAB[], ERRMSG[].
GMHEAD-PSTNG_DATE = SY-DATUM. "凭证中的过帐日期
GMHEAD-DOC_DATE = SY-DATUM. "凭证中的凭证日期
GMHEAD-PR_UNAME = SY-UNAME.
LOOP AT SHOW_TAB WHERE SEL_COL = 'X'.
ITAB-MATERIAL = SHOW_TAB-MATNR. "物料号
ITAB-PLANT = SHOW_TAB-WERKS. "工厂
ITAB-STGE_LOC = SHOW_TAB-ZLGORTO. "库存地点
ITAB-COSTCENTER = SHOW_TAB-KOSTL. "成本中心 比311多了个成本中心
ITAB-BATCH = SHOW_TAB-CHARG. "批次
ITAB-ENTRY_QNT = SHOW_TAB-MENGE. "实领数量
ITAB-ENTRY_UOM = SHOW_TAB-MEINS. "单位
ITAB-MOVE_TYPE = SHOW_TAB-ZLLTYPE. "移动类型
* ITAB-mvt_ind = 'O'.
ITAB-MOVE_MAT = SHOW_TAB-MATNR. "收货/发货物料号
ITAB-MOVE_PLANT = SHOW_TAB-WERKS. "收货/发货工厂
ITAB-MOVE_STLOC = SHOW_TAB-ZLGORTI. "收货/发货物料仓库
* ITAB-no_more_gr = 'X'. "交货完成标识
APPEND ITAB.
ENDLOOP.
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
GOODSMVT_HEADER = GMHEAD
GOODSMVT_CODE = GMCODE
* TESTRUN = ' '
* GOODSMVT_REF_EWM =
IMPORTING
GOODSMVT_HEADRET = MTHEAD
MATERIALDOCUMENT = MAT_DOC
* MATDOCUMENTYEAR =
TABLES
GOODSMVT_ITEM = ITAB
* GOODSMVT_SERIALNUMBER =
RETURN = ERRMSG
* GOODSMVT_SERV_PART_DATA =
* EXTENSIONIN =
.
READ TABLE ERRMSG WITH KEY TYPE = 'E'.
IF SY-SUBRC = 0.
MESSAGE ERRMSG-MESSAGE TYPE 'S' DISPLAY LIKE 'E'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK' .
"SHOW_TAB-POST = ''.
ELSE.
"必须成功执行 BAPI_GOODSMVT_CREATE 不然会在MIGO查不到 生成的凭证号 MAT_DOC
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
DATA: L_MESS(100).
CONCATENATE '过账成功,凭证号:' MAT_DOC INTO L_MESS.
MESSAGE L_MESS TYPE 'S' .
"SHOW_TAB-POST = 'X'.
ENDIF.
posted on 2016-10-27 15:36 seven1314pp 阅读(3150) 评论(0) 编辑 收藏 举报