4.5 1 1 1 1 1 Rating 90% (2 Votes)
In article Link Attachments of Purchase Requisition to Purchase Order I've shown how to link standard attachments from purchase requisition to purchase orders, but to have full set of options we also need a a method to link business documents of PR to PO. This is not so hard as we have in disposition class cl_alink_connection which allows to do such operations. Of course the time when you're copying the link depends on you, you can do it during posting of PO (as I do, to be sure that I will copy only this documents and attachments which are linked to PR's used in the PO ), you can do it after the PO is save with your some background job or you can try to insert the object directly to the GOS of purchase order.  I didn't do direct attachment to GOS of PO but as I mention in the comments of Attachments article you can connect to GOS from class CL_PO_HEADER_HANDLE_MM which contains method GET_GOS_MANAGER. You can do it for example in PROCESS_ITEM method of ME_PROCESS_PO_CUST . You'll need to get header object firstly (type ref to if_purchase_order_mm ) and then call GET_GOS_MANAGER method.
 
Anyway, I will present you the method which I used in POST method of ME_PROCESS_PO_CUST BADI. As I said, it's quite simple if you know class cl_alink_connection. Firstly we need to check if any business document is attached to PR, I will do it with method cl_alink_connection=>find. Then when we have list of all business documents we can insert link to it to PO with  cl_alink_connection=>insert.
Importing:

I_PURCHASE_REQUISITION Type EBAN-BANFN
I_PURCHASE_ORDER Type EKKO-EBELN

Implementation:

method gos_alink_copy_link_pr_to_po.

  datamt_connections type standard table of toav0.
  datams_toavo type toav0.
  datam_object type toav0-object_id.
  field-symbols<toavo> type toav0.

  check i_purchase_requisition is not initial and i_purchase_order is not initial.

  m_object i_purchase_requisition.

  cl_alink_connection=>find(
  exporting
    sap_object         'BUS2105'
    object_id          m_object
    mandt              
sy-mandt
*    archiv_id          = archiv_id
*    arc_doc_id         = arc_doc_id
*    ar_object          = ar_object
*    from_ar_date       = from_ar_date
*    until_ar_date      = SY-DATUM
*    doc_type           = doc_type
*    del_date           = del_date
*    limited            = limited
    no_auth_check      'X'
*    limit              = limit
*    parameter          = parameter
  importing
*    count              = count
*    reducedbylimit     = reducedbylimit
*    reducedbyauthority = reducedbyauthority
    connections        mt_connections
  
exceptions
    not_found          1
    error_authorithy   2
    error_parameter    3
    others             4
    ).
  if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  endif.

  loop at mt_connections assigning <toavo>.
    clear ms_toavo.
    move-corresponding <toavo> to ms_toavo.
    ms_toavo-object_id i_purchase_order.
    ms_toavo-sap_object 'BUS2012'.

    cl_alink_connection=>insert(
    exporting
      link     ms_toavo
*      barcode  = barcode
*    receiving
*      tab_name =
    exceptions
      error    1
      others   2
      ).
    if sy-subrc eq 0.

    endif.
  endloop.
endmethod.

Enjoy!