• BAPI_GOODSMVT_CREATE物料凭证创建…


    'BAPI_GOODSMVT_CREATE可以实现物料凭证创建和部分冲销

    全部冲销可以使用BAPI_GOODSMVT_CANCEL


    CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
            EXPORTING
              GOODSMVT_HEADER  GOODSMVT_HEADER
              GOODSMVT_CODE    GOODSMVT_CODE
            IMPORTING
              MATERIALDOCUMENT MATERIALDOCUMENT
              MATDOCUMENTYEAR  MATDOCUMENTYEAR
            TABLES
              GOODSMVT_ITEM    GOODSMVT_ITEM[]
              RETURN           RETURN[].

     

    抬头部分给值:

      GOODSMVT_HEADER-PSTNG_DATE SY-DATUM.
        GOODSMVT_HEADER-DOC_DATE SY-DATUM.
        GOODSMVT_HEADER-PR_UNAME SY-UNAME.
        GOODSMVT_HEADER-REF_DOC_NO S_PBLNR-low.
        GOODSMVT_HEADER-HEADER_TXT 'Packing List Post'.
        GOODSMVT_CODE '04'.


    行项目部分给值(根据移动类型有差异):

      loop at gt_itab WHERE WERKS GT_ITAB1-WERKS.
            GOODSMVT_ITEM-MATERIAL gt_itab-matnr.
            GOODSMVT_ITEM-PLANT gt_itab-werks.
            GOODSMVT_ITEM-STGE_LOC gt_itab-lgort.
            GOODSMVT_ITEM-MOVE_TYPE '311'.
            GOODSMVT_ITEM-ENTRY_QNT gt_itab-menge.
            GOODSMVT_ITEM-ENTRY_UOM gt_itab-meins.
            GOODSMVT_ITEM-ITEM_TEXT gt_itab-MBLNR.
            GOODSMVT_ITEM-MOVE_PLANT gt_itab-werks.
            if gt_itab-lgort+0(1) 'B'.
              GOODSMVT_ITEM-MOVE_STLOC 'B902'.
            elseif gt_itab-lgort+0(1) 'C'.
              GOODSMVT_ITEM-MOVE_STLOC 'C902'.
            ENDIF.
            append GOODSMVT_ITEM.
          endloop.


    冲销时与正常创建凭证一样,只是BAPI2017_GM_ITEM_CREATE-XSTOB 'X'. "冲销标志 移动类型为正向,比如261发料,做262的冲销,移动类型仍给261,不需要修改,此处打叉即可


    MBST冲销整个凭证: 

            CALL FUNCTION 'BAPI_GOODSMVT_CANCEL'
            EXPORTING
              materialdocument gt_up-MBLNR
              matdocumentyear  gt_up-MJAHR
            IMPORTING
              GOODSMVT_HEADRET GOODSMVT_HEADRET
            TABLES
              RETURN           RETURN.

     

    bapi_goodsmvt_create中goodsmvt_code对应值(T158G)

    01 MB01

    02 MB31

    03 MB1A

    04 MB1B

    05 MB1C

    06 MB11

    07 MB04


     BAPI2017_GM_ITEM_CREATE-mvt_ind(Domain:KZBEW) Movement Indicator
         Goods movement w/o reference
     Goods movement for purchase order
     Goods movement for production order
     Goods movement for delivery note
     Goods movement for kanban requirement (WM internal only)
     Subsequent adjustment of "material-provided" consumption
     Subsequent adjustment of proportion/product unit material


    参考:

    http://hi.baidu.com/tktik/item/2b0b2017faa5ab21f7625c7d


    一个部分冲销的例子;

    FORM bapi_process.

      CLEAR gdsmt_item.

      REFRESH gdsmt_item[].

      LOOP AT gii_tab.

    *    SHIFT gii_tab-kdauf LEFT DELETING LEADING '0'.

    *    SHIFT GII_TAB-KDPOS LEFT DELETING LEADING '0'.

        MOVE '313' TO gdsmt_item-move_type.   "移动类型

        MOVE gii_tab-sobkz TO gdsmt_item-spec_stock.  

        MOVE gii_tab-matnr TO gdsmt_item-material.  "物料

        MOVE gii_tab-gmnga TO gdsmt_item-entry_qnt. "数量

        MOVE gii_tab-meinh TO gdsmt_item-entry_uom. "单位

        MOVE gii_tab-werks TO gdsmt_item-plant. "工厂

        MOVE 'LW01' TO gdsmt_item-stge_loc.

        MOVE gii_tab-lgort TO gdsmt_item-move_stloc.

    *    MOVE gii_tab-lgort TO gdsmt_item-stge_loc.

    *    MOVE 'LW01' TO gdsmt_item-move_stloc.

        MOVE 'X' TO gdsmt_item-xstob.    "冲销标志

        MOVE gii_tab-kdauf TO gdsmt_item-val_sales_ord.

        MOVE gii_tab-kdpos TO gdsmt_item-val_s_ord_item.

        MOVE gii_tab-ktext TO gdsmt_item-item_text.

        MOVE gii_tab-aufnr TO gdsmt_item-gr_rcpt.



        APPEND gdsmt_item.

      ENDLOOP.

      IF NOT gdsmt_item[] IS INITIAL.

        CALL FUNCTION 'BAPI_GOODSMVT_CREATE'

          EXPORTING

            goodsmvt_header  = gdsmt_header

            goodsmvt_code    = gdsmt_code

          IMPORTING

            materialdocument = mat_doc

          TABLES

            goodsmvt_item    = gdsmt_item

            return           = return.


        LOOP AT return.

          CLEAR loc_msg.

          CONCATENATE '冲销成功!' return-message INTO loc_msg.

          IF return-type EQ 'E'.

            MESSAGE return-message TYPE 'E'.

            errflag = 'X'.

          ELSE.

            MESSAGE loc_msg TYPE 'S'.

          ENDIF.

        ENDLOOP.

        IF errflag IS INITIAL.

          COMMIT WORK AND WAIT.

          CLEAR loc_msg.

          IF sy-subrc NE 0.

            MESSAGE '冲销操作出现错误,请稍后重试!' TYPE 'E'.

            EXIT.

          ELSE.

            CONCATENATE '冲销物料凭证:' mat_doc '已成功创建!' INTO loc_msg.

            MESSAGE i184(sabapdocu) WITH loc_msg.

          ENDIF.

        ELSE.

          MESSAGE   '冲销有误!' TYPE 'E'.

        ENDIF.

        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

          EXPORTING

            wait = 'X'.

      ENDIF.

    ENDFORM.                    "bapi_process

    http://blog.sina.com.cn/sapliumeng
  • 相关阅读:
    Enum, Generic and Templates
    Writing A Threadpool in Rust
    A First Look at Rust Language
    Closures in OOC
    Complexity Behind Closure
    Introduction to OOC Programming Language
    OOC,泛型,糟糕的设计。
    Enlightenment笔记
    Machine Learning/Random Projection
    Machine Learning/Introducing Logistic Function
  • 原文地址:https://www.cnblogs.com/senlinmu110/p/3802119.html
Copyright © 2020-2023  润新知