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_m
m ) and then call GET_GOS_MANAGER
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.
I_PURCHASE_REQUISITION Type EBAN-BANFN
I_PURCHASE_ORDER Type EKKO-EBELN
data: mt_connections type standard table of toav0.
data: ms_toavo type toav0.
data: m_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.
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
* count = count
* reducedbylimit = reducedbylimit
* reducedbyauthority = reducedbyauthority
connections = mt_connections
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.
loop at mt_connections assigning <toavo>.
move-corresponding <toavo> to ms_toavo.
ms_toavo-object_id = i_purchase_order.
ms_toavo-sap_object = 'BUS2012'.
link = ms_toavo
* barcode = barcode
* tab_name =
error = 1
others = 2
if sy-subrc eq 0.