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…
Cool.. thanks Rich for sharing !!
thanks, this a great Idea!
Unfortunately you use lots of non whitelisted stuff:
So how should I use this class?
PS See also https://github.com/SAP-samples/abap-file-uploader/issues/1
Please refer to the requirements section in the Github project:
"Note: The XCO APIs are available automatically in trial systems and require no further steps. In productive accounts: "The XCO library is currently only available via feature toggle. If you are interested in using this new feature, please contact SAP." https://help.sap.com/doc/43b304f99a8145809c78f292bfc0bc58/Cloud/en-US/98bf747111574187a7c76f8ced51cfeb.html For more general information on XCO: https://blogs.sap.com/2020/05/17/the-rap-generator"
BTW: We plan to release the XCO library without Feature Toggle with release 2008 (planned upgrade mid of August).
yes, this section was added because of my question and issue…
And yes, after activating XCO (thank you Frank), this works now and is absolutly great!
Just a hint for other readers: “contact SAP” means eg. create an incident.
Thanks Rich.. let me try and will be back if I face any issue.
Thanks for sharing Rich.
Hi Rich ,
When will be available the Excel format ?
Thank you !
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.
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?
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...
For SAP BTP ABAP Environment and SAP S/4HANA Cloud there is now an app available that allows you to upload data into tables via uploading Excel “.xslx” file format.
Upload Business Configuration - SAP Help Portal