***********GOODSMVT_CODE取值含义*******
*01 MB01
*02 MB31
*03 MB1A "发
*04 MB1B "转储
*05 MB1C "其它收货
*06 MB11
*07 MB04
经常会遇到一些自定义的移动类型,但是并不知道对应的goodsmvt_code是多少。可以用如下方法进行查找
首先去T158B中根据移动类型找到对应的事务代码:如图
然后再将对应的事务代码去T158G 中找code,如图:
1.移动类型 344 冻结库存
"bapi 参数
DATA:LW_GOODSMVT_HEADER TYPE BAPI2017_GM_HEAD_01,
LV_GOODSMVT_CODE TYPE BAPI2017_GM_CODE,
LT_GOODSMVT_ITEM TYPE TABLE OF BAPI2017_GM_ITEM_CREATE,
LW_GOODSMVT_ITEM TYPE BAPI2017_GM_ITEM_CREATE,
LT_RETURN TYPE TABLE OF BAPIRET2,
LW_RETURN TYPE BAPIRET2,
LV_MATERIALDOCUMENT TYPE BAPI2017_GM_HEAD_RET-MAT_DOC,
LV_MATDOCUMENTYEAR TYPE BAPI2017_GM_HEAD_RET-DOC_YEAR.
LV_GOODSMVT_CODE = '04'.
"准备抬头数据
LW_GOODSMVT_HEADER-PSTNG_DATE = SY-DATUM.
LW_GOODSMVT_HEADER-DOC_DATE = SY-DATUM. "凭证中的凭证日期
LW_GOODSMVT_HEADER-PR_UNAME = SY-UNAME. "用户名
"行项目数据
LW_GOODSMVT_ITEM-MATERIAL = ''物料号
LW_GOODSMVT_ITEM-PLANT = LS_ITEM-WERKS. " 从
LW_GOODSMVT_ITEM-STGE_LOC = LS_ITEM-LGORT.
LW_GOODSMVT_ITEM-MOVE_TYPE = '344'.
LW_GOODSMVT_ITEM-ENTRY_QNT = LS_ITEM-QTY .
LW_GOODSMVT_ITEM-MOVE_PLANT = LS_ITEM-WERKS . " 到
LW_GOODSMVT_ITEM-MOVE_STLOC = LS_ITEM-LGORT .
APPEND LW_GOODSMVT_ITEM TO LT_GOODSMVT_ITEM .
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
GOODSMVT_HEADER = LW_GOODSMVT_HEADER
GOODSMVT_CODE = LV_GOODSMVT_CODE
IMPORTING
MATERIALDOCUMENT = LV_MATERIALDOCUMENT
MATDOCUMENTYEAR = LV_MATDOCUMENTYEAR
TABLES
GOODSMVT_ITEM = LT_GOODSMVT_ITEM
RETURN = LT_RETURN
.
2. 移动类型 343 解冻库存
"bapi 参数
DATA:LW_GOODSMVT_HEADER TYPE BAPI2017_GM_HEAD_01,
LV_GOODSMVT_CODE TYPE BAPI2017_GM_CODE,
LT_GOODSMVT_ITEM TYPE TABLE OF BAPI2017_GM_ITEM_CREATE,
LW_GOODSMVT_ITEM TYPE BAPI2017_GM_ITEM_CREATE,
LT_RETURN TYPE TABLE OF BAPIRET2,
LW_RETURN TYPE BAPIRET2,
LV_MATERIALDOCUMENT TYPE BAPI2017_GM_HEAD_RET-MAT_DOC,
LV_MATDOCUMENTYEAR TYPE BAPI2017_GM_HEAD_RET-DOC_YEAR.
LV_GOODSMVT_CODE = '04'.
"准备抬头数据
LW_GOODSMVT_HEADER-PSTNG_DATE = SY-DATUM.
LW_GOODSMVT_HEADER-DOC_DATE = SY-DATUM. "凭证中的凭证日期
LW_GOODSMVT_HEADER-PR_UNAME = SY-UNAME. "用户名
"行项目数据
LW_GOODSMVT_ITEM-MATERIAL = ''物料号
LW_GOODSMVT_ITEM-PLANT = LS_ITEM-WERKS. " 从
LW_GOODSMVT_ITEM-STGE_LOC = LS_ITEM-LGORT.
LW_GOODSMVT_ITEM-MOVE_TYPE = '343'.
LW_GOODSMVT_ITEM-ENTRY_QNT = LS_ITEM-QTY .
LW_GOODSMVT_ITEM-MOVE_PLANT = LS_ITEM-WERKS . " 到
LW_GOODSMVT_ITEM-MOVE_STLOC = LS_ITEM-LGORT .
APPEND LW_GOODSMVT_ITEM TO LT_GOODSMVT_ITEM .
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
GOODSMVT_HEADER = LW_GOODSMVT_HEADER
GOODSMVT_CODE = LV_GOODSMVT_CODE
IMPORTING
MATERIALDOCUMENT = LV_MATERIALDOCUMENT
MATDOCUMENTYEAR = LV_MATDOCUMENTYEAR
TABLES
GOODSMVT_ITEM = LT_GOODSMVT_ITEM
RETURN = LT_RETURN
.
3. 移动类型 101 收货
"bapi 参数
DATA:LW_GOODSMVT_HEADER TYPE BAPI2017_GM_HEAD_01,
LV_GOODSMVT_CODE TYPE BAPI2017_GM_CODE,
LT_GOODSMVT_ITEM TYPE TABLE OF BAPI2017_GM_ITEM_CREATE,
LW_GOODSMVT_ITEM TYPE BAPI2017_GM_ITEM_CREATE,
LT_RETURN TYPE TABLE OF BAPIRET2,
LW_RETURN TYPE BAPIRET2,
LV_MATERIALDOCUMENT TYPE BAPI2017_GM_HEAD_RET-MAT_DOC,
LV_MATDOCUMENTYEAR TYPE BAPI2017_GM_HEAD_RET-DOC_YEAR.
LV_GOODSMVT_CODE = '01'.
"准备抬头数据
LW_GOODSMVT_HEADER-PSTNG_DATE = SY-DATUM.
LW_GOODSMVT_HEADER-DOC_DATE = SY-DATUM. "凭证中的凭证日期
LW_GOODSMVT_HEADER-PR_UNAME = SY-UNAME. "用户名
"行项目数据
LW_GOODSMVT_ITEM-PO_NUMBER = GS_ITEM-EBELN. "采购凭证号
LW_GOODSMVT_ITEM-ITEM_TEXT = GS_ITEM-WMSNO. "项目文本
LW_GOODSMVT_ITEM-PO_ITEM = GS_ITEM-ZEILE. "采购凭证的项目编号
LW_GOODSMVT_ITEM-PLANT = GS_ITEM-WERKS. "工厂
LW_GOODSMVT_ITEM-STGE_LOC = GS_ITEM-LGORT. "库存地点
LW_GOODSMVT_ITEM-BATCH = GS_ITEM-CHARG. "批次号
LW_GOODSMVT_ITEM-ENTRY_QNT = GS_ITEM-ERFMG. "以录入项单位表示的数量
LW_GOODSMVT_ITEM-MVT_IND = 'B'. "移动标识 ’B‘为采购收货 ’F ' 生产收货
LW_GOODSMVT_ITEM-MOVE_TYPE = '101'. "移动类型
APPEND LW_GOODSMVT_ITEM TO LT_GOODSMVT_ITEM .
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
GOODSMVT_HEADER = LW_GOODSMVT_HEADER
GOODSMVT_CODE = LV_GOODSMVT_CODE "MB01 按采购订单的货物移动
IMPORTING
MATERIALDOCUMENT = LV_MATERIALDOCUMENT
MATDOCUMENTYEAR = LV_MATDOCUMENTYEAR
TABLES
GOODSMVT_ITEM = LT_GOODSMVT_ITEM
RETURN = LT_RETURN
.
4. 移动类型 Z21 生产退料
"bapi 参数
DATA:LW_GOODSMVT_HEADER TYPE BAPI2017_GM_HEAD_01,
LV_GOODSMVT_CODE TYPE BAPI2017_GM_CODE,
LT_GOODSMVT_ITEM TYPE TABLE OF BAPI2017_GM_ITEM_CREATE,
LW_GOODSMVT_ITEM TYPE BAPI2017_GM_ITEM_CREATE,
LT_RETURN TYPE TABLE OF BAPIRET2,
LW_RETURN TYPE BAPIRET2,
LV_MATERIALDOCUMENT TYPE BAPI2017_GM_HEAD_RET-MAT_DOC,
LV_MATDOCUMENTYEAR TYPE BAPI2017_GM_HEAD_RET-DOC_YEAR.
LV_GOODSMVT_CODE = '03'.
"准备抬头数据
LW_GOODSMVT_HEADER-PSTNG_DATE = SY-DATUM.
LW_GOODSMVT_HEADER-DOC_DATE = SY-DATUM. "凭证中的凭证日期
LW_GOODSMVT_HEADER-PR_UNAME = SY-UNAME. "用户名
"行项目数据
LW_GOODSMVT_ITEM-MATERIAL = ''物料号
LW_GOODSMVT_ITEM-PLANT = LS_ITEM-WERKS. " 从
LW_GOODSMVT_ITEM-STGE_LOC = LS_ITEM-LGORT.
LW_GOODSMVT_ITEM-MOVE_TYPE = 'Z21'.
LW_GOODSMVT_ITEM-ENTRY_QNT = LS_ITEM-QTY .
APPEND LW_GOODSMVT_ITEM TO LT_GOODSMVT_ITEM .
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
GOODSMVT_HEADER = LW_GOODSMVT_HEADER
GOODSMVT_CODE = LV_GOODSMVT_CODE
IMPORTING
MATERIALDOCUMENT = LV_MATERIALDOCUMENT
MATDOCUMENTYEAR = LV_MATDOCUMENTYEAR
TABLES
GOODSMVT_ITEM = LT_GOODSMVT_ITEM
RETURN = LT_RETURN
.
5. 移动类型 101 生产订单收货
"bapi 参数
DATA:LW_GOODSMVT_HEADER TYPE BAPI2017_GM_HEAD_01,
LV_GOODSMVT_CODE TYPE BAPI2017_GM_CODE,
LT_GOODSMVT_ITEM TYPE TABLE OF BAPI2017_GM_ITEM_CREATE,
LW_GOODSMVT_ITEM TYPE BAPI2017_GM_ITEM_CREATE,
LT_RETURN TYPE TABLE OF BAPIRET2,
LW_RETURN TYPE BAPIRET2,
LV_MATERIALDOCUMENT TYPE BAPI2017_GM_HEAD_RET-MAT_DOC,
LV_MATDOCUMENTYEAR TYPE BAPI2017_GM_HEAD_RET-DOC_YEAR.
LV_GOODSMVT_CODE = '02'.
"准备抬头数据
LW_GOODSMVT_HEADER-PSTNG_DATE = SY-DATUM.
LW_GOODSMVT_HEADER-DOC_DATE = SY-DATUM. "凭证中的凭证日期
LW_GOODSMVT_HEADER-PR_UNAME = SY-UNAME. "用户名
"行项目数据
LW_GOODSMVT_ITEM-MATERIAL = LS_ITEM-MATNR. "物料编号
LW_GOODSMVT_ITEM-PLANT = LS_ITEM-WERKS. "工厂
LW_GOODSMVT_ITEM-STGE_LOC = LS_ITEM-LGORT. "库存地点
LW_GOODSMVT_ITEM-BATCH = LS_ITEM-CHARG. "批次号
LW_GOODSMVT_ITEM-ENTRY_QNT = LS_ITEM-ERFMG. "以录入项单位表示的数量
LW_GOODSMVT_ITEM-MOVE_STLOC = LS_ITEM-UMLGO. "收货库存地点
LW_GOODSMVT_ITEM-MOVE_BATCH = LS_ITEM-UMCHA. "收货批次
LW_GOODSMVT_ITEM-STCK_TYPE = '2' . "质检状态
LW_GOODSMVT_ITEM-MVT_IND = 'F'. "移动标识 ’B‘为采购收货 ’F ' 生产收货
LW_GOODSMVT_ITEM-MOVE_TYPE = '101'. "移动类型
APPEND LW_GOODSMVT_ITEM TO LT_GOODSMVT_ITEM .
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
GOODSMVT_HEADER = LW_GOODSMVT_HEADER
GOODSMVT_CODE = LV_GOODSMVT_CODE
IMPORTING
MATERIALDOCUMENT = LV_MATERIALDOCUMENT
MATDOCUMENTYEAR = LV_MATDOCUMENTYEAR
TABLES
GOODSMVT_ITEM = LT_GOODSMVT_ITEM
RETURN = LT_RETURN
.
6. 移动类型 501 无源单入库
"bapi 参数
DATA:LW_GOODSMVT_HEADER TYPE BAPI2017_GM_HEAD_01,
LV_GOODSMVT_CODE TYPE BAPI2017_GM_CODE,
LT_GOODSMVT_ITEM TYPE TABLE OF BAPI2017_GM_ITEM_CREATE,
LW_GOODSMVT_ITEM TYPE BAPI2017_GM_ITEM_CREATE,
LT_RETURN TYPE TABLE OF BAPIRET2,
LW_RETURN TYPE BAPIRET2,
LV_MATERIALDOCUMENT TYPE BAPI2017_GM_HEAD_RET-MAT_DOC,
LV_MATDOCUMENTYEAR TYPE BAPI2017_GM_HEAD_RET-DOC_YEAR.
LV_GOODSMVT_CODE = '05'.
"准备抬头数据
LW_GOODSMVT_HEADER-PSTNG_DATE = SY-DATUM.
LW_GOODSMVT_HEADER-DOC_DATE = SY-DATUM. "凭证中的凭证日期
LW_GOODSMVT_HEADER-PR_UNAME = SY-UNAME. "用户名
"行项目数据
LW_GOODSMVT_ITEM-MATERIAL = ''物料号
LW_GOODSMVT_ITEM-PLANT = LS_ITEM-WERKS. " 从
LW_GOODSMVT_ITEM-STGE_LOC = LS_ITEM-LGORT.
LW_GOODSMVT_ITEM-MOVE_TYPE = '501'.
LW_GOODSMVT_ITEM-VENDOR = LS_ITEM-LIFNR. "供应商编码
LW_GOODSMVT_ITEM-ENTRY_QNT = LS_ITEM-QTY .
APPEND LW_GOODSMVT_ITEM TO LT_GOODSMVT_ITEM .
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
GOODSMVT_HEADER = LW_GOODSMVT_HEADER
GOODSMVT_CODE = LV_GOODSMVT_CODE
IMPORTING
MATERIALDOCUMENT = LV_MATERIALDOCUMENT
MATDOCUMENTYEAR = LV_MATDOCUMENTYEAR
TABLES
GOODSMVT_ITEM = LT_GOODSMVT_ITEM
RETURN = LT_RETURN
.
7.移动类型 321 状态转移
"bapi 参数
DATA:LW_GOODSMVT_HEADER TYPE BAPI2017_GM_HEAD_01,
LV_GOODSMVT_CODE TYPE BAPI2017_GM_CODE,
LT_GOODSMVT_ITEM TYPE TABLE OF BAPI2017_GM_ITEM_CREATE,
LW_GOODSMVT_ITEM TYPE BAPI2017_GM_ITEM_CREATE,
LT_RETURN TYPE TABLE OF BAPIRET2,
LW_RETURN TYPE BAPIRET2,
LV_MATERIALDOCUMENT TYPE BAPI2017_GM_HEAD_RET-MAT_DOC,
LV_MATDOCUMENTYEAR TYPE BAPI2017_GM_HEAD_RET-DOC_YEAR.
LV_GOODSMVT_CODE = '04'.
"准备抬头数据
LW_GOODSMVT_HEADER-PSTNG_DATE = SY-DATUM.
LW_GOODSMVT_HEADER-DOC_DATE = SY-DATUM. "凭证中的凭证日期
LW_GOODSMVT_HEADER-PR_UNAME = SY-UNAME. "用户名
"行项目数据
LW_GOODSMVT_ITEM-MATERIAL = LS_ITEM-MATNR. "物料编号
LW_GOODSMVT_ITEM-PLANT = LS_ITEM-WERKS. "发出工厂
LW_GOODSMVT_ITEM-STGE_LOC = LS_ITEM-LGORT. "发出库存地点
LW_GOODSMVT_ITEM-SPEC_STOCK = LS_ITEM-UMSOK. "特殊库存标识
LW_GOODSMVT_ITEM-SALES_ORD = LS_ITEM-KDAUF. "发出销售订单
LW_GOODSMVT_ITEM-S_ORD_ITEM = LS_ITEM-KDPOS. "发出销售订单行项目
LW_GOODSMVT_ITEM-BATCH = LS_ITEM-CHARG. "发出批次号
LW_GOODSMVT_ITEM-ENTRY_QNT = LS_ITEM-ERFMG. "以录入项单位表示的数量
LW_GOODSMVT_ITEM-VAL_SALES_ORD = LS_ITEM-MAT_KDAUF. "接收销售订单号
LW_GOODSMVT_ITEM-VAL_S_ORD_ITEM = LS_ITEM-MAT_KDPOS. "接收销售订单行项目
LW_GOODSMVT_ITEM-MOVE_STLOC = LS_ITEM-UMLGO. "接收收货库存地点
LW_GOODSMVT_ITEM-MOVE_BATCH = LS_ITEM-UMCHA. "接收收货批次
LW_GOODSMVT_ITEM-MOVE_TYPE = '321'. "移动类型
* 如果生产订单不为空
SELECT
SINGLE
*
INTO @DATA(LS_MSEG)
FROM MSEG
WHERE MBLNR = @LS_ITEM-MBLNR
AND BWART = '101'
AND AUFNR = @LV_AUFNR.
IF SY-SUBRC = 0 .
LW_GOODSMVT_ITEM-REF_DOC_YR = LS_MSEG-MJAHR .
LW_GOODSMVT_ITEM-REF_DOC = LS_MSEG-MBLNR .
LW_GOODSMVT_ITEM-REF_DOC_IT = LS_MSEG-ZEILE .
ENDIF .
APPEND LW_GOODSMVT_ITEM TO LT_GOODSMVT_ITEM .
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
GOODSMVT_HEADER = LW_GOODSMVT_HEADER
GOODSMVT_CODE = LV_GOODSMVT_CODE
IMPORTING
MATERIALDOCUMENT = LV_MATERIALDOCUMENT
MATDOCUMENTYEAR = LV_MATDOCUMENTYEAR
TABLES
GOODSMVT_ITEM = LT_GOODSMVT_ITEM
RETURN = LT_RETURN
.
8. 移动类型 541
"bapi 参数
DATA:LW_GOODSMVT_HEADER TYPE BAPI2017_GM_HEAD_01,
LV_GOODSMVT_CODE TYPE BAPI2017_GM_CODE,
LT_GOODSMVT_ITEM TYPE TABLE OF BAPI2017_GM_ITEM_CREATE,
LW_GOODSMVT_ITEM TYPE BAPI2017_GM_ITEM_CREATE,
LT_RETURN TYPE TABLE OF BAPIRET2,
LW_RETURN TYPE BAPIRET2,
LV_MATERIALDOCUMENT TYPE BAPI2017_GM_HEAD_RET-MAT_DOC,
LV_MATDOCUMENTYEAR TYPE BAPI2017_GM_HEAD_RET-DOC_YEAR.
LV_GOODSMVT_CODE = '04'.
"准备抬头数据
LW_GOODSMVT_HEADER-PSTNG_DATE = SY-DATUM.
LW_GOODSMVT_HEADER-DOC_DATE = SY-DATUM. "凭证中的凭证日期
LW_GOODSMVT_HEADER-PR_UNAME = SY-UNAME. "用户名
"行项目数据
LW_GOODSMVT_ITEM-PLANT = LS_ITEM-WERKS.
LW_GOODSMVT_ITEM-STGE_LOC = LS_ITEM-LGORT.
LW_GOODSMVT_ITEM-MOVE_TYPE = '541'.
LW_GOODSMVT_ITEM-ENTRY_QNT = LS_ITEM-ERFMG .
LW_GOODSMVT_ITEM-BATCH = LS_ITEM-CHARG.
LW_GOODSMVT_ITEM-ITEM_TEXT = LS_ITEM-EBELN .
LW_GOODSMVT_ITEM-MOVE_PLANT = LS_ITEM-UMWRK .
LW_GOODSMVT_ITEM-MOVE_BATCH = LS_ITEM-CHARG .
LW_GOODSMVT_ITEM-VENDOR = LS_ITEM-LIFNR.
APPEND LW_GOODSMVT_ITEM TO LT_GOODSMVT_ITEM .
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
GOODSMVT_HEADER = LW_GOODSMVT_HEADER
GOODSMVT_CODE = LV_GOODSMVT_CODE
IMPORTING
MATERIALDOCUMENT = LV_MATERIALDOCUMENT
MATDOCUMENTYEAR = LV_MATDOCUMENTYEAR
TABLES
GOODSMVT_ITEM = LT_GOODSMVT_ITEM
RETURN = LT_RETURN
.
9.移动类型 551
"bapi 参数
DATA:LW_GOODSMVT_HEADER TYPE BAPI2017_GM_HEAD_01,
LV_GOODSMVT_CODE TYPE BAPI2017_GM_CODE,
LT_GOODSMVT_ITEM TYPE TABLE OF BAPI2017_GM_ITEM_CREATE,
LW_GOODSMVT_ITEM TYPE BAPI2017_GM_ITEM_CREATE,
LT_RETURN TYPE TABLE OF BAPIRET2,
LW_RETURN TYPE BAPIRET2,
LV_MATERIALDOCUMENT TYPE BAPI2017_GM_HEAD_RET-MAT_DOC,
LV_MATDOCUMENTYEAR TYPE BAPI2017_GM_HEAD_RET-DOC_YEAR.
LV_GOODSMVT_CODE = '03'.
"准备抬头数据
LW_GOODSMVT_HEADER-PSTNG_DATE = SY-DATUM.
LW_GOODSMVT_HEADER-DOC_DATE = SY-DATUM. "凭证中的凭证日期
LW_GOODSMVT_HEADER-PR_UNAME = SY-UNAME. "用户名
"行项目数据
LW_GOODSMVT_ITEM-MATERIAL = ''物料号
LW_GOODSMVT_ITEM-PLANT = LS_ITEM-WERKS. " 从
LW_GOODSMVT_ITEM-STGE_LOC = LS_ITEM-LGORT.
LW_GOODSMVT_ITEM-MOVE_TYPE = '551'.
LW_GOODSMVT_ITEM-ENTRY_QNT = LS_ITEM-QTY .
LW_GOODSMVT_ITEM-BATCH = LS_ITEM-CHARG.
LW_GOODSMVT_ITEM-STCK_TYPE = LS_ITEM-INSMK .
LW_GOODSMVT_ITEM-COSTCENTER = LS_ITEM-KOSTL.
APPEND LW_GOODSMVT_ITEM TO LT_GOODSMVT_ITEM .
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
GOODSMVT_HEADER = LW_GOODSMVT_HEADER
GOODSMVT_CODE = LV_GOODSMVT_CODE
IMPORTING
MATERIALDOCUMENT = LV_MATERIALDOCUMENT
MATDOCUMENTYEAR = LV_MATDOCUMENTYEAR
TABLES
GOODSMVT_ITEM = LT_GOODSMVT_ITEM
RETURN = LT_RETURN
.
10. 移动类型 105 收货
"bapi 参数
DATA:LW_GOODSMVT_HEADER TYPE BAPI2017_GM_HEAD_01,
LV_GOODSMVT_CODE TYPE BAPI2017_GM_CODE,
LT_GOODSMVT_ITEM TYPE TABLE OF BAPI2017_GM_ITEM_CREATE,
LW_GOODSMVT_ITEM TYPE BAPI2017_GM_ITEM_CREATE,
LT_RETURN TYPE TABLE OF BAPIRET2,
LW_RETURN TYPE BAPIRET2,
LV_MATERIALDOCUMENT TYPE BAPI2017_GM_HEAD_RET-MAT_DOC,
LV_MATDOCUMENTYEAR TYPE BAPI2017_GM_HEAD_RET-DOC_YEAR.
LV_GOODSMVT_CODE = '01'.
"准备抬头数据
LW_GOODSMVT_HEADER-PSTNG_DATE = SY-DATUM.
LW_GOODSMVT_HEADER-DOC_DATE = SY-DATUM. "凭证中的凭证日期
LW_GOODSMVT_HEADER-PR_UNAME = SY-UNAME. "用户名
"行项目数据
LW_GOODSMVT_ITEM-MATERIAL = LS_MSEG-MATNR.
LW_GOODSMVT_ITEM-PLANT = LS_ITEM-WERKS.
LW_GOODSMVT_ITEM-STGE_LOC = LS_ITEM-LGORT.
LW_GOODSMVT_ITEM-MOVE_TYPE = '105'.
LW_GOODSMVT_ITEM-SPEC_STOCK = LS_MSEG-SOBKZ .
LW_GOODSMVT_ITEM-VAL_SALES_ORD = LS_MSEG-MAT_KDAUF .
LW_GOODSMVT_ITEM-VAL_S_ORD_ITEM = LS_MSEG-MAT_KDPOS .
LW_GOODSMVT_ITEM-ENTRY_QNT = LS_ITEM-ERFMG .
LW_GOODSMVT_ITEM-BATCH = LS_ITEM-CHARG.
LW_GOODSMVT_ITEM-REF_DOC_YR = LS_MSEG-MJAHR . "参考年度
LW_GOODSMVT_ITEM-REF_DOC = LS_MSEG-MBLNR . "参考凭证
LW_GOODSMVT_ITEM-REF_DOC_IT = LS_MSEG-ZEILE . "参考行项目信息
LW_GOODSMVT_ITEM-MVT_IND = 'B' .
LW_GOODSMVT_ITEM-PO_NUMBER = LS_MSEG-EBELN .
LW_GOODSMVT_ITEM-PO_ITEM = LS_MSEG-EBELP .
LW_GOODSMVT_ITEM-GR_RCPT = LS_MSEG-WEMPF . "收货方
APPEND LW_GOODSMVT_ITEM TO LT_GOODSMVT_ITEM .
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
GOODSMVT_HEADER = LW_GOODSMVT_HEADER
GOODSMVT_CODE = LV_GOODSMVT_CODE
IMPORTING
MATERIALDOCUMENT = LV_MATERIALDOCUMENT
MATDOCUMENTYEAR = LV_MATDOCUMENTYEAR
TABLES
GOODSMVT_ITEM = LT_GOODSMVT_ITEM
RETURN = LT_RETURN
.
11. 移动类型 261
"bapi 参数
DATA:LW_GOODSMVT_HEADER TYPE BAPI2017_GM_HEAD_01,
LV_GOODSMVT_CODE TYPE BAPI2017_GM_CODE,
LT_GOODSMVT_ITEM TYPE TABLE OF BAPI2017_GM_ITEM_CREATE,
LW_GOODSMVT_ITEM TYPE BAPI2017_GM_ITEM_CREATE,
LT_RETURN TYPE TABLE OF BAPIRET2,
LW_RETURN TYPE BAPIRET2,
LV_MATERIALDOCUMENT TYPE BAPI2017_GM_HEAD_RET-MAT_DOC,
LV_MATDOCUMENTYEAR TYPE BAPI2017_GM_HEAD_RET-DOC_YEAR.
LV_GOODSMVT_CODE = '04'.
"准备抬头数据
LW_GOODSMVT_HEADER-PSTNG_DATE = SY-DATUM.
LW_GOODSMVT_HEADER-DOC_DATE = SY-DATUM. "凭证中的凭证日期
LW_GOODSMVT_HEADER-PR_UNAME = SY-UNAME. "用户名
"行项目数据
LW_GOODSMVT_ITEM-MATERIAL = ''物料号
LW_GOODSMVT_ITEM-PLANT = LS_ITEM-WERKS. " 从
LW_GOODSMVT_ITEM-STGE_LOC = LS_ITEM-LGORT.
LW_GOODSMVT_ITEM-MOVE_TYPE = '261'.
LW_GOODSMVT_ITEM-reserv_no = ls_item-rsnum. "预留号
LW_GOODSMVT_ITEM-res_item = ls_item-rspos. "预留行号
LW_GOODSMVT_ITEM-orderid = ls_item-aufnr.
LW_GOODSMVT_ITEM-plant = ls_item-werks. "工厂
LW_GOODSMVT_ITEM-stge_loc = ls_item-lgort. "库存地点
LW_GOODSMVT_ITEM-batch = ls_item-charg. "批次号
LW_GOODSMVT_ITEM-entry_qnt = ls_item-erfmg. "数量
LW_GOODSMVT_ITEM-sales_ord = ls_item-kdauf. "销售订单
LW_GOODSMVT_ITEM-s_ord_item = ls_item-kdpos. "销售订单行项目
IF ls_item-kdauf IS NOT INITIAL AND ls_item-kdpos IS NOT INITIAL.
LW_GOODSMVT_ITEM-spec_stock = 'E'.
ENDIF.
APPEND LW_GOODSMVT_ITEM TO LT_GOODSMVT_ITEM .
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
GOODSMVT_HEADER = LW_GOODSMVT_HEADER
GOODSMVT_CODE = LV_GOODSMVT_CODE
IMPORTING
MATERIALDOCUMENT = LV_MATERIALDOCUMENT
MATDOCUMENTYEAR = LV_MATDOCUMENTYEAR
TABLES
GOODSMVT_ITEM = LT_GOODSMVT_ITEM
RETURN = LT_RETURN
.
12 移动类型 311 413 411
"bapi 参数
DATA:LW_GOODSMVT_HEADER TYPE BAPI2017_GM_HEAD_01,
LV_GOODSMVT_CODE TYPE BAPI2017_GM_CODE,
LT_GOODSMVT_ITEM TYPE TABLE OF BAPI2017_GM_ITEM_CREATE,
LW_GOODSMVT_ITEM TYPE BAPI2017_GM_ITEM_CREATE,
LT_RETURN TYPE TABLE OF BAPIRET2,
LW_RETURN TYPE BAPIRET2,
LV_MATERIALDOCUMENT TYPE BAPI2017_GM_HEAD_RET-MAT_DOC,
LV_MATDOCUMENTYEAR TYPE BAPI2017_GM_HEAD_RET-DOC_YEAR.
LV_GOODSMVT_CODE = '04'.
"准备抬头数据
LW_GOODSMVT_HEADER-PSTNG_DATE = SY-DATUM.
LW_GOODSMVT_HEADER-DOC_DATE = SY-DATUM. "凭证中的凭证日期
LW_GOODSMVT_HEADER-PR_UNAME = SY-UNAME. "用户名
"行项目数据
LW_GOODSMVT_ITEM-MATERIAL = ''物料号
LW_GOODSMVT_ITEM-PLANT = LS_ITEM-WERKS.
LW_GOODSMVT_ITEM-STGE_LOC = LS_ITEM-LGORT.
LW_GOODSMVT_ITEM-MOVE_TYPE = LS_HEAD-BWART.
LW_GOODSMVT_ITEM-SPEC_STOCK = LS_ITEM-SOBKZ .
LW_GOODSMVT_ITEM-ENTRY_QNT = LS_ITEM-ERFMG .
LW_GOODSMVT_ITEM-BATCH = LS_ITEM-CHARG.
LW_GOODSMVT_ITEM-MOVE_PLANT = LS_ITEM-UMWRK .
LW_GOODSMVT_ITEM-MOVE_STLOC = LS_ITEM-UMLGO .
LW_GOODSMVT_ITEM-MOVE_BATCH = LS_ITEM-UMCHA .
LW_GOODSMVT_ITEM-RESERV_NO = LS_ITEM-RSNUM.
LW_GOODSMVT_ITEM-RES_ITEM = LS_ITEM-RSPOS.
LW_GOODSMVT_ITEM-ITEM_TEXT = LS_ITEM-SGTXT .
IF LW_GOODSMVT_ITEM-MOVE_TYPE = '311'.
LW_GOODSMVT_ITEM-VAL_SALES_ORD = LS_ITEM-MAT_KDAUF . "发出的销售订单
LW_GOODSMVT_ITEM-VAL_S_ORD_ITEM = LS_ITEM-MAT_KDPOS .
LW_GOODSMVT_ITEM-SALES_ORD = LS_ITEM-KDAUF . "收到的销售订单
LW_GOODSMVT_ITEM-S_ORD_ITEM = LS_ITEM-KDPOS .
ENDIF.
IF LW_GOODSMVT_ITEM-MOVE_TYPE = '413'.
LW_GOODSMVT_ITEM-VAL_SALES_ORD = LS_ITEM-KDAUF . "收到的销售订单
LW_GOODSMVT_ITEM-VAL_S_ORD_ITEM = LS_ITEM-KDPOS .
ENDIF.
IF LW_GOODSMVT_ITEM-MOVE_TYPE = '411'.
LW_GOODSMVT_ITEM-VAL_SALES_ORD = LS_ITEM-MAT_KDAUF . "发出的销售订单
LW_GOODSMVT_ITEM-VAL_S_ORD_ITEM = LS_ITEM-MAT_KDPOS .
ENDIF.
APPEND LW_GOODSMVT_ITEM TO LT_GOODSMVT_ITEM .
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
GOODSMVT_HEADER = LW_GOODSMVT_HEADER
GOODSMVT_CODE = LV_GOODSMVT_CODE
IMPORTING
MATERIALDOCUMENT = LV_MATERIALDOCUMENT
MATDOCUMENTYEAR = LV_MATDOCUMENTYEAR
TABLES
GOODSMVT_ITEM = LT_GOODSMVT_ITEM
RETURN = LT_RETURN
.
移动类型107
这个case 遇到一个问题就是同一个采购订单,但是多个交货单
基于每一个内向交货单过账的时候,无法正确更新VL33N的凭证流,
查阅相关note:1901224
"bapi 参数
DATA:lw_goodsmvt_header TYPE bapi2017_gm_head_01,
lv_goodsmvt_code TYPE bapi2017_gm_code,
lt_goodsmvt_item TYPE TABLE OF bapi2017_gm_item_create,
lw_goodsmvt_item TYPE bapi2017_gm_item_create,
lt_return TYPE TABLE OF bapiret2,
lS_return TYPE bapiret2,
lv_materialdocument TYPE bapi2017_gm_head_ret-mat_doc,
lv_matdocumentyear TYPE bapi2017_gm_head_ret-doc_year,
ls_serialnumber TYPE bapi2017_gm_serialnumber,
lt_serialnumber TYPE STANDARD TABLE OF bapi2017_gm_serialnumber.
LOOP AT gt_data INTO gs_data WHERE box IS NOT INITIAL AND icon NE icon_green_light.
CLEAR:lw_goodsmvt_header,lt_goodsmvt_item,lt_serialnumber,lt_return,lv_materialdocument,lv_matdocumentyear.
lv_goodsmvt_code = '01'.
"准备抬头数据
lw_goodsmvt_header-pstng_date = lv_budat.
lw_goodsmvt_header-doc_date = lv_budat. "凭证中的凭证日期
lw_goodsmvt_header-pr_uname = sy-uname. "用户名
lw_goodsmvt_header-ref_doc_no = gs_data-verur_la. "参考凭证
lw_goodsmvt_header-bill_of_lading = gs_data-bolnr. "参考凭证
LOOP AT gt_lips INTO gs_lips WHERE vbeln_vl = gs_data-vbeln_vl.
"行项目数据
CLEAR:lw_goodsmvt_item.
lw_goodsmvt_item-po_number = gs_lips-ebeln. "采购凭证号
lw_goodsmvt_item-po_item = gs_lips-ebelp. "采购凭证的项目编号
lw_goodsmvt_item-deliv_numb = gs_lips-vbeln_vl. "交货单
lw_goodsmvt_item-DELIV_NUMB_TO_SEARCH = gs_lips-vbeln_vl. "交货单
lw_goodsmvt_item-deliv_item = gs_lips-posnr_vl. "交货单行号
lw_goodsmvt_item-deliv_item_TO_SEARCH = gs_lips-posnr_vl. "交货单行号
lw_goodsmvt_item-plant = gs_lips-werks. "工厂
lw_goodsmvt_item-material = gs_lips-matnr. "工厂
lw_goodsmvt_item-stge_loc = gs_lips-lgort. "库存地点
lw_goodsmvt_item-entry_qnt = gs_lips-lfimg. "以录入项单位表示的数量
lw_goodsmvt_item-mvt_ind = 'B'. "移动标识 ’B‘为采购收货 ’F ' 生产收货
lw_goodsmvt_item-move_type = '107'. "移动类型
APPEND lw_goodsmvt_item TO lt_goodsmvt_item .
CLEAR: lt_ser01.
SELECT ser01~obknr
lief_nr
posnr
obzae
sernr
matnr
FROM ser01 INNER JOIN objk ON ser01~obknr = objk~obknr
INTO CORRESPONDING FIELDS OF TABLE lt_SER01
WHERE lief_nr = gs_lips-vbeln_vl
AND posnr = gs_lips-posnr_vl.
IF sy-subrc = 0.
LOOP AT lt_SER01 INTO ls_ser01.
CLEAR:ls_serialnumber.
ls_serialnumber-matdoc_itm = gs_lips-posnr_vl+1(4).
ls_serialnumber-serialno = ls_ser01-sernr.
APPEND ls_serialnumber TO lt_serialnumber.
ENDLOOP.
ENDIF.
ENDLOOP.
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header = lw_goodsmvt_header
goodsmvt_code = lv_goodsmvt_code "MB01 按采购订单的货物移动
IMPORTING
materialdocument = lv_materialdocument
matdocumentyear = lv_matdocumentyear
TABLES
goodsmvt_item = lt_goodsmvt_item
goodsmvt_serialnumber = lt_serialnumber
return = lt_return.
IF lv_materialdocument IS NOT INITIAL .
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
gs_data-icon = icon_green_light.
gs_data-mblnr = lv_materialdocument.
ELSE.
LOOP AT lt_return INTO lS_return WHERE type CA 'EAX'.
gs_data-msg = gs_data-msg && lS_return-message.
ENDLOOP.
gs_data-icon = icon_red_light.
ENDIF.
MODIFY gt_data FROM gs_data.
ENDLOOP.