码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2020-01-19 11:07:22      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:表数   tor   rfc   收货   ldo   产品   exp   库存管理   cas   

code-gm_code取值:

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

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

 

下 面  代 码 都 已 封 装 为 RFC

调拨单(货物移动)

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.

工单发料

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.

工单退料

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.

工单入库

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.

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.

收货

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.

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.

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

标签:表数   tor   rfc   收货   ldo   产品   exp   库存管理   cas   

原文地址:https://www.cnblogs.com/freeandeasy/p/12212800.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!