Save Internal Table Data in Background using ABAP Code
ABAP programmer can save internal table data executing in background on SAP Application Server using sample ABAP code in this tutorial. Using AL11 SAP transaction code, SAP directories and included files can be displayed by users.
As illustrated with a sample case, ABAP developers can export and save data stored in internal table using ABAP function module WS_DOWNLOAD easily.
On the other hand, programmers can not use WS_DOWNLOAD if they want to run ABAP report in background.
When I check the ST22 ABAP dumps list I got the following error detail text for exception condition:
Front-End Function Cannot Be Executed in Background
You can find detailed documentation about the exception condition in transaction SE37 (Function Library). You can find the name of the function module called from the display of active calls.
In such a case a safe function module or an ABAP code should be used for exporting ABAP internal table data which will not cause programming errors when executed as a background process.
If ABAP programmer has a requirement to execute an ABAP report in background and export or save internal table data as text file, following sample ABAP code can help.
Here is the ABAP report which SAP user can execute in background without error and save internal table lt_report as text file.
Above ABAP program will create a file named ExportData including the execution time to seperate repeated data export files. The data stored in internal table lt_report is concatenated into a string variable for each row using ABAP Loop command and transferred to data file which is created by "open dataset ... for output in text mode" command. After all data is transferred to text file, simple execute "close dataset" ABAP command for completing the SAP data export.
Please note that between selected structure fields, I preferred to use semi-colon as seperator. You can use or not usei or choose an other character variable for seperating export fields.
After executing above ABAP program in background, SAP user can browse SAP Application Server directories and files under tmp folder using AL11 SAP transaction code.
I have created a few data export text files for this tutorial as seen in below screenshot.
How to export internal table data to text file and write file on SAP application server using ABAP in background execution