Skip to Content

When attachment is added to PR and when we create Purchase Order (PO) based on Purchase Requisition (PR), then all the attachment attached to PR line Item will be copied from PR to PO automatically. But if we are using BAPI to create PO, then attachments won’t get transferred to PO. When I searched for such requirement, I did not get any solution. Hence I have designed and sharing the same which might be useful for few members. Below code will help to transfer the DMS document id (attachments) from PR to PO while using BAPI to create PO . This function need to be called after committing “BAPI_PO_CHANGE” OR  “BAPI_PO_CREATE1” BAPI. PR number will be passed as input to this function module.

FUNCTION zm_copy_att_from_pr_to_po.

*”———————————————————————-

*”*”Local Interface:

*”  IMPORTING

*”     VALUE(I_BANFN) TYPE  BANFN

*”  TABLES

*”      T_RETURN STRUCTURE  BAPIRETURN

*”  EXCEPTIONS

*”      NO_PURCHAING_DATA

*=============================================================================*

*—————————————————————————–*

* Function Module  : ZM_COPY_ATT_FROM_PR_TO_PO                                *

* Author           : Sasikanth SM (XSSM)                                      *

* Date             : 05/15/2015                                               *

* Thread Manager ID:                                                          *

*—————————————————————————–*

* Type of Program  : Function Module                                          *

* Purpose          : This function will copy the DMS document id attached     *

*                    to PR and link the same to PO                            *

* Transport Req    :                                                          *

*—————————————————————————–*

  DATA: w_drad          TYPE drad,

        i_drad          TYPE TABLE OF drad,

        i_dradn         TYPE TABLE OF  drad_n,

        w_dradn         TYPE drad_n,

        w_eban          TYPE eban,

        i_eban          TYPE TABLE OF eban,

        w_bapireturn    TYPE bapireturn.

  DATA: lv_new_objkey     TYPE drad-objky,

        lv_old_objkey     TYPE drad-objky.

  CONSTANTS : c_eban      TYPE dokob  VALUE ‘EBAN’,

              c_ekpo      TYPE dokob  VALUE ‘EKPO’,

              c_x         TYPE c      VALUE ‘X’,

              c_i         TYPE c      VALUE ‘I’,

              c_e         TYPE c      VALUE ‘E’.

*=============================================================================*

* Get the PR details based on the input passed.

  SELECT * FROM eban INTO TABLE i_eban

    WHERE banfn = i_banfn.

  IF sy-subrc NE 0.

    RAISE no_purchaing_data.

  ENDIF.

  LOOP AT i_eban INTO w_eban.

*   Generate refference object (PR) key

    CONCATENATE w_eban-banfn w_eban-bnfpo INTO lv_old_objkey.

*   Generate new object (PO) key

    IF w_eban-ebeln  IS NOT INITIAL.

      CONCATENATE w_eban-ebeln w_eban-ebelp INTO lv_new_objkey.

    ENDIF.

    CHECK lv_new_objkey IS NOT INITIAL.

*   Get the Document key’s of PR Line Item

    CALL FUNCTION ‘DOKUMENTE_ZU_OBJEKT’

      EXPORTING

        key           = lv_old_objkey

        objekt        = c_eban

      TABLES

        doktab        = i_drad

      EXCEPTIONS

        kein_dokument = 1

        OTHERS        = 2.

    IF sy-subrc NE 0.

      CONCATENATE text-001 lv_old_objkey  INTO   w_bapireturn-message.

      w_bapireturn-type      = c_i.

      APPEND w_bapireturn TO t_return.

      CONTINUE.

    ENDIF.

*  Populate i_dradn itab from i_drad

    LOOP AT i_drad INTO w_drad.

*   Assign PR Item document to PO Item

      MOVE-CORRESPONDING w_drad TO w_dradn.

      w_dradn-dokob = c_ekpo.

      w_dradn-objky = lv_new_objkey.

      APPEND w_dradn  TO i_dradn.

    ENDLOOP.

    CHECK i_dradn[] IS NOT INITIAL.

*   Map the PR document key to PO Line Item

    CALL FUNCTION ‘DOKUMENTZUORDNUNGEN_BUCHEN’

      IN UPDATE TASK

      EXPORTING

        ob      = c_ekpo

        objky   = lv_new_objkey

      TABLES

        savdrad = i_dradn.

*  Commit the changes

    CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’

      EXPORTING

        wait = c_x.

    REFRESH: i_drad, i_dradn.

    CLEAR  : lv_new_objkey, lv_old_objkey, w_drad, w_dradn, w_eban.

  ENDLOOP.

*=============================================================================*

ENDFUNCTION.

To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

    1. SASIKANTH SM Post author

      No Configuration is required for this required. If your system is already configured to add DMS attachment and when it’s getting copied from PR to PO while creating PO manually, then you should be able to copy via code.

      (0) 

Leave a Reply