File upload functionality in MIRO transaction not working properly

I’m working on a functionality to upload attachments through MIRO transaction code. The files I need to attach are TIF format images and documents. My current implementation updates the database table 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. Here’s my current approach:

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

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,
  object_ref    TYPE borident,
  object_key    TYPE soodk,
  content_data  TYPE soli,
  folder_key    TYPE soodk,
  object_data   TYPE sood1,
  note_key      TYPE borident-objkey,
  vendor_num    TYPE lifnr,
  file_string   TYPE string,
  file_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 = upload_table.

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.

What am I missing in this implementation? Any suggestions would be helpful.

Your code’s missing the key step - you’re not actually linking the document to the MIRO transaction. Just updating the database won’t make attachments show up in the interface. You need to connect your uploaded document to the specific invoice document in MIRO. After uploading with SO functions, use the GOS framework to create the attachment relationship. Call function module ‘BINARY_RELATION_CREATE_COMMIT’ to link your document object to the invoice object. Invoice documents usually use business object type ‘BUS2081’ and the object key should be the invoice document number. Don’t forget ‘COMMIT WORK’ after creating the relationship - without it, the attachment won’t stick. I’ve hit this same issue where everything looked fine in debugging but attachments vanished after the transaction ended because of missing commits.

Your function module sequence is wrong. You’re calling SO_CONVERT_CONTENTS_BIN incorrectly - it needs proper binary data from GUI_UPLOAD. Plus, you’re missing the document creation step completely. After getting the folder root ID, you need SO_DOCUMENT_INSERT_API1 to actually create the document object. Then SO_DOCUMENT_SEND_API1 to finalize it. Right now, your code just uploads the file but never creates the document record MIRO can reference. I had the same problem until I figured out SO_FOLDER_ROOT_ID_GET doesn’t create anything - it just gives you folder structure. Also, make sure your vendor number matches the invoice you’re attaching to, or the business object link fails silently.

Your binary file handling is wrong. You’re using GUI_UPLOAD with filetype ‘BIN’ but then passing the data to SO_CONVERT_CONTENTS_BIN incorrectly. For TIF files, use GUI_UPLOAD with filetype ‘ASC’ and encoding ‘UTF-8’ to get proper binary conversion. Then use SO_DOCUMENT_INSERT_API1 with document type ‘RAW’ for images. Your code skips the actual document creation - SO_FOLDER_ROOT_ID_GET just gives you folder structure. Once you create the document properly, use ‘ATTACHMENTS_CREATE’ to establish the GOS relationship with the invoice. Business object should be ‘BUS2081’ and the object key format needs client + invoice document number padded to 18 characters. Right now you’re just uploading bits without creating any SAP document object.

you’re using the wrong business object type. MIRO needs ‘BUS2081’ for invoice documents - check what you’ve got in your bus_obj parameter. Your object_key should be the invoice document number from RBKP table. I ran into the same issue until I figured out the attachment service needs proper document linking through SWO_INVOKE after the upload finishes.