Skip to Content
Technical Articles

How to Upload Data to SAP Cloud Platform, ABAP Environment

Hey gang!  This morning on the ABAP_Freak->show(), we introduced you to the little project we’ve been working on which we call the ABAP File Uploader tool.  This tool allows you to upload data directly to a database table in SAP Cloud Platform, ABAP Environment, aka Steampunk.  How this came about was when I was messing around with the RAP(ABAP RESTful Application Programming Model) a few weeks ago and wanted to seed my tables with some data for my testing and prototype purposes.  Because of limitations and restrictions of the Steampunk environment, my choices were also limited.  In an on-prem scenario, the answer to this question is pretty simple, we use the CL_GUI_FRONTEND_SERVICES class to upload data via a custom program.  But as you may know, this class and many others that are SAP GUI dependent are not allowed in Steampunk.  So what I started out doing was simply having a loader class which had a method containing a few INSERT statements with hardcoded values.  I did not like this approach almost immediately.  So I pinged my buddy, Thomas Jung and asked, “you know of a good way to get data into a table in Steampunk”.  His answer was “yea, INSERT statements in a class/method”.  At which point, I believe I responded with the “puke” emoji.  Then he said, “would be nice to have a generic uploader tool”.  I was like, “Hold my Old Monk & Coke….”.  Couple days later I had something working using an HTTP Service, and then Tom threw a nice UI on it for us.

The UI is pretty simple, you provide the name of the database table(yes, there is value help there!) that you want to load the data into as well as the actual file.  You can choose to append the data to data already existing in the table, or to replace it, meaning that a DELETE will be performed before the data is uploaded.  At this point, we only support json as the format for the import file. I’m looking to add support for csv soon, its not all that much more work, just some nuances with how the request comes in. Also it is important to note that this tool assumes a lot and is not all that robust. We assume that the structure of the json, meaning the attributes, are the same as the columns of the database table in the same order.  Also, I’ve only tested this with a file of 1000 rows. It will probably do much more but I assume there is a limit to what it can do.  That being said this is not your ETL tool for Steampunk, so don’t try loading a file with millions of lines in it. So again, not a whole lot of intelligence built into it right now.

In this example, I have a json file with 3 attributes, COLA, COLB, COLC which correspond to my columns in the database table called ZRH_TEST

 

 

When you click the “Upload File” button, the tool creates a dynamic internal table and deserializes the json into that internal table and then simply does an INSERT into the database table.  There is some error handling built in there, but again not all that robust at the moment. It does do the job quite nicely though, as oppose to having a massive method of INSERT statements.

We are releasing this tool on our SAP-samples github.  Instructions on how to install the tool are provided in the README there.

We hope this is helpful for you guys!  Till next time…

 

10 Comments
You must be Logged on to comment or reply to a post.
  • /
    Errors
  • Thanks to this great post ? I managed to get an upload for json files for my rap generator.

    So if you just need to upload a json and have to perform some fancy stuff you can check my stripped down version that only uploads the json file without any dependency on table names.

    https://blogs.sap.com/2020/09/11/how-to-use-the-rap-generator/

  • Thank you for this great blog! I just started developing apps based on ABAP environment and was astonished to see the complexity of a simple file upload. So I implemented your code to upload csv-files which worked perfectly and is very useful to add data to db tables for testing.
    But, I am a bit at a loss about how to use this for enabling a customer to upload data. In our app the customer would create a project and add source systems. Using a button (realized via cds-view actions) the customer shall upload a list of organizational units to be stored on DB. I assume that I cannot ask for pressing the URL button in the http connectivity artefact in Eclipse... 🙂
    - I see that the connectivity item is transportable: if transported to customer would this automatically enable to access the presentation server or would it needed to be recreated?
    - How do I create an http client right with ABAP code using this connectivity? Is there an XCO like class to read the URL from the connectivity item to pass it to lo_http_destination = cl_http_destination_provider=>create_by_url( <connectivity> )?
    - ...or would we create by cloud destination, meaning that it is required to have a destination to presentation server avaliable on cloud platform?
    Alternative would be to do the upload using Javascript in the Fiori app, but then I need another means (web API) to pass the data to the ABAP environment. I would prefer to keep the logic right in my ABAP code.
    I searched the web up and down but I did not find anything addressing this topic like you do. Would be great if you could at least give a hint to where to continue the search or to speed me up on the uptake...