Recently a requirement was brought up by my client where they wanted to attach supporting documents to cross company journal entries and wanted the documents to be attached to all the accounting documents posted as part of the given cross company entry. In standard SAP, the attachments needed to be attached to each accounting document separately. Typically I would have advised them to not to duplicate the attachments and ask the users to be provided with appropriate security access so view the supporting documents from the leading company code on the inter-company posting but this was not an option since it was a very unique situation where the company codes involved belonged to different shareholder ownership and had very strict security controls. Manual attachment of documents were not preferred due to the number of entities involved in a average posting.
As a first step, I was looking around in SAP service market place to see whether do we have any standard solutions to cater to this requirement and ended up with no luck. Ultimately I have given the following solution. I'm updating my blog with the solution so anyone come across the same requirement can implement it.
This solution can be copied and pasted in any system without any modification.
Step 1- Implicit enhancement point.
As a first step, we need to create an Implicit enhancement point in function module SGOS_OBJECT_ADD_TO_HISTORY
Step 2 - Copy the following code and paste it in the enhancement created above.
if not SYST-TITLE = 'Service: Attachment list'.
if SYST-TCODE = 'FB02' or SYST-TCODE = 'FB03'.Tables: BKPF,
BVOR,
SRGBTBREL.
DATA: ls_source TYPE sibflporb, " Source
ls_target TYPE sibflporb. " Target
DATA: lt_services TYPE tgos_sels. " Services table typ
DATA: ls_service TYPE sgos_sels. " Services structure type
DATA: ZBELNR type BKPF-BELNR,
ZBUKRS type BKPF-BUKRS,
ZBUKRS2 type BKPF-BUKRS,
ZGJAHR type BKPF-GJAHR.
DATA: IT_BKPF type BKPF.
DATA: ZINSTID TYPE SRGBTBREL-INSTID_A.
DATA: BEGIN OF it_bvor OCCURS 0,
BELNR type bvor-BELNR,
BUKRS type bvor-BUKRS,
GJAHR type bvor-GJAHR,
END OF it_bvor.
FIELD-SYMBOLS: <BVOR> LIKE it_bvor.
ls_service-sign = 'I'.
ls_service-option = 'EQ'.
ls_service-low = 'PCATTA_CREA'.
APPEND ls_service TO lt_services.
ZBUKRS = bc_object-instid+0(4).
ZBELNR = bc_object-instid+4(10).
ZGJAHR = bc_object-instid+14(4).
ls_source-instid = bc_object-instid.
ls_source-typeid = 'BKPF'.
ls_source-catid = 'BO'.
select single * from BKPF into IT_BKPF where BELNR = ZBELNR and BUKRS = ZBUKRS and GJAHR = ZGJAHR and BVORG <> ''.
if sy-subrc = 0.
ZBUKRS2 = IT_BKPF-BVORG+10(4).
if ZBUKRS2 = ZBUKRS.
select * from BVOR APPENDING CORRESPONDING FIELDS OF TABLE it_bvor where BVORG = IT_BKPF-BVORG.
Loop at it_bvor assigning <bvor>.
if <bvor>-BELNR <> ZBELNR.
CONCATENATE <BVOR>-BUKRS <BVOR>-BELNR <BVOR>-GJAHR into ZINSTID.
ls_target-instid = ZINSTID.
ls_target-typeid = 'BKPF'.
ls_target-catid = 'BO'.
cl_gos_service_tools=>copy_linked_objects(
is_source = ls_source
is_target = ls_target
it_service_selection = lt_services
).
commit work.
endif.
endloop.
endif.
endif.
endif.
endif.
Now, this is how the solution works.
Step 1 - Attach a document to the leading or header company code of the posting.
This attachment will automatically be attached to all the other company codes in the given cross company journal entry.
Any supporting documents attached to non leading company codes will not be copied to other entities. Users also have to delete the attachment from the leading entity that initiated the cross company journal entry before deleting from the non leading entities since the business requirement was to make sure that the supporting documents attached by the initiating entity cannot be tampered by other entities.
Please feel free to copy and modify my code to suit your needs if it helps.
No comments:
Post a Comment