BAPI_GOODSMVT_CREATE物料凭证增强字段

人走茶凉 提交于 2021-02-02 07:23:47

项目MSEG 的 BAPI 表增强结构  BAPI_TE_XMSEG

抬头MKPF 的 BAIP 表增强 BAPI_TE_XMKPF

  • 1. 在结构BAPI_TE_XMSEG中appending structure附加结构 ZMSEG_001,增加字段LSMNG,

LSMEH

 

In The method IF_EX_MB_Hi, you can update LSMNG quantity using EXTENSIONIN structures of BAPI_GOODSMVT_CREATE. The steps are the following: Add LSMNG field in BAPI_TE_XMSEG structure create an appending structure (char field) By SE19 transaction create the Enhancement Spot starting from MB_GOODSMOVEMENT Define the Badi Implementation choosing MB_BAPI_GOODSMVT_CREATE Badi Definition implementing a new customer class.

---------------------

作者:ChampaignWolf

来源:CSDN

原文:https://blog.csdn.net/champaignwolf/article/details/80676837

版权声明:本文为博主原创文章,转载请附上博文链接!

  • 2.SE19 使用MB_GOODSMOVEMENT创建实施,实现新客户类的定义

 

 

选中行,点击赋值示例类

 

  • 3.保存并激活全部对象,

  双击实施类,可以看到方法:IF_EX_MB_BAPI_GOODSMVT_CREATE~EXTENSIONIN_TO_MATDOC

方法里面可以看到如下代码:

METHOD IF_EX_MB_BAPI_GOODSMVT_CREATE~EXTENSIONIN_TO_MATDOC.

  DATA:
    c_lenstruc          TYPE i VALUE 30,
    wa_bapi_mb_header   TYPE bapi_te_xmkpf,
    wa_bapi_mb_item     TYPE bapi_te_xmseg,
    wa_extension_in     TYPE bapiparex.

  FIELD-SYMBOLS:
    <fs_imseg>          TYPE imseg.

  CHECK NOT extension_in[] IS INITIAL.

* Analyze IMSEG for document structure and assign LINE_IDs if necessary
  CALL METHOD cl_mmim_line_id_manager=>analyze_mb_create
    CHANGING
      ct_imseg          = ct_imseg[]
    EXCEPTIONS
      duplicate_line_id = 1
      OTHERS            = 2.

  LOOP AT extension_in INTO wa_extension_in.
    CASE wa_extension_in-structure.
* extension of MKPF
      WHEN 'BAPI_TE_XMKPF'.
        MOVE wa_extension_in+c_lenstruc TO wa_bapi_mb_header.
        MOVE-CORRESPONDING wa_bapi_mb_header TO cs_imkpf.
* extension of MSEG
      WHEN 'BAPI_TE_XMSEG'.
        MOVE wa_extension_in+c_lenstruc TO wa_bapi_mb_item.
        READ TABLE ct_imseg
          WITH KEY line_id = wa_bapi_mb_item-matdoc_itm
          ASSIGNING <fs_imseg>.
        IF sy-subrc EQ 0.
          MOVE-CORRESPONDING wa_bapi_mb_item TO <fs_imseg>.
        ENDIF.
    ENDCASE.
  ENDLOOP.

ENDMETHOD.
  • 3. BAPI_GOODSMVT_CREATE 赋值表extensionin

 

* 定义过账BAPI的结构
  DATA: lt_item   TYPE TABLE OF bapi2017_gm_item_create,
        lt_return TYPE TABLE OF bapiret2.
  DATA: ls_item   TYPE bapi2017_gm_item_create,
        ls_return TYPE bapiret2,
        ls_head   TYPE bapi2017_gm_head_01,
        ls_code   TYPE bapi2017_gm_code.
  DATA: ls_extensionin TYPE bapiparex,
        lt_extensionin TYPE TABLE OF bapiparex.
  DATA: lv_mblnr   TYPE mkpf-mblnr,
        lv_mjahr   TYPE mkpf-mjahr,
        lv_flag    TYPE c,
        lv_message TYPE string,
        lv_testrun TYPE bapi2017_gm_gen-testrun,
        lv_date    TYPE sy-datum,
        lv_meins   TYPE lips-meins.



  LOOP AT gt_doc ASSIGNING <gf_doc> WHERE sel = 'X'.
    IF <gf_doc>-zstatus = 'S'.
      CONTINUE.
    ENDIF.

