BAPI_GOODSMVT_CREATE: Order confirmation updating - 海边星
【原创】 BAPI_GOODSMVT_CREATE: Order confirmation updating
栏目:ABAP  作者:在海边看星星  阅读:(1198)

Symptom

You want to use the BAPI to post a goods receipt for a purchase order subject to acknowledgment. The goods receipt always updates the first confirmation.


Other Terms

Order confirmation, MRP reduced quantity, ETENS


Reason and Prerequisites



Solution

This note provides example code for the EXTENSIONIN_TO_MATDOC method of the BAdI MB_BAPI_GOODSMVT_CREATE (enhancement spot MB_GOODSMOVEMENT). As a result, you can use the EXTENSIONIN table parameter to transfer the confirmation key.


This BAdI uses the customer enhancement concept for SAP tables.


First, create the following object (you can leave the default value for any settings that are not mentioned). Save and activate the new object:


Create the CI_MSEGDB structure in the ABAP dictionary (Transaction SE11) as follows:


Structure CI_MSEGDB

Short description Append structure material document item


Component Component type DTyp Length

Z_ETENS ETENS NUMC 4


Add the CI_MSEGDB structure to the BAPI_TE_XMSEG structure in the ABAP dictionary (Transaction SE11) using an include.


Component   Component type Dtyp       Length Short description

MAT_DOC    MBLNR          CHAR      10     Number of material document

DOC_YEAR    MJAHR          NUMC      4      Material document year

MATDOC_ITM  MBLPO          NUMC      4      Item in material document


.INCLUDE    CI_MSEGDB

Z_ETENS    ETENS          NUMC      4      Eg. Customer field 2


Use the BAdI builder (Transaction SE19) to create an enhancement implementation (New BADI -> Enhancement Spot -> MB_GOODSMOVEMENT) for the EXTENSIONIN_TO_MATDOC method of the MB_BAPI_GOODSMVT_CRE BAdI.


Copy the following source code to the method that you have just created:


METHOD if_ex_mb_bapi_goodsmvt_create~extensionin_to_matdoc.


  DATA:

    c_lenstr1           TYPE i VALUE 30,

    c_lenstr2           TYPE i VALUE 14,

    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_lenstr1 TO wa_bapi_mb_header+c_lenstr2.

        MOVE-CORRESPONDING wa_bapi_mb_header TO cs_imkpf.

* extension of MSEG

      WHEN 'BAPI_TE_XMSEG'.

        MOVE wa_extension_in+c_lenstr1 TO wa_bapi_mb_item+c_lenstr2.

        READ TABLE ct_imseg

          WITH KEY line_id = wa_bapi_mb_item-matdoc_itm

            ASSIGNING <fs_imseg>.

        IF sy-subrc = 0.

          <fs_imseg>-etens = wa_bapi_mb_item-z_etens.

        ENDIF.

    ENDCASE.

  ENDLOOP.


ENDMETHOD.


Example procedure:


You want to post a goods receipt for the purchase order 4500000123 (1 material with two units and two confirmation keys).


For the material document items you want


- to transfer the 0001 confirmation key for the first item

- to transfer the 0002 confirmation key for the second item


To do this, you must fill the ExtensionIn table as follows:

STRUCTURE                  VALUEPART1    ....        VALUEPART4

BAPI_TE_XMSEG              00010001

BAPI_TE_XMSEG              00020001

The values of the Valuepart1-4 variables are set as follows

:


- BAPI_TE_XMSEG

  The first four places correspond to the material document line to which you want to transfer the confirmation key. The next four places correspond to the confirmation key.


Below we have included an example program for the call of BAPI_GOODSMVT_CREATE. The program posts a goods receipt for a purchase order with a confirmation key.


The implementation described above is used.


REPORT Z_BAPI_GOODSMVT.


DATA: bapigmhead     TYPE bapi2017_gm_head_01,

      bapigmcode     TYPE bapi2017_gm_code,

      bapigmheadret  TYPE bapi2017_gm_head_ret,

      lt_messages    TYPE TABLE OF bapiret2,

      lt_extensionin TYPE TABLE OF bapiparex,

      ls_extensionin TYPE bapiparex,

      ls_imseg       TYPE bapi2017_gm_item_create,

      lt_imseg       TYPE TABLE OF bapi2017_gm_item_create.


bapigmhead-pstng_date = sy-datum.

bapigmhead-doc_date   = sy-datum.

bapigmcode-gm_code    = '01'.


ls_imseg-move_type = '101'.

ls_imseg-entry_qnt = '1'.

ls_imseg-material  = 'MATERIAL1'.

ls_imseg-plant     = '0001'.

ls_imseg-stge_loc  = '0001'.

ls_imseg-po_number = '4500000123'.

ls_imseg-po_item   = '10'.

APPEND ls_imseg TO lt_imseg.


ls_imseg-move_type = '101'.

ls_imseg-entry_qnt = '1'.

ls_imseg-material  = 'MATERIAL1'.

ls_imseg-plant     = '0001'.

ls_imseg-stge_loc  = '0001'.

ls_imseg-po_number = '4500000123'.

ls_imseg-po_item   = '10'.

APPEND ls_imseg TO lt_imseg.


ls_extensionin-structure = 'BAPI_TE_XMSEG'.

*digits 1-4 line number - digits 5-8 vendor confirmation

ls_extensionin-valuepart1 = '00010001'.

APPEND wa_extensionin TO lt_extensionin.

ls_extensionin-structure = 'BAPI_TE_XMSEG'.

ls_extensionin-valuepart1 = '00020002'.

APPEND wa_extensionin TO lt_extensionin.


CALL FUNCTION 'BAPI_GOODSMVT_CREATE'

     EXPORTING

          goodsmvt_header  = bapigmhead

          goodsmvt_code    = bapigmcode

     IMPORTING

          goodsmvt_headret = bapigmheadret

     TABLES

          return          = lt_messages

          goodsmvt_item    = lt_imseg

          extensionin      = lt_extensionin

     EXCEPTIONS

          error

          message.


IF sy-subrc = 0.

  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

   *   exporting

   *     wait          =

   *   importing

   *     return    =

endif.


转载自sap官网note 906314



我的评论
昵称
邮箱
域名
  记住 通知博主
验证码

  联系我们

微信扫一扫

 登录  打赏

  随机文章