in this blog post I'm going to show you how you are able to make a picture via a mobile application and store it as an attachment in SAP (SAPoffice). The blog post contains out of the following steps:
Finding the storage place
Encode and decode
Creating the attachment
Creating the linking
So let's start:
1. General information
SAPoffice is a mailing and also a filing system with which you are able to store and administrate files but also able to send files inside the SAP system or over the internet. I'll show you how you can make it to store a picture which was made with you mobile camera and save it as an attachment in the SAPoffice. The picture which is made via the phone's own camera is going to be sent as a base64 encoded String to the SAP system. Some of you may ask themselves, why I receive the image encoded as a base64 String. In the background there is a ICF-Service which handles HTTP-Requests. This request is also responsible for receiving the picture. The image itself is encoded at the mobile application and sent via POST-Request to the SAP system. This is the main reason why I have to deal with a String.
2. Finding the storage place
It's quite important for the SAP system where it hase to save the image. Therefore a function module called "SO_FOLDER_ROOT_ID_GET' is existing:
CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'
region = 'B'
folder_id = lf_folder.
This FM returns the unique ID of the folder associated to the region which you set as an importing parameter.
3. Encode and decode
As already mentioned, the image is transfered to the SAP system as a base64 encoded String. For the further process this String is going to be converted into a XString. What is the difference? Both, String and XString are datatypes for objects with variable length. The only difference is that a String is for a sequence of text and the XString for a sequence of byte. The main conversion is done by a FM too. This one is called "SSCF_BASE64_DECODE":
As a return value you get a table which contains the whole content of the picture encoded and the length of the encoded value itself.
4. Creating the attachment
The first step is to create an object of type "SODOCCHGI1". With this object you are able to provide general information like the description, language, size, datatype of the attachment and whether the file should be changeable or not for example. For creating the file you have to call the FM "SO_DOCUMENT_INSERT_API1":
As importing parameters the FM takes the determined ID of the folder where the attachment should be stored, the object of type "SODOCCHGI1", the datatype of the object and the binary encoded table which stores the image itself. The return value is an object of type "SOFOLENTI1". This object contains the information of the unique created SAPoffice object. The last step is now to create the linking between the SAPoffice object and the SAP object itself.
5. Creating the linking
For making the correct linking between the two objects. For each of them you have to provide the following information:
This is nothing else then the unique number of the object.
This is the so called business object. Each object which can be created or can be stored through an application in SAP is a business object. A Notification for example has the ID 2038 --> "BUS2038".
Nothing else than a short ID which stands for the category. In our case we're dealing with business objects --> "BO".
Finally we can now start with creating the link. The class "cl_binary_relation" provides a method called "create_link". This method takes the two created objects and builds as a relation type "ATTACHMENT" the linking. The complete linking procedure looks like following: