Search The SAP Consultant

Tuesday, October 09, 2018

My solution to attach supporting documents to cross company documents

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 should be attached to each accounting document separately. But typically the security of a given user would be restricted by company code.

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 who comes across with the same requirement can implement it.

This solution can be copied and pasted in any system without any modification (Including S4Hana).

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'.


DATAls_source TYPE sibflporb,      " Source
      ls_target TYPE sibflporb.      " Target
DATAlt_services TYPE tgos_sels.    " Services table typ
DATAls_service TYPE sgos_sels.     " Services structure type
      ZBUKRS2 type BKPF-BUKRS,
      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.

Loop at it_bvor assigning <bvor>.

if <bvor>-BELNR <> ZBELNR.

  ls_target-instid ZINSTID.
  ls_target-typeid 'BKPF'.
  ls_target-catid   'BO'.

      is_source            ls_source
      is_target            ls_target
      it_service_selection lt_services
commit work.


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.