5 1 1 1 1 1 Rating 100% (3 Votes)

If during creation of purchase requisition you've attached some documents into requisition and you convert requisition to purchase order then the attachments aren't copy to PO. But you can do it either by daily job or by the implementation of user-exit if you know how to link GOS object to PO. I faced a request to copy attachments from PR to PO, but what I did was in fact just linking existing attachment to PO. In that way you do not double the same content on server. Bellow you can find the code of an function module which uses 'BINARY_RELATION_CREATE' and 'BINARY_RELATION_CREATE_COMMIT'.

  • Importing

I_EBELN TYPE EBELN -> Purchase Order number
I_COMMIT TYPE C     -> Do you want to do the commit?

  • Tables

T_EBAN STRUCTURE EBAN  -> Table with PR lines to check GOS relations

  • Exceptions


  • Function code:

function z_copy_att_from_pr_to_po.
*"*"Local Interface:
  datafs_option type obl_s_relt,
        ft_options type obl_t_relt,
        ft_links type obl_t_link,
        fs_link  type obl_s_link.

  dataft_polinks type obl_t_link.

  datafs_lpor    type    sibflporb.
  dataft_eban type standard table of eban.
  datafs_eban like line of ft_eban.

  datal_length    type i,
        l_fol_id    type soodk,
        l_fol_mk    type sofmk,
        l_obj_id    type soodk,
        l_obj_data  type sood1,
        l_rolea     type borident,
        l_roleb     type borident,
        l_ep_note   type borident-objkey,
        l_itobjh    type standard table of soli.

        dataf_object type srgbtbrel-instid_a.

  check t_eban[] is not initial.
  ft_eban[] t_eban[].

    move i_ebeln to f_object.

  "get attachments for PO
  select instid_b from srgbtbrel
into corresponding fields of table ft_polinks
where reltype eq 'ATTA'
      and instid_a eq f_object
and typeid_a eq  'BUS2012'
      and catid_a  eq 'BO'
      and typeid_b eq 'MESSAGE'.

  sort ft_polinks by instid_b.

  sort ft_eban by banfn.
  delete adjacent duplicates from ft_eban comparing banfn.

  " get attachments links for all pr

  loop at ft_eban into fs_eban where banfn is not initial.
    fs_lpor-instid fs_eban-banfn.
    fs_lpor-typeid 'BUS2105'.
    fs_lpor-catid  'BO'.

    fs_option-sign 'I'.
    fs_option-option 'EQ'.
    fs_option-low 'ATTA'.
    append fs_option to ft_options.

        call method cl_binary_relation=>read_links_of_binrels
          is_object           fs_lpor
*    ip_no_buffer        =
          et_links            ft_links.
        loop at ft_links into fs_link.
          case fs_link-typeid_b .
            when 'MESSAGE'.
              read table ft_polinks with key instid_b fs_link-instid_b
binary search
                                             transporting no fields.
              if sy-subrc eq 0.
                delete table ft_links from fs_link.
            when others.
              delete table ft_links from fs_link.

      catch cx_obl_parameter_error .
      catch cx_obl_internal_error .
      catch cx_obl_model_error .
      catch cx_root.


  sort ft_links by instid_b ascending.
  delete adjacent duplicates from ft_links comparing instid_b.

  "link attachments from PR to PO.
  loop at ft_links into fs_link.
    " Prepare attachment-attributes
    move           'BUS2012'        to        l_rolea-objtype.
    move           i_ebeln          to        l_rolea-objkey.
    " Build Key for GOS-Relation

    move           fs_link-instid_b  to        l_roleb-objkey.
    move           'MESSAGE'          to        l_roleb-objtype.

    " Create GOS-Relation
    if   i_commit eq 'X'.
        obj_rolea            l_rolea
*          IMPORTING
*            BINREL               = BINREL
*          TABLES
*            BINREL_ATTRIB        = BINREL_ATTRIB
        no_model             1
        internal_error       2
        unknown              3.
      call function 'BINARY_RELATION_CREATE'
        obj_rolea            l_rolea
*          IMPORTING
*            BINREL               = BINREL
*          TABLES
*            BINREL_ATTRIB        = BINREL_ATTRIB
        no_model             1
        internal_error       2
        unknown              3.

    if   sy-subrc ne 0.
      raise          binary_relation_create_error.

ABAP Favorites Eclipse plugin

Drag to your running Eclipse* workspace. *Requires Eclipse Marketplace Client