Adding file attachments to MIRO transaction in SAP

I need help with uploading attachments through the MIRO transaction code. I’m trying to attach two TIF format files (one image and one document) but having issues. My code updates the database table correctly, but the attachments don’t show up in the MIRO interface. I think there might be an error in how I’m handling the business object or business key parameters. Here’s my current approach:

SELECTION-SCREEN BEGIN OF BLOCK b15 WITH FRAME TITLE text-002.
PARAMETERS: p_filepath TYPE localfile,
            p_objectid TYPE swo_typeid,
            p_busobj   TYPE swo_objtyp.
SELECTION-SCREEN END OF BLOCK b15.

DATA:
  lt_binary_data TYPE STANDARD TABLE OF soli,
  ls_binary_rec  TYPE soli,
  lt_header_info TYPE STANDARD TABLE OF soli,
  lv_folder_mem  TYPE sofmk,
  lv_note_ref    TYPE borident,
  lv_object_ref  TYPE borident,
  lv_object_key  TYPE soodk,
  lv_binary_line TYPE soli,
  lv_folder_key  TYPE soodk,
  lv_object_info TYPE sood1,
  lv_note_key    TYPE borident-objkey,
  lv_vendor_num  TYPE lifnr,
  lv_filepath    TYPE string,
  lv_file_name   TYPE c LENGTH 100,
  lv_file_ext    TYPE c LENGTH 4.

CLEAR: lt_binary_data[], lt_header_info[].

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

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

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

Can someone point out what I might be missing in this attachment process?

you’re missing the commit statement after creating the attachment. without COMMIT WORK, your changes won’t stick in the database. also, check your business object type - for MIRO transactions it should be ‘BUS2081’. make sure your object key format matches exactly what MIRO expects.

Your code’s missing a key piece - you’re not actually creating the document object or linking it to MIRO. After you convert the binary data, you need SO_OBJECT_INSERT to create the document in SAP Office, then SO_OBJECT_SEND to make the connection. You’re prepping the binary data but stopping short of finishing the attachment workflow. Don’t forget BINARY_RELATION_CREATE_COMMIT to properly link everything to your business object. Set your business object type to ‘BUS2081’ for invoices and make sure the object key matches your MIRO document number. Right now your attachment just sits in memory without getting tied to the transaction.

Your code has a few key problems with the business object setup and linking. You’re handling the binary data correctly, but you’re missing the SO_OBJECT_INSERT function call that actually creates the document in the system. After that, you need SO_NEW_DOCUMENT_ATT_INSERT_API1 to attach it to MIRO properly. Also, don’t make p_busobj a parameter for MIRO transactions - just hardcode it to ‘BKPF’ (accounting document). Your object key should be company code + document number + fiscal year from the invoice, all concatenated together. The folder handling isn’t complete either. Once you get the root folder ID, you need to create a proper document header with SO_DOCUMENT_INSERT_API1. Skip these steps and your attachment just sits there orphaned in the system.

Been there, done that. Your biggest issue is manually handling all these SAP function modules when there’s a cleaner way.

Skip wrestling with SO_OBJECT_INSERT, SO_CONVERT_CONTENTS_BIN, and that legacy SAP Office stuff. Just automate the whole workflow. Set up integration that monitors your file directory, processes TIF files automatically, and pushes them into MIRO through proper APIs.

I’ve built similar automations for invoice processing - files upload to a shared folder, then automatically attach to the right MIRO transactions based on filename patterns or metadata. Way more reliable than debugging function module chains.

You can handle business object mapping (BUS2081 for invoices), document numbering, and commit logic in one smooth workflow. Plus you get error handling and retry logic built in.

Skip the ABAP headaches and automate it properly: https://latenode.com