SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
Development resources, articles, tutorials, code samples, tools and downloads for SAP HANA and ABAP, HANA Database, SQLScript, SAP UI5, Screen Personas, Web Dynpro, Workflow

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.

execute ABAP program 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.

save ABAP internal table data in background

Here is the ABAP report which SAP user can execute in background without error and save internal table lt_report as text file.

data lt_report type table of gty_report.
data lr_report type ref to gty_report.


data i_filename type string.
concatenate '/tmp/ExportData' sy-uzeit '.txt' into i_filename.

open dataset i_filename for output in text mode
 encoding default ignoring conversion errors.
if sy-subrc ne 0.
* error handling code

data lv_tmpstr type string.
loop at lt_report reference into lr_report.
 concatenate lr_report->vbeln lr_report->idoc into lv_tmpstr seperated by ';'.
 transfer lv_tmpstr to i_filename.

close dataset i_filename.

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.

export internal table data to text file on SAP application server using ABAP in background
How to export internal table data to text file and write file on SAP application server using ABAP in background execution


Install SAP Free
CRM Companies List
Web Based CRM Software

Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.