Create and Download a File from ABAP

DevWorkbench Sunday August 24th, 2014

After yesterday’s post about uploading files into ABAP variables, let’s look at things the other way round – how to provide data for download by your users.

I don’t think it comes as a huge surprise to you that CL_GUI_FRONTEND_SERVICES is, once again, the tool of our choice to do the task. The way to do it is quite similar to yesterday’s post about file uploading. Instead of the methods FILE_OPEN_DIALOG and GUI_UPLOAD, we will make use of FILE_SAVE_DIALOG and GUI_DOWNLOAD.

Let’s look at the code. We need some data first, so I’m putting some dummy data into a table that we can export later. The next step is to call the method that displays a file save dialog and get the name and path under which the file should be saved.

…aaaand we’re done! Even simpler than file uploading, isn’t it? This makes it easy for your users to import and export data to and from SAP. Of course, there’s a lot more you can do – just check out all the method parameters of both methods. Enjoy playing around!