**clear:
    CLEAR: lv_message,lv_mblnr,lv_mjahr,
           ls_head,ls_code,
           ls_item,lt_item,
           lv_mblnr,lv_mjahr,
           ls_extensionin,lt_extensionin,
           ls_return,lt_return.

    ls_code-gm_code = '01'.

**set head
    ls_head-pstng_date = sy-datum.   "过账日期
    ls_head-doc_date   = sy-datum.   "
    ls_head-pr_uname   = sy-uname.   "
    ls_head-gr_gi_slip_no = <gf_doc>-vbeln.
    ls_head-ref_doc_no = <gf_doc>-vbeln.

**set item
    ls_item-move_type  = '101'.          "移动类型
    ls_item-mvt_ind    = 'B'.            "移动标识:有关交货通知的货物移动

    ls_item-material   = <gf_doc>-zmatnr.  "物料号码
    ls_item-entry_qnt  = <gf_doc>-zlfimg.  "数量
    ls_item-quantity   = <gf_doc>-zlfimg.
*    ls_item-batch      = <gf_doc>-zcharg.  "SAP批次
*    ls_item-move_stloc = <gf_doc>-zkcd.    "库存地点
    ls_item-deliv_numb = <gf_doc>-vbeln.  "DN
    ls_item-deliv_item = <gf_doc>-posnr.  "DN item
**输入采购订单
*PO_NUMBER
*PO_ITEM
    CLEAR: lv_meins.
    SELECT SINGLE vgbel vgpos charg meins
      INTO (ls_item-po_number,ls_item-po_item,ls_item-batch,lv_meins)
      FROM lips
     WHERE vbeln = <gf_doc>-vbeln
       AND posnr = <gf_doc>-posnr.
**工厂
    SELECT SINGLE werks
      INTO ls_item-plant
      FROM ekpo
     WHERE ebeln EQ ls_item-po_number
       AND ebelp EQ ls_item-po_item.
    ls_item-stge_loc  = <gf_doc>-zkcd."收货库存地点
    APPEND ls_item TO lt_item.
    CLEAR: ls_item.
**LSMNG LSMEH
    ls_extensionin-structure  = 'BAPI_TE_XMSEG'.
    ls_extensionin-valuepart1+14(4) = '0001'.
    ls_extensionin-valuepart1+18(16) = <gf_doc>-zlfimg.
    ls_extensionin-valuepart1+34(3) = lv_meins.
    APPEND ls_extensionin TO lt_extensionin.

    CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
      EXPORTING
        goodsmvt_header  = ls_head
        goodsmvt_code    = ls_code
        testrun          = lv_testrun
      IMPORTING
        materialdocument = lv_mblnr
        matdocumentyear  = lv_mjahr
      TABLES
        goodsmvt_item    = lt_item
        return           = lt_return
        extensionin      = lt_extensionin.

    LOOP AT lt_return INTO ls_return WHERE type = 'E' OR type = 'A'.
      lv_flag = 'E'.
      lv_message = lv_message && ls_return-message.
      EXIT.
    ENDLOOP.

    <gf_doc>-zendat = sy-datum.
    <gf_doc>-zendtm = sy-uzeit.
    <gf_doc>-usnam = sy-uname.
    IF lv_flag = 'E'.
      CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
      <gf_doc>-zstatus = 'E'.
      <gf_doc>-zmessage = lv_message.
      <gf_doc>-icon  = '@5C@'.
    ELSE.
      <gf_doc>-zstatus = 'S'.
      <gf_doc>-zmessage = '过账成功'.
      <gf_doc>-icon = '@5B@'.
      <gf_doc>-mblnr = lv_mblnr.
      <gf_doc>-mjahr = lv_mjahr.
    ENDIF.
    PERFORM frm_update_db.
  ENDLOOP.

测试出现DUMP:

要改这一段:

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!