Adding file attachments to MIRO transaction in SAP

I need help with uploading documents (TIF images and files) 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 or business key parameters.

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

DATA:
  binary_data    TYPE STANDARD TABLE OF soli,
  line_content   TYPE soli,
  header_info    TYPE STANDARD TABLE OF soli,
  folder_member  TYPE sofmk,
  note_ref       TYPE borident,
  object_ref     TYPE borident,
  object_key     TYPE soodk,
  content_line   TYPE soli,
  folder_key     TYPE soodk,
  object_data    TYPE sood1,
  note_key       TYPE borident-objkey,
  vendor_num     TYPE lifnr,
  upload_file    TYPE string,
  file_name      TYPE c LENGTH 100,
  file_ext       TYPE c LENGTH 4.

CLEAR: binary_data[], header_info[].

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 = binary_data[]
  IMPORTING
    et_contents_bin = binary_data[].

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 spot what I’m missing in this approach?

The Problem: You are having trouble uploading TIF images and files as attachments to MIRO transactions in SAP. Your current ABAP code correctly updates database tables, but the attachments don’t appear in the MIRO interface. You suspect an issue with how you’re handling business object or business key parameters.

:thinking: Understanding the “Why” (The Root Cause):

Your ABAP code is likely missing the crucial steps to correctly link the uploaded document to the MIRO transaction. Simply uploading the file to the SAP system isn’t enough; you must explicitly create a document object and then associate that object with the specific MIRO transaction (invoice) using the appropriate SAP function modules. Your current approach likely leaves the uploaded document orphaned within the system, invisible to the MIRO interface. Relying solely on database table updates isn’t sufficient for managing attachments within SAP’s document management framework. The SAP system uses specific function modules to manage this link, and omitting them results in the observed behavior. Furthermore, using a large number of manual function module calls makes your code brittle and less maintainable. It will be increasingly difficult to manage and update as the system changes and you need to support different document types.

:gear: Step-by-Step Guide:

  1. Migrate to an External Workflow Engine (Recommended): The most robust and maintainable solution involves moving the entire document upload and attachment process outside of your core SAP ABAP code. Use an external workflow engine (like the one mentioned in the original post) to handle file upload, conversion (if necessary), and integration with SAP’s APIs. This approach offers several advantages:

    • Improved Maintainability: Changes in SAP’s underlying structure or function modules won’t directly impact your process.
    • Enhanced Scalability: You can easily adapt to handle increasing volumes of documents and various file types.
    • Simplified Error Handling: External workflow engines often provide built-in error handling, retry logic, and logging, simplifying debugging and monitoring.
    • Flexibility: You can more easily add additional steps such as validation or transformation as needed.
  2. Using SAP Function Modules (If External Workflow is Not Feasible): If you cannot use an external workflow engine, you must explicitly add the missing function module calls to your ABAP code. This requires incorporating the following function modules:

    • SO_OBJECT_INSERT: Creates the document object in the SAP system.
    • SO_DOCUMENT_INSERT_API1: Finalizes the insertion of the document into the SAP system.
    • SO_NEW_DOCUMENT_ATT_INSERT_API1: Establishes the link between the newly created document object and the MIRO transaction. This function requires the business object type (BUS2081 for invoices) and the correct object_key (invoice document number from the RBKP table).

    Your updated code might look something like this (replace placeholders with your actual values):

    " ... your existing code ...
    
    CALL FUNCTION 'SO_OBJECT_INSERT'
      EXPORTING
        object_id = <your_object_id>
        ... other parameters ...
      IMPORTING
        object_key = note_key.
    
    CALL FUNCTION 'SO_DOCUMENT_INSERT_API1'
      EXPORTING
        object_key = note_key
        ... other parameters ...
    
    CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_INSERT_API1'
      EXPORTING
        bus_obj = 'BUS2081' " Invoice business object type
        object_key = note_key
        object_ref = object_ref  " Reference to the MIRO invoice
        ... other parameters ...
    
    " ... rest of your code ...
    

:mag: Common Pitfalls & What to Check Next:

  • Incorrect Business Object Type: Ensure you’re using BUS2081 as the business object type for invoices. Using an incorrect type will prevent the attachment from linking correctly.
  • Object Key Mismatch: Double-check that your object_key accurately reflects the invoice document number from the RBKP table. A mismatch will lead to the attachment not appearing in MIRO.
  • Insufficient Authorizations: Verify that your user has the necessary authorizations to create and attach documents within MIRO.
  • Document Class: Check if you are properly setting the document class in your object_data structure. An incorrect document class may cause MIRO to not be able to display the document.
  • MIME Type: Ensure that the MIME type of your TIF files is correctly identified and handled during the upload process.

:speech_balloon: Still running into issues? Share your (sanitized) config files, the exact command you ran, and any other relevant details. The community is here to help!

Your code’s missing key steps to link the attachment to MIRO. The main problem? You’re not connecting your uploaded document to the actual invoice in MIRO. After uploading the binary data, you need to create the document object with SO_OBJECT_INSERT, then link it to the business object using SO_NEW_DOCUMENT_ATT_INSERT_API1. Use ‘BUS2081’ for invoice documents, and make sure your object key matches the invoice document number from the RBKP table. You’re also missing SO_DOCUMENT_INSERT_API1 to finalize the attachment. Without these function modules, your attachment sits in the system but won’t show up in MIRO - there’s no relationship established between the document and invoice.

The issue might be simpler - are you setting the correct document class in your object_data structure? I’ve seen this before where everything uploads but MIRO can’t display it because the document class isn’t set to ‘INV’ or the mime type is wrong for TIF files. Also check if your business object reference points to the right RBKP entry.

You’re getting the root folder but not actually creating a document in the GOS attachment list. After SO_CONVERT_CONTENTS_BIN, you need SO_OBJECT_INSERT to create the document object, then SO_DOCUMENT_INSERT_API1 to store it. Here’s what you’re missing: link it to MIRO using SO_NEW_DOCUMENT_ATT_INSERT_API1 with business object type ‘BUS2081’ for invoice documents. Your object_key needs the invoice document number from RBKP-BELNR - not some random key. Also make sure your folder_member structure has the right document type and object properties before you insert.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.