Adding file attachments to MIRO transaction

I’m working on building a report or function module that needs to attach files (specifically TIF images and documents) to the MIRO transaction in SAP.

My current implementation updates the database tables correctly, but the attachments don’t show up in the MIRO interface. I think there might be an issue with how I’m handling the business object and business key parameters.

SELECTION-SCREEN BEGIN OF BLOCK block1 WITH FRAME TITLE text-100.
PARAMETERS: file_path   TYPE localfile,
            object_id   TYPE swo_typeid,
            bus_object  TYPE swo_objtyp.
SELECTION-SCREEN END OF BLOCK block1.

DATA:
  file_content_tab TYPE STANDARD TABLE OF soli,
  content_line     TYPE soli,
  header_table     TYPE STANDARD TABLE OF soli,
  folder_member    TYPE sofmk,
  note_ref         TYPE borident,
  business_obj     TYPE borident,
  object_key       TYPE soodk,
  line_content     TYPE soli,
  folder_key       TYPE soodk,
  object_details   TYPE sood1,
  note_key         TYPE borident-objkey,
  vendor_number    TYPE lifnr,
  file_string      TYPE string,
  file_name        TYPE c LENGTH 100,
  file_ext         TYPE c LENGTH 4.

CLEAR: file_content_tab[], header_table[].

CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    filename = 'C:\Temp\sample.TIF'
    filetype = 'BIN'
  TABLES
    data_tab = upload_table.

CALL FUNCTION 'SO_CONVERT_CONTENTS_BIN'
  EXPORTING
    it_contents_bin = file_content_tab[]
  IMPORTING
    et_contents_bin = file_content_tab[].

CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'
  EXPORTING
    region = 'B'
  IMPORTING
    folder_id = folder_key
  EXCEPTIONS
    communication_failure = 1
    owner_not_exist = 2
    system_failure = 3
    x_error = 4
    OTHERS = 5.

Can someone help me identify what I’m missing in this approach? The attachment process seems to work at the database level but doesn’t integrate properly with the MIRO transaction screen.

I ran into this exact problem about six months ago when implementing a similar solution. The key issue in your code is that you’re missing the crucial step of creating the actual document object before attempting the attachment linkage. After your SO_CONVERT_CONTENTS_BIN call, you need to use SO_OBJECT_INSERT to create the document in the SAP Office repository first. Your current approach jumps straight to folder operations without establishing the document entity. Additionally, make sure you’re calling COMMIT WORK after each major step in the attachment process, not just at the end. The MIRO interface reads attachment data differently than direct table queries, so database updates alone won’t suffice. I found that explicitly calling SO_ATTACHMENT_INSERT with the correct business object parameters after document creation resolved the visibility issue. Double-check that your object_id parameter matches the actual MIRO document structure too.

check if your using the right business object type for miro - should be BUS2081 for invoice documents. also make sure your calling SO_DOCUMENT_INSERT_API1 with proper parameters before linking. i had similar issue and it was becuase the attachment ID wasnt being generated correctly in the first step.

Looking at your code, I suspect the main issue is that you’re not properly linking the attachment to the specific invoice document in MIRO. The attachment framework needs to know which business object instance to associate the file with.

From my experience with similar integration work, you need to establish the correct business object reference first. For MIRO transactions, this typically involves the document number and fiscal year. After creating the attachment using SO_OBJECT_INSERT or similar functions, you must create the link using SO_ATTACHMENT_INSERT_API1 with the proper business object key.

Another common pitfall is the timing of when you create the attachment. If you’re trying to attach during document creation before the document is saved, the business object instance might not exist yet. Consider implementing this as a post-processing step after the MIRO document is committed to the database.

Also verify that your folder_id from SO_FOLDER_ROOT_ID_GET is correct and that you have the necessary authorization objects for attachment processing in your user profile.

The issue likely stems from your handling of the business object and the sequence of attachment creation. It’s essential to link the document properly after uploading the file. First, use SO_OBJECT_INSERT to create the document attachment, and then utilize BINARY_RELATION_CREATE_COMMIT to establish the necessary relationship. Ensure that the MIRO business object corresponds to ‘BUS2081’ and that your object key includes the company code, document number, and fiscal year in the correct format. I’ve faced this issue previously; if the objtype and objkey parameters aren’t set correctly, the attachment will not show up in MIRO. Don’t forget to execute COMMIT WORK after creating the relationship to ensure the attachment links are preserved. Lastly, confirm that your user profile includes the necessary authorizations for attachment processing (refer to S_BDS_DS).