I’m trying to write text to a local file (i.e. on my laptop) using the following code:
data: fname(60), text type string value 'la la la'.
fname = 'myfile.txt'.
OPEN DATASET fname FOR OUTPUT IN TEXT MODE encoding default.
TRANSFER text TO fname.
CLOSE DATASET fname.
write 'done'.
The program runs fine and “done” appears after execution. However I cannot find the text file “myfile.txt” on my PC (it’s not in the SAP work directory).
Additional Info
I have gotten this working using the function module GUI_DOWNLOAD, however I have to use the OPEN DATASET and TRANSFER statements as I’m writing this in a background program (to be called by a BSP using SUBMIT).
It is not possible to write to a client while in background processing because nature of background processing is that no client machine has to be connected to the WAS. By default all files are save into sever directory
DIR_HOME.SOLUTION:
Generally downloading data is achieved by setting the right HTTP header fields and pushing the binary data into the http response with the help of
cl_bsp_utility=>download.This class sets the right content headers in your response.
You have to specify your data in
XSTRINGform and specify whichContent-TypeandContent-Dispositionyou want, for exampleapplication/vnd.ms-excelorapplication/octetstream.Also
Content-Dispositioncan be used to tell the browser the default filename to use, seeP.S.
For general information on working with files in ABAP you can refer to this help file http://wiki.sdn.sap.com/wiki/display/ABAP/Working+with+files