The following article shows how to extract attachment files of all formats from an SAP system, e.g., .pdf files of purchase orders.

About this Workflow #

This article leads you through all necessary steps to set up the following workflows:

  • Get a list of attached files from the SAP ERP system
  • Download SAP attachment files of any format
SAP System SAP Objects Xtract for Alteryx Component
SAP ERP SRGBTBREL (Relationships in GOS Environment)
SOOD (SAPoffice: Object Definition)
Xtract Table
SAP ERP SO_DOCUMENT_READ_API1 (SAPoffice: View object from folder using RFC) Xtract BAPI

You can download the Alteryx workflow for this application in the Alteryx Community - Read SAP Attachment Files.

Get a List of all SAP Attachments #

Follow the steps below to set up the following workflow:

  • Read the table SRGBTBREL to get all object IDs that are attached to business objects
  • Read the table SOOD to get the corresponding file names and extensions of the object IDs.

Get a List of Object IDs

  1. Drag & drop the Xtract Table component into your Alteryx workflow (1).
    xfa_create_table_extraction_01
  2. Select an SAP connection (2). If no SAP connection is available, create a new connection, see Online Help: Creating an SAP Connection.
  3. Click [Edit] (3) to open the main window of the Xtract Table component.
  4. Look up the SAP table SRGBTBREL.
  5. Select the columns TYPEID_A (source of the attached file) and INSTID_B (Object ID) for output.
    attachment-files-table1
  6. Click [OK] to save the table extraction.
  7. Optional: Add a Formula tool after the Xtract Table component to separate the key objects of INSTID_B into the following columns: “Object”, “OBJTP” (object type), “OBJYR” (object year) and “OBJNO” (object number).
    attachment-files-formula

The processed list of attached files contains the following information:
attachment-files-SRGBTBREL-parsed-output

Get a List of File Names

  1. Drag & drop the Xtract Table component into your Alteryx workflow.
  2. Select an SAP connection. If no SAP connection is available, create a new connection, see Online Help: Creating an SAP Connection.
  3. Look up the SAP table SOOD. The table contains all document IDs attached to business objects.
  4. Select the columns OBJTP, OBJYR and OBJNO for output.
    attachment-files-table2
  5. Click [Edit parameters] and create a runtime parameter OBJNO of type string.
    attachment-files-runtime-parameter
  6. Navigate to the WHERE Clause tab and create the following WHERE clause: SOOD~OBJNO IN [OBJNO].
    attachment-files-where-clause
  7. Click [OK] to save the table extraction.
  8. Define an object number as the input for the runtime parameter of the Xtract Table component, e.g., 000000001276.
    attachment-files-table-input
  9. Add a Join tool to join the results of the two table extraction into a single list.
    attachment-files-workflow1

Note: The workflow provided in the Alteryx community contains further steps to download the first file in the list of attached files in the SAP ERP system.

Download SAP Attachment Files #

Follow the steps below to download SAP attachment files using their Object ID as input:

  1. Drag & drop the Xtract BAPI component into your Alteryx workflow (1).
    xfa_create_bapi_extraction_01
  2. Select an SAP connection (2). If no SAP connection is available, create a new connection, see Online Help: Creating an SAP Connection.
  3. Click [Edit] (3) to open the main window of the Xtract BAPI component.
  4. In the main window of the component click magnifying-glass. The window “Function Module Lookup Lookup” opens.
  5. Look up the function module SO_DOCUMENT_READ_API1.
  6. Click [Edit parameters] and create a runtime parameter ObjectIdentifier of type string.
    attachment-files-runtime-parameter2
  7. In the Import tab, set the DOCUMENT_ID to the runtime parameter ObjectIdentifier.
    attachment-files-bapi-import
  8. In the Export tab, select DOCUMENT_DATA for output.
  9. In the Table tab, select CONTENTS_HEX for the output. CONTENTS_HEX contains the attachment file in the format of a HEX string.
  10. Click [OK] to save your input.
  11. Define an Object ID as the input for the runtime parameter of the Xtract BAPI component, e.g., FOL18 4 EXT45000000000229.
    Tip: Object IDs are available in the SAP table SRGBTBREL, see Get a List of all SAP Attachments. attachment-files-bapi-input
  12. Add a Summarize tool (4) to concatenate the multi-line HEX string returned by the Xtract BAPI component into a single line.
  13. Add a Select (5) and a Formula tool to concatenate the file name using the Xtract BAPI output fields OBJDES and FILE_EXT, e.g., example.pdf.
    attachment-files-formula-filename
  14. Add a Append Fields tool to append the file name to the HEX string.
    attachment-files-append-fields
  15. Add a Blob Convert tool (6) to convert the HEX string to a Binary Large OBject (BLOB). BLOB data types can store multiple file types, e.g., images, audio, and other objects, see Alteryx Documentation: Blob Convert Tool for more information.
    attachment-files-blob-convert
  16. Add a Blob Output tool (7) to save the file.
    attachment-files-blob-convert