当前位置: 首页 > article >正文

BAPI_GOODSMVT_CREATE(调拨 收货 发货 入库 退货)BAPI

一些相关的事务码:

 MB01 按采购订单的货物移动
 MB31 按生产订单的货物移动
 MB1A 货物提取(工单退料
 MB1B 转移过帐
 MB1C 其他收货
 MB11 货物移动
 MB04 "物料供应"消耗的事后调整

一些相关的移动标识:
 无参考的货物移动(空)
B 按采购订单的货物移动
F 有关生产单的货物移动 
L 有关交货通知的货物移动
K 看板需求的货物移动(WM-仅限内部)
O "提供物料"消耗的后续调整
W 比例的后续调整/产品单位物料

1、调拨单(货物移动)↓

FUNCTION zfunction.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  EXPORTING
*"     VALUE(RSTYPE) TYPE  XFELD
*"     VALUE(RSMESG) TYPE  STRING
*"     VALUE(O_MBLNR) TYPE  MBLNR
*"  TABLES
*"      ZMES_TORDER_REQ_I STRUCTURE  ZMES_TORDER_REQ_I
*"----------------------------------------------------------------------
*输入表数据:ZMES_TORDER_REQ_I(表结构)  
*  PSTNG_DATE type    BUDAT        凭证中的过帐日期
*  MATERIAL    MATNR            物料号 
*  PLANT    WERKS_D    CHAR      工厂
*  MOVE_PLANT    UMWRK          收货/发货工厂
*  STGE_LOC    LGORT_D          库存地点
*  MOVE_STLOC    UMLGO          收货/发货库存地点
*  ENTRY_QNT    ERFMG            以输入单位计的数量 
*  BATCH    CHARG_D                批号
*"----------------------------------------------------------------------

  DATA:goodsmvt_header  LIKE  bapi2017_gm_head_01,
        itab  TYPE TABLE OF bapi2017_gm_item_create WITH HEADER LINE,
        return  LIKE TABLE OF bapiret2 WITH HEADER LINE,
        mat_doc LIKE  bapi2017_gm_head_ret-mat_doc,
        req_i TYPE zmes_torder_req_i.


  CLEAR:goodsmvt_header.
  goodsmvt_header-doc_date = sy-datum.    "凭证中的凭证日期
  goodsmvt_header-pr_uname = sy-datum.    "用户名

  LOOP AT zmes_torder_req_i INTO req_i.
    MOVE-CORRESPONDING req_i TO itab.
    goodsmvt_header-pstng_date = req_i-pstng_date.  "凭证中的过帐日期
    IF req_i-plant = req_i-move_plant.
      itab-move_type = '311'.                         "移动类型(库储存地点<->库存地点)
    ELSE.
*      itab-move_type = '301'.                         "移动类型(工厂<->工厂)
    ENDIF.
    APPEND itab.
    CLEAR itab.
  ENDLOOP.

  CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
    EXPORTING
      goodsmvt_header  = goodsmvt_header
      goodsmvt_code    = '04'
    IMPORTING
      materialdocument = mat_doc
    TABLES
      goodsmvt_item    = itab
      return           = return.
  READ TABLE return WITH KEY type = 'E'.
  IF  sy-subrc = 0.
    rstype = 'E'.
    LOOP AT return WHERE type = 'E' .
      CONCATENATE rsmesg return-message ',' INTO rsmesg.
    ENDLOOP.
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK' .
  ELSE.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'.
    rstype = 'S'.
    o_mblnr = mat_doc.
  ENDIF.
ENDFUNCTION.

2、工单发料 ↓

function zfunction.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  EXPORTING
*"     VALUE(RSTYPE) TYPE  XFELD
*"     VALUE(RSMESG) TYPE  STRING
*"     VALUE(O_MBLNR) TYPE  MBLNR
*"  TABLES
*"      ZMES_ORD_REQ_I STRUCTURE  ZMES_ORD_REQ_I
*"----------------------------------------------------------------------
*输入表:ZMES_ORD_REQ_I(表结构)
*  PLANT     WERKS_D      工厂
*  ORDERID    AUFNR        订单号 
*  MATERIAL    MATNR      物料号 
*  ENTRY_QNT    ERFMG      以输入单位计的数量 
*  STGE_LOC    LGORT_D    库存地点
*"----------------------------------------------------------------------
  data:goodsmvt_header  like  bapi2017_gm_head_01,
        itab  type table of bapi2017_gm_item_create with header line,
        return  like table of bapiret2 with header line,
        mat_doc like  bapi2017_gm_head_ret-mat_doc,
        req_i type zmes_ord_req_i.


  clear:goodsmvt_header.
  goodsmvt_header-doc_date = sy-datum.    "凭证中的凭证日期
  goodsmvt_header-pstng_date = sy-datum.  "凭证中的过帐日期
  goodsmvt_header-pr_uname = sy-datum.    "用户名

  loop at zmes_ord_req_i into req_i.
    move-CORRESPONDING req_i to itab.
    itab-move_type = '261'. "移动类型(库存管理)
    append itab.
    clear itab.
  endloop.

  call function 'BAPI_GOODSMVT_CREATE'
  exporting
    goodsmvt_header  = goodsmvt_header
    goodsmvt_code    = '03'
  importing
    materialdocument = mat_doc
  tables
    goodsmvt_item    = itab
    return           = return.
  read table return with key type = 'E'.
  if  sy-subrc = 0.
    rstype = 'E'.
    loop at return where type = 'E' .
      concatenate rsmesg return-message ',' into rsmesg.
    endloop.
    call function 'BAPI_TRANSACTION_ROLLBACK' .
  else.
    call function 'BAPI_TRANSACTION_COMMIT'
    exporting
      wait = 'X'.
    rstype = 'S'.
    o_mblnr = mat_doc.
  endif.
endfunction.

3、工单退料 ↓

function zfunction.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  EXPORTING
*"     VALUE(RSTYPE) TYPE  XFELD
*"     VALUE(RSMESG) TYPE  STRING
*"     VALUE(O_MBLNR) TYPE  MBLNR
*"  TABLES
*"      ZMES_RT_ORDER_I STRUCTURE  ZMES_RT_ORDER_I
*"----------------------------------------------------------------------
*输入表:ZMES_RT_ORDER_I(表结构)
*  PLANT    WERKS_D         工厂
*  ORDERID    AUFNR         订单号 
*  MATERIAL    MATNR          物料号 
*  RESERV_NO    RSNUM             预留/相关需求的编号
*  RES_ITEM    RSPOS             预留/相关需求的项目编号
*  ENTRY_QNT    ERFMG             以输入单位计的数量 
*  MOVE_REAS    MB_GRBEW      移动原因
*  STGE_LOC    LGORT_D           库存地点
*  BATCH    CHARG_D               批号
*"----------------------------------------------------------------------
  data:goodsmvt_header  like  bapi2017_gm_head_01,
        itab  type table of bapi2017_gm_item_create with header line,
        return  like table of bapiret2 with header line,
        mat_doc like  bapi2017_gm_head_ret-mat_doc,
        order_i type zmes_rt_order_i.

  clear:goodsmvt_header.
  goodsmvt_header-doc_date = sy-datum.    "凭证中的凭证日期
  goodsmvt_header-pstng_date = sy-datum.  "凭证中的过帐日期
  goodsmvt_header-pr_uname = sy-datum.    "用户名

  loop at zmes_rt_order_i into order_i.
    move-corresponding order_i to itab.
    itab-move_type = '262'. "移动类型(库存管理)
    append itab.
    clear itab.
  endloop.

  call function 'BAPI_GOODSMVT_CREATE'
  exporting
    goodsmvt_header  = goodsmvt_header
    goodsmvt_code    = '03'
  importing
    materialdocument = mat_doc
  tables
    goodsmvt_item    = itab
    return           = return.
  read table return with key type = 'E'.
  if  sy-subrc = 0.
    rstype = 'E'.
    loop at return where type = 'E' .
      concatenate rsmesg return-message ',' into rsmesg.
    endloop.
    call function 'BAPI_TRANSACTION_ROLLBACK' .
  else.
    call function 'BAPI_TRANSACTION_COMMIT'
    exporting
      wait = 'X'.
    rstype = 'S'.
    o_mblnr = mat_doc.
  endif.
endfunction.

4、工单入库 ↓

FUNCTION zfunction.
  FUNCTION zmes_order_in.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  EXPORTING
*"     VALUE(RSTYPE) TYPE  XFELD
*"     VALUE(RSMESG) TYPE  STRING
*"     VALUE(O_MBLNR) TYPE  MBLNR
*"  TABLES
*"      ZMES_ORDER_IN_I STRUCTURE  ZMES_ORDER_IN_I
*"----------------------------------------------------------------------
*输入表:ZMES_ORDER_IN_I(表结构)
*    PLANT  WERKS_D       工厂
*    ORDERID  AUFNR       订单号
*    ENTRY_QNT  ERFMG     以输入单位计的数量
*    STGE_LOC    LGORT_D      库存地点
*    BATCH  CHARG_D       批号
*"----------------------------------------------------------------------
    DATA:header  LIKE  bapi2017_gm_head_01,
          code LIKE  bapi2017_gm_code,
          itab  TYPE TABLE OF bapi2017_gm_item_create WITH HEADER LINE,
          return  LIKE TABLE OF bapiret2 WITH HEADER LINE,
          mat_doc LIKE  bapi2017_gm_head_ret-mat_doc,
          goodsmvt_serialnumber TYPE TABLE OF bapi2017_gm_serialnumber,
          order_in TYPE zmes_order_in_i.

    CLEAR:header,code.
    header-doc_date = sy-datum.    "凭证中的凭证日期
    header-pstng_date = sy-datum.  "凭证中的过帐日期
    header-pr_uname = sy-datum.    "用户名

    code-gm_code = '01'.

    LOOP AT zmes_order_in_i INTO order_in.
      MOVE-CORRESPONDING order_in TO itab.
      itab-move_type = '101'.             "移动类型
      itab-mvt_ind = 'F'.                 "移动标识
      APPEND itab.
      CLEAR itab.
    ENDLOOP.

    CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
      EXPORTING
        goodsmvt_header       = header
        goodsmvt_code         = code
      IMPORTING
        materialdocument      = mat_doc
      TABLES
        goodsmvt_item         = itab
        goodsmvt_serialnumber = goodsmvt_serialnumber
        return                = return.
    READ TABLE return WITH KEY type = 'E'.
    IF  sy-subrc = 0.
      rstype = 'E'.
      LOOP AT return WHERE type = 'E' .
        CONCATENATE rsmesg return-message ',' INTO rsmesg.
      ENDLOOP.
      CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK' .
    ELSE.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        EXPORTING
          wait = 'X'.
      rstype = 'S'.
      o_mblnr = mat_doc.
    ENDIF.
  ENDFUNCTION.
ENDFUNCTION.

5、PO退货 ↓

FUNCTION zfunction.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  EXPORTING
*"     VALUE(RSTYPE) TYPE  XFELD
*"     VALUE(RSMESG) TYPE  STRING
*"     VALUE(O_MBLNR) TYPE  MBLNR
*"  TABLES
*"      ZMES_PO_STOCK_I STRUCTURE  ZMES_PO_STOCK_I
*"----------------------------------------------------------------------
*输入表:ZMES_PO_STOCK_I(表结构)
*  MOVE_TYPE  BWART   移动类型(库存管理)
*  PO_NUMBER  BSTNR   采购订单编号
*  PO_ITEM  EBELP     采购凭证的项目编号
*  PLANT  WERKS_D     工厂
*  MATERIAL    MATNR      物料号
*  ENTRY_QNT  ERFMG   以输入单位计的数量
*  STGE_LOC LGORT_D       库存地点
*  MOVE_REAS  MB_GRBEW      移动原因
*  REF_DOC  MBLNR           物料凭证编号
*  REF_DOC_IT LFPOS       参考凭证项目
*"----------------------------------------------------------------------
  DATA:header  LIKE  bapi2017_gm_head_01,
        itab  TYPE TABLE OF bapi2017_gm_item_create WITH HEADER LINE,
        return  LIKE TABLE OF bapiret2 WITH HEADER LINE,
        mat_doc LIKE  bapi2017_gm_head_ret-mat_doc,
        stock_i TYPE zmes_po_stock_i.

  CLEAR:header.
  header-doc_date = sy-datum.    "凭证中的凭证日期
  header-pstng_date = sy-datum.  "凭证中的过帐日期
  header-pr_uname = sy-datum.    "用户名

  LOOP AT zmes_po_stock_i INTO stock_i.
    MOVE-CORRESPONDING stock_i TO itab.
    itab-mvt_ind = 'B'.                 "移动标识
    CASE stock_i-move_type.
      WHEN '102'.
        itab-move_reas = ''.            "移动原因
      WHEN '122'.
      WHEN '161'.
        itab-move_type = '101'.        "移动类型
        itab-ref_doc = ''.             "物料凭证
        itab-ref_doc_it = ''.          "物料凭证项目
        itab-move_reas = ''.           "移动原因
    ENDCASE.
    APPEND itab.
    CLEAR itab.
  ENDLOOP.

  CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
    EXPORTING
      goodsmvt_header  = header
      goodsmvt_code    = '01'          "MB01 按采购订单的货物移动
    IMPORTING
      materialdocument = mat_doc
    TABLES
      goodsmvt_item    = itab
      return           = return.
  READ TABLE return WITH KEY type = 'E'.
  IF  sy-subrc = 0.
    rstype = 'E'.
    LOOP AT return WHERE type = 'E' .
      CONCATENATE rsmesg return-message ',' INTO rsmesg.
    ENDLOOP.
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK' .
  ELSE.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'.
    rstype = 'S'.
    o_mblnr = mat_doc.
  ENDIF.
ENDFUNCTION.

6、收货 ↓

FUNCTION zfunction.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  EXPORTING
*"     VALUE(RSTYPE) TYPE  XFELD
*"     VALUE(RSMESG) TYPE  STRING
*"     VALUE(O_MBLNR) TYPE  MBLNR
*"  TABLES
*"      ZMES_PO_IN STRUCTURE  ZMES_PO_IN
*"----------------------------------------------------------------------
*输入表:ZMES_PO_IN(表结构)
*  REF_DOC_NO    XBLNR      参考凭证编号
*  PLANT  WERKS_D       工厂
*  PO_NUMBER  EBELN     采购凭证号
*  PO_ITEM  EBELP       采购凭证的项目编号
*  ETENS  EETEN         交货计划行计数器
*  MATERIAL MATNR     物料号
*  STGE_LOC    LGORT_D      库存地点
*  ENTRY_QNT  ERFMG     以输入单位计的数量
*  VENDOR    ELIFN          供应商帐户号
*  BATCH  CHARG_D       批号

*"----------------------------------------------------------------------
  DATA:header  LIKE  bapi2017_gm_head_01,
        code LIKE  bapi2017_gm_code,
        itab  TYPE TABLE OF bapi2017_gm_item_create WITH HEADER LINE,
        return  LIKE TABLE OF bapiret2 WITH HEADER LINE,
        mat_doc LIKE  bapi2017_gm_head_ret-mat_doc,
        po_in TYPE zmes_po_in.

  CLEAR:header,code.
  header-doc_date = sy-datum.    "凭证中的凭证日期
  header-pstng_date = sy-datum.  "凭证中的过帐日期
  header-pr_uname = sy-datum.    "用户名
  header-ref_doc_no =  zmes_po_in-ref_doc_no.    "外向交货单

  code-gm_code = '01'. "为 BAPI 货物移动分配事务代码  4500090063

  LOOP AT zmes_po_in INTO po_in.
    MOVE-CORRESPONDING po_in TO itab.
    itab-move_type = '101'.             "移动类型
    itab-mvt_ind = 'B'.                 "移动标识
    APPEND itab.
    CLEAR itab.
  ENDLOOP.

  CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
    EXPORTING
      goodsmvt_header  = header
      goodsmvt_code    = code
    IMPORTING
      materialdocument = mat_doc
    TABLES
      goodsmvt_item    = itab
      return           = return.
  READ TABLE return WITH KEY type = 'E'.
  IF  sy-subrc = 0.
    rstype = 'E'.
    LOOP AT return WHERE type = 'E' .
      CONCATENATE rsmesg return-message ',' INTO rsmesg.
    ENDLOOP.
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK' .
  ELSE.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'.
    rstype = 'S'.
    o_mblnr = mat_doc.
  ENDIF.
ENDFUNCTION.

7、IQC入库 ↓

FUNCTION zfunction.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  EXPORTING
*"     VALUE(RSTYPE) TYPE  XFELD
*"     VALUE(RSMESG) TYPE  STRING
*"     VALUE(O_MBLNR) TYPE  MBLNR
*"  TABLES
*"      ZMES_PO_IQC_I STRUCTURE  ZMES_PO_IQC_I
*"----------------------------------------------------------------------
*输入表:ZMES_PO_IQC_I(表结构)
*  PLANT  WERKS_D       工厂
*  MATERIAL    MATNR        物料号
*  ENTRY_QNT  ERFMG     以输入单位计的数量
*  STGE_LOC    LGORT_D      库存地点
*  BATCH  CHARG_D       批号
*"----------------------------------------------------------------------
  DATA:header  LIKE  bapi2017_gm_head_01,
        itab  TYPE TABLE OF bapi2017_gm_item_create WITH HEADER LINE,
        return  LIKE TABLE OF bapiret2 WITH HEADER LINE,
        mat_doc LIKE  bapi2017_gm_head_ret-mat_doc,
        goodsmvt_serialnumber TYPE TABLE OF bapi2017_gm_serialnumber,
        iqc_in TYPE zmes_po_iqc_i.

  CLEAR:header.
  header-doc_date = sy-datum.    "凭证中的凭证日期
  header-pstng_date = sy-datum.  "凭证中的过帐日期
  header-pr_uname = sy-datum.    "用户名

  LOOP AT zmes_po_iqc_i INTO iqc_in.
    MOVE-CORRESPONDING iqc_in TO itab.
    itab-move_type = '321'.             "移动类型
    APPEND itab.
    CLEAR itab.
  ENDLOOP.

  CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
    EXPORTING
      goodsmvt_header       = header
      goodsmvt_code         = '04'     "为BAPI货物移动分配事务代码(MB1B 转移过帐)
    IMPORTING
      materialdocument      = mat_doc
    TABLES
      goodsmvt_item         = itab
      goodsmvt_serialnumber = goodsmvt_serialnumber
      return                = return.
  READ TABLE return WITH KEY type = 'E'.
  IF  sy-subrc = 0.
    rstype = 'E'.
    LOOP AT return WHERE type = 'E' .
      CONCATENATE rsmesg return-message ',' INTO rsmesg.
    ENDLOOP.
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK' .
  ELSE.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'.
    rstype = 'S'.
    o_mblnr = mat_doc.
  ENDIF.
ENDFUNCTION.

如有不完整或其他错误,在评论区留言即可。


http://www.kler.cn/a/4321.html

相关文章:

  • 【力扣Hot 100】普通数组1
  • GitLab集成Jira
  • 《小迪安全》学习笔记05
  • ASP.NET Core - 缓存之分布式缓存
  • Redis哨兵(Sentinel)
  • 信号与系统初识---信号的分类
  • Android Jetpack从使用到源码深耕【开篇】
  • 【洛谷P8306】【模板】字典树
  • 两篇2023 ICLR多模态论文分享(模态互补性对多模态鲁棒性影响 与 对多模表示学习有效的单模学习)
  • 最近的学习目标
  • leetcode112:路径总和
  • wait讲解
  • 网络排查命令
  • JavaScript中链式调用大合集、应付面试够够的
  • 在服务器中使用Docker安装Tomcat、同时实现目录挂载、并且部署War包到服务器
  • VMware虚拟机与主机无法互传文件的解决办法
  • 记录一下,win11,单击zip文件后文件管理器闪退
  • 蓝桥杯C/C++VIP试题每日一练之Sine之舞
  • Java 学习
  • 系统分析——系统构建最重要的一环
  • 链表、双链表的插入和删除
  • PhotoZoom Pro2023免费版图形图像放大工具
  • Maven <repository> 配置小知识
  • Visual Genome数据集简介
  • SpringBoot 将PDF转成图片或Word
  • 08基于拉丁超立方法的风光场景生成与削减