How to store file incoming as XSTRING in SAP

Let’s assume that we are redefining method CREATE_STREAM of our extended Data Provider Class. We are importing structure which contains mime type and content of the file as XSTRING. This structure is IS_MEDIA_RESOURCE with type TY_S_MEDIA_RESOURCE.

Before we start, if you want to know what is XSTRING, you can take a look at my other article.

First option – Storing XSTRING in SAP Office

Proposed solution is to save the file into SAP office using function module SO_DOCUMENT_INSERT_API1 from a function group providing SAP Office API – SOI1.

1. Converting XSTRING to SOLIX
Best way to supply content of the file is in SOLIX structure which is a table of hexadecimal characters. We can use the following approach to solve this issue.

2. Using SO_DOCUMENT_INSERT_API1 to store file in SAP Office
Now, we can save the content of a file in hexadecimal characters to SAP Office using FM API. We need to provide at least these parameters:

  • folder_id – ID of the folder where we want to store data
  • document_data – Filled document data
  • document_type – Extension of the file
  • contents_hex – Content of the file in hexadecimal table
  • object_header – Header with filename

With successful implementation, file can be transferred from a web client through an OData service into SAP office.

Second option – Storing XSTRING in database

There is also an option to store XSTRING in database. It would be inefficient to store whole file in database, thus only pointer is stored, content of the file is stored in storage. Performance should not be affected, though it is recommended to store only small files in database. New column with corresponding type RAWSTRING has to be created and then you can insert new file into database.

Peter Marcely

ABAP, Python, JavaScript developer