Question

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).

Était-ce utile?

La solution

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 XSTRING form and specify which Content-Type and Content-Disposition you want, for example application/vnd.ms-excel or application/octetstream.

Also Content-Disposition can be used to tell the browser the default filename to use, see

attachment; filename=filexyz.xls`

P.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

Autres conseils

The OPEN DATASET and related keywords operate on files on the server only. There are various other options for getting the file on to the target machine from a background process.

  1. If your server and client machines run on Windows, you can map a Windows path in AL11 and save the file there. (Note that you will have to open the target Windows machine firewall to allow this traffic).

  2. You can run an FTP server on the target machine and ftp the files there. SAP has function modules to deal with this. Look at function group SFTP.

  3. If both machines run some version of UNIX, you can even SCP the files on to the target machine (as most Unixes will include ssh and therefore scp). You will have to create an external command in SM49 and then set up public key authentication from the server to the target machine, which is a bit more tricky if you don't have admin rights on the SAP server, but there are ways around that too.

As Turismo wrote: In Background processing, you can not write on a PC. Writing to a PC needs a connected SAPGui (=Client).

OPEN DATASET and TRANSFER writes the data to the server.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top