【Demo】采购订单收货Bapi

   日期:2020-10-30     浏览:88    评论:0    
核心提示:基于SAP采购订单的收货可使用物料移动中常用的Bapi函数“BAPI_GOODSMVT_CREATE”来处理,其中GOODSMVT_CODE采用“01”,也就是MB01界面的功能。其中支持多个不同采购订单的收货,最后不会忘记Commit提交,否则只会产生物料凭证,而不会实质记录。下面是一个测试Demo。*&---------------------------------------------------------------------**& Report ZTEST

基于SAP采购订单的收货可使用物料移动中常用的Bapi函数“BAPI_GOODSMVT_CREATE”来处理,其中GOODSMVT_CODE采用“01”,也就是MB01界面的功能。其中支持多个不同采购订单的收货,最后不会忘记Commit提交,否则只会产生物料凭证,而不会实质记录。

下面是一个测试Demo。

*&---------------------------------------------------------------------*
*& Report  ZTEST_POGR
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZTEST_POGR.


START-OF-SELECTION.

  DATA: LS_HEADER  LIKE  BAPI2017_GM_HEAD_01,
        LV_CODE    LIKE  BAPI2017_GM_CODE VALUE '01',
        LV_DOC     TYPE  BAPI2017_GM_HEAD_RET-MAT_DOC,
        LV_YEAR    TYPE  BAPI2017_GM_HEAD_RET-DOC_YEAR,
        LT_ITEM    LIKE  BAPI2017_GM_ITEM_CREATE OCCURS 0 WITH HEADER LINE,
        LT_RET     LIKE  BAPIRET2 OCCURS 0 WITH HEADER LINE.

*** Header
  LS_HEADER-PSTNG_DATE  = '20160701'.
  LS_HEADER-DOC_DATE    = '20160701'.
  LS_HEADER-HEADER_TXT  = 'Header Text'.

*** Item
  LT_ITEM-MATERIAL      = 'F-F-H300'.
  PERFORM CONVERSION_EXIT_MATN1_INPUT USING LT_ITEM-MATERIAL.
  LT_ITEM-VENDOR        = 'H5Q9'.
  PERFORM CONVERSION_EXIT_ALPHA_INPUT USING LT_ITEM-VENDOR.
  LT_ITEM-PLANT         = 'CN32'.
  LT_ITEM-PO_NUMBER     = '4500039125'.
  LT_ITEM-PO_ITEM       =  '10'.
  PERFORM CONVERSION_EXIT_MATN1_INPUT USING LT_ITEM-PO_ITEM.
  LT_ITEM-ITEM_TEXT  = LT_ITEM-PO_ITEM.
  LT_ITEM-ENTRY_QNT     = 10.
  LT_ITEM-STGE_LOC      = 'RC10'.
  LT_ITEM-MVT_IND       = 'B'.
  LT_ITEM-MOVE_TYPE     = '101'.
  LT_ITEM-ENTRY_UOM     = 'EA'.
  APPEND LT_ITEM.CLEAR LT_ITEM.

  LT_ITEM-MATERIAL      = 'C-S1-300'.
  PERFORM CONVERSION_EXIT_MATN1_INPUT USING LT_ITEM-MATERIAL.
  LT_ITEM-VENDOR        = 'H5Q9'.
  PERFORM CONVERSION_EXIT_ALPHA_INPUT USING LT_ITEM-VENDOR.
  LT_ITEM-PLANT         = 'CN32'.
  LT_ITEM-PO_NUMBER     = '4500039124'.
  LT_ITEM-PO_ITEM       =  '10'.
  PERFORM CONVERSION_EXIT_MATN1_INPUT USING LT_ITEM-PO_ITEM.
  LT_ITEM-ITEM_TEXT  = LT_ITEM-PO_ITEM.
  LT_ITEM-ENTRY_QNT     = 10.
  LT_ITEM-STGE_LOC      = 'RC10'.
  LT_ITEM-MVT_IND       = 'B'.
  LT_ITEM-MOVE_TYPE     = '101'.
  LT_ITEM-ENTRY_UOM     = 'EA'.
  APPEND LT_ITEM.CLEAR LT_ITEM.

  "过账
  PERFORM BAPI_GOODS_MOVE TABLES LT_ITEM  LT_RET
                    USING LS_HEADER  LV_CODE  LV_DOC LV_YEAR .
  COMMIT WORK.
  WRITE : / LV_DOC,LV_YEAR.
  IF LT_RET[] IS NOT INITIAL.
    LOOP AT LT_RET.
      WRITE : / LT_RET-TYPE,LT_RET-MESSAGE.
    ENDLOOP.
  ENDIF.

