data: g_gos_ident type borident.
data: g_banfn type eban-banfn.
data: go_gos_manager type ref to cl_gos_manager.
And we activate GOS with temporary object name if we're in creation mode:
clear g_gos_ident.
if g_creation_mode is initial.
g_gos_ident-objkey = g_banfn.
clear p_no_commit.
else.
"temporary object key which is unique
concatenate 'ZBANF' sy-uname sy-datum sy-uzeit into g_gos_ident-objkey.
endif.
g_gos_ident-objtype = 'BUS2105'. "PR BUS object
create object go_gos_manager
exporting
" io_container = g_cc_att
is_object = g_gos_ident
it_service_selection =
* IO_CALLBACK =
ip_start_direct = ' '
" IP_NO_INSTANCE = f_ip_no_instance
ip_no_commit = 'X' "commit done manually
exceptions
object_invalid = 1
callback_invalid = 2
others = 3.
So now each attachment and business document will be linked to temporary object. Now after successful save of new PR we need to move the link from temporary object to final one.
Let's start with attachments, I will move them using cl_gos_service_tools=>move_linked_objects.
I_TEMP_OBJECT TYPE BORIDENT-OBJKEY -> temporary key for GOS
I_PURCHASE_REQUISITION TYPE EBAN-BANFN -> taget Purchase requistion
Implementation:
method gos_move_att_tpr_to_pr.
data: mt_services type tgos_sels. " Services table typ
data: ms_service type sgos_sels. " Services structure type
data: ms_source type sibflporb. " Source
data: ms_target type sibflporb. " Target
* Source
ms_source-instid = i_temp_object.
ms_source-typeid = 'BUS2105'.
ms_source-catid = 'BO'.
*
* Target
ms_target-instid = i_purchase_requisition.
ms_target-typeid = 'BUS2105'.
ms_target-catid = 'BO'.
cl_gos_service_tools=>move_linked_objects(
is_source = ms_source
is_target = ms_target
it_service_selection = mt_services
).
endmethod.
Now business documents, here I will use cl_alink_connection=>find, cl_alink_connection=>insert and cl_alink_connection=>delete.
Importing:
I_PURCHASE_REQUISITION TYPE EBAN-BANFN -> Purchase Requisition Number
I_TEMP_OBJECT TYPE TOA02-OBJECT_ID -> SAP ArchiveLink: Object ID (object identifier)
Implementation:
method gos_alink_move_link_tpr_to_pr.
data: mt_connections type standard table of toav0.
data: ms_toavo type toav0.
field-symbols: <toavo> type toav0.
check i_purchase_requisition is not initial and i_temp_object is not initial.
cl_alink_connection=>find(
exporting
sap_object = 'BUS2105'
object_id = i_temp_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_requisition.
cl_alink_connection=>insert(
exporting
link = ms_toavo
* barcode = barcode
* receiving
* tab_name =
exceptions
error = 1
others = 2
).
if sy-subrc eq 0.
cl_alink_connection=>delete(
exporting
link = <toavo>
tab_name = 'TOA02'
* importing
* tab_names = tab_names
exceptions
not_found = 1
others = 2
).
if sy-subrc <> 0.
"raise error_moving_attachments.
endif.
else.
"raise error_moving_attachments.
endif.
endloop.
endmethod.
This is all fine when at the end you move links from temporary object to final one, but in case you didn't then in your program you should run a method or function to clear not needed entries. In the method bellow you'll see that I look for particular or all dummy links older than 1 day and then I set deletion date for the file to tomorrow with cl_alink_connection=>update. So next archiving run not needed files will be deleted.
I_TEMP_OBJECT TYPE TOA02-OBJECT_ID OPTIONAL -> SAP ArchiveLink: Object ID (object identifier)
Implementation:
method gos_alink_temp_date_change.
data: mt_toa02 type standard table of toa02.
data: mr_object_id type range of toa02-object_id.
data: ms_object_id like line of mr_object_id.
data: ms_taov0 type toav0.
data: mr_ar_date type range of toa02-ar_date.
data: ms_ar_date like line of mr_ar_date.
data: mr_del_date type range of toa02-del_date.
data: ms_del_date like line of mr_del_date.
field-symbols: <toa02> type toa02.
if i_temp_pr_object is not initial.
ms_object_id-sign = 'I'.
ms_object_id-option = 'EQ'.
ms_object_id-low = i_temp_object.
append ms_object_id to mr_object_id.
else. "change the date to tommorow for all temporary files older than 1 day.
ms_object_id-sign = 'I'.
ms_object_id-option = 'CP'.
ms_object_id-low = 'ZBANF*'.
append ms_object_id to mr_object_id.
ms_ar_date-sign = 'I'.
ms_ar_date-option = 'LT'.
ms_ar_date-low = sy-datum - 1.
append ms_ar_date to mr_ar_date.
ms_del_date-sign = 'I'.
ms_del_date-option = 'GT'.
ms_del_date-low = sy-datum + 1.
append ms_del_date to mr_del_date.
endif.
select * into corresponding fields of table mt_toa02
from toa02
where sap_object eq 'BUS2105'
and object_id in mr_object_id
and ar_date in mr_ar_date
and del_date in mr_del_date.
loop at mt_toa02 assigning <toa02>.
clear ms_taov0.
move-corresponding <toa02> to ms_taov0.
ms_taov0-del_date = sy-datum + 1.
cl_alink_connection=>update(
exporting
link = ms_taov0
exceptions
error = 1
others = 2
).
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endloop.
endmethod.
Job done :)