Adding file attachments to MIRO transaction

I need help with uploading attachments to the MIRO transaction in SAP. I’m working on a function module that should attach both image files and documents (TIF format) to vendor invoices.

The issue is that my code updates the database tables correctly, but the attachments don’t show up in the MIRO transaction interface. I think there might be something wrong with how I’m handling the business object and business key parameters.

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

DATA:
  lt_binary_data TYPE STANDARD TABLE OF soli,
  ls_binary_line TYPE soli,
  lt_header_info TYPE STANDARD TABLE OF soli,
  lv_folder_key  TYPE sofmk,
  lv_document_id TYPE borident,
  lv_business_id TYPE borident,
  lv_doc_key     TYPE soodk,
  lv_folder_key2 TYPE soodk,
  lv_doc_info    TYPE sood1,
  lv_note_key    TYPE borident-objkey,
  lv_vendor      TYPE lifnr,
  lv_filepath    TYPE string,
  lv_fname       TYPE c LENGTH 100,
  lv_ext         TYPE c LENGTH 4.

CLEAR: lt_binary_data[], lt_header_info[].

CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    filename = 'C:\Temp\invoice_scan.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_key2
  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 my approach?

Had this exact frustration six months ago when I set up invoice automation for our finance team. Your attachment logic looks solid, but MIRO’s super picky about GOS config details that everyone misses.

What fixed it: make sure your business object key has the right client and company code prefix. Format it exactly as CLIENT+COMPANYCODE+DOCUMENTNUMBER+FISCALYEAR. Also check that your attachment category’s set right in the document info record - MIRO filters them out even when they’re sitting in the backend tables.

Another gotcha: attachment type classification. Use document type ‘EXT’ for external docs like TIFs, and verify the MIME type’s registered in your system. Run SPAD to check if your system recognizes TIF format for business documents. Without proper MIME registration, attachments exist but stay invisible in the transaction.

I’ve hit this exact problem before and it drove me crazy for weeks. The issue is usually timing - when you call the attachment functions versus when you commit the invoice. MIRO expects the accounting document to exist in BKPF before you can attach files. If you’re trying to attach during invoice creation, the business object reference might not be available yet. Try this: let MIRO complete the invoice posting first, then trigger your attachment routine separately using the generated document number. Use ‘BKPF’ as your business object type with format ‘BUKRS+BELNR+GJAHR’. Also use ‘SO_DOCUMENT_INSERT_API1’ instead of the older SO functions - the API1 version handles GOS linkage much better. And verify that attachment services are configured properly in SPAD for your document types.

I’ve been down this rabbit hole countless times. Everyone’s giving you the right technical fixes, but you’re fighting SAP’s attachment system - and it’s brutal.

Your code isn’t the real problem. SAP’s document attachment workflow breaks constantly. Tables get updated but the UI doesn’t show anything because of timing issues, auth problems, or missing GOS config.

Don’t spend weeks debugging ABAP attachment functions. Flip the whole process around. Set up automation that handles attachments outside MIRO, then pushes everything in cleanly.

I built something like this for our AP team using Latenode. It monitors email attachments and file drops, processes invoices, and uses SAP’s RFC interface to attach files directly to business objects. No more SO_DOCUMENT_INSERT headaches or BDS linking nightmares.

The automation handles the messy stuff - file validation, business object keys, commit timing, and error handling when attachments fail. Users just drop files in a folder and everything shows up in MIRO automatically.

Takes about an hour to set up versus weeks debugging SAP’s attachment APIs. Plus you get better error logging and can easily tweak the workflow when requirements change.

This is a super common issue with SAP’s Generic Object Services attachments. Your code creates the document fine, but it’s not linking it properly to the business object that MIRO needs.

After you create the attachment with SO_* functions, you’ve got to use BDS_BUSINESSDOCUMENT_CREATE_TAB to actually link it to the vendor invoice. Set the business object to ‘BKPF’ (accounting document) and make sure you’re using the right document key format.

Don’t forget to call COMMIT WORK after all your attachment stuff. Without it, the relationships won’t stick even if the table updates work.

Also check authorization objects. Users need specific auth to see attachments in MIRO, so verify your attachment visibility settings in the document info structure. The attachment might be there but just hidden because of auth restrictions.

Been there, done that. SAP attachment workflows are a nightmare to debug, especially when tables update but the UI doesn’t reflect changes.

Your code’s missing the crucial step of linking the document to the business object properly. The SO_* functions create the attachment in the generic document management system, but MIRO needs specific object linkage.

Here’s what usually goes wrong:

  • Business object type should be ‘BUS2081’ for vendor invoices
  • The object key needs to match exactly what MIRO expects
  • You need to call ‘BINARY_RELATION_CREATE_COMMIT’ after creating the attachment
  • Missing the proper folder assignment for invoice documents

Honestly though, instead of wrestling with SAP’s ancient attachment APIs, I’d automate this whole thing with Latenode. You can set up a workflow that monitors your invoice folder, processes the files, and pushes them into SAP through RFC calls or web services.

I did something similar for our procurement team. Latenode watches a shared drive, grabs new invoice scans, extracts key data using OCR, and attaches everything to the right MIRO transaction automatically. No more manual uploads, no more missing attachments.

The workflow handles file format conversion, validates business keys, and even sends notifications when attachments fail. Takes about 30 minutes to set up versus weeks of ABAP debugging.

check your commit timing. i had the same issue - i was calling commit work too early. the attachment gets created but miro can’t find the link to the invoice doc. move your commit after both invoice posting AND attachment creation finish. also make sure your object_id parameter matches the actual invoice document number format.