*&---------------------------------------------------------------------*
*&      Form  BAPI_GOODS_MOVE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_LT_ITEM  text
*      -->P_LT_RET  text
*      -->P_LS_HEADER  text
*      -->P_LV_CODE  text
*      -->P_LV_DOC  text
*      -->P_LV_YEAR  text
*----------------------------------------------------------------------*
FORM BAPI_GOODS_MOVE  TABLES  LT_ITEM   STRUCTURE BAPI2017_GM_ITEM_CREATE
                               LT_RET    STRUCTURE BAPIRET2
                      USING    LS_HEADER STRUCTURE BAPI2017_GM_HEAD_01
                               LV_CODE
                               LV_DOC
                               LV_YEAR.

  CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
    EXPORTING
      GOODSMVT_HEADER  = LS_HEADER
      GOODSMVT_CODE    = LV_CODE
    IMPORTING
      MATERIALDOCUMENT = LV_DOC
      MATDOCUMENTYEAR  = LV_YEAR
    TABLES
      GOODSMVT_ITEM    = LT_ITEM
      RETURN           = LT_RET.

ENDFORM.                    " BAPI_GOODS_MOVE
*&---------------------------------------------------------------------*
*&      Form  CONVERSION_EXIT_MATN1_INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_MATNR  text
*----------------------------------------------------------------------*
FORM CONVERSION_EXIT_MATN1_INPUT  USING    P_MATNR.
  CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
    EXPORTING
      INPUT        = P_MATNR
    IMPORTING
      OUTPUT       = P_MATNR
    EXCEPTIONS
      LENGTH_ERROR = 1
      OTHERS       = 2.

ENDFORM.                    " CONVERSION_EXIT_MATN1_INPUT
*&---------------------------------------------------------------------*
*&      Form  CONVERSION_EXIT_ALPHA_INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_LT_101_LIFNR  text
*----------------------------------------------------------------------*
FORM CONVERSION_EXIT_ALPHA_INPUT  USING    P_LIFNR.
  CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
    EXPORTING
      INPUT  = P_LIFNR
    IMPORTING
      OUTPUT = P_LIFNR.
ENDFORM.                    " CONVERSION_EXIT_ALPHA_INPUT

附加内容:

GMCODE TCODE:

  1. GM_Code 01: Goods receipt for purchase order
  2. GM_Code 02: Goods receipt for production order
  3. GM_Code 03: Goods issue
  4. GM_Code 04: Transfer posting
  5. GM_Code 05: Other goods receipts
  6. GM_Code 06: Reversal of goods movements
  7. GM_Code 07: Subsequent adjustment to a subcontract order

 

 
打赏
 本文转载自:网络 
所有权利归属于原作者,如文章来源标示错误或侵犯了您的权利请联系微信13520258486
更多>最近资讯中心
更多>最新资讯中心
0相关评论

推荐图文
推荐资讯中心
点击排行
最新信息
新手指南
采购商服务
供应商服务
交易安全
关注我们
手机网站:
新浪微博:
微信关注:

13520258486

周一至周五 9:00-18:00
(其他时间联系在线客服)

24小时在线客服