Adding file attachments to MIRO transaction in SAP

I need to build a report that can attach documents (images and files in .TIF format) to the MIRO transaction. My current implementation updates the database tables correctly, but the attachments don’t show up in the MIRO interface itself.

I’m working with business objects and business keys for the attachment process. Could someone review my approach and point out what might be wrong?

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

DATA:
  content_table   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,
  content_wa      TYPE soli,
  folder_key      TYPE soodk,
  object_data     TYPE sood1,
  note_key        TYPE borident-objkey,
  vendor_num      TYPE lifnr,
  filepath        TYPE string,
  doc_name        TYPE c LENGTH 100,
  file_ext        TYPE c LENGTH 4.

CLEAR: content_table[], header_table[].

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

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

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.

check if ur using the right function modules after SO_FOLDER_ROOT_ID_GET. you probably need SO_DOCUMENT_INSERT_API1 instead of SO_OBJECT_INSERT, and make sure the object_type is correct for MIRO - sometimes ‘RBKP’ works better than ‘BUS2081’. ur binary conversion looks wrong too - u should convert to soli format, not from it. ur also missing the actual attachment step.

I’ve hit this same issue with MIRO attachments. It’s usually not the file upload that’s broken - it’s the business object key setup. You need to use business object type ‘BUS2081’ and make sure your object key exactly matches the invoice document number format. Your code is missing the link between the uploaded document and the MIRO business object. After you create the document in the folder, you’ve got to establish the relationship using BINARY_RELATION_CREATE or similar attachment services. Also check your timing - if you’re trying to attach before the MIRO document finishes saving, the attachment won’t stick. I’d check the attachment services in transaction OAOR to see if your documents are getting stored but just aren’t linking to the business object properly.

Your business object config and attachment sequence are messed up. I see you’re uploading the file and getting the folder structure, but you’re skipping the actual document creation and MIRO linking. After SO_CONVERT_CONTENTS_BIN, you need SO_OBJECT_INSERT to create the document in SAP’s system, then SO_OBJECT_SEND to connect it to your business object. Use object type ‘BKPF’ with the accounting document number as the key - don’t use the MIRO transaction itself. Also check that your vendor number and document reference exactly match what’s in the MIRO transaction tables.