How to write text to a local file

I am 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 works fine, and after execution appears "done". However, I cannot find the text file "myfile.txt" on my PC (it is not in the SAP working directory).

Additional Information

I got this working using the GUI_DOWNLOAD function module, however I have to use the OPEN DATASET and TRANSFER statements since I am writing this in the background program (for calling BSP using SUBMIT ).

+4
source share
3 answers

Unable to write to client during background processing.
The nature of the background processing is that the client machine should not be connected to the WAS.

If file creation is time consuming, you can initiate file creation in WAS and then offer a list of files to download somewhere in your BSP application.

Update:
If you simply provide a file name, the file will be placed in the directory specified by the DIR_HOME profile DIR_HOME . You can check / change profile settings in RZ11 or browse directories in AL11.

For general information on working with files in ABAP, you can refer to http://wiki.sdn.sap.com/wiki/display/ABAP/Working+with+files

second update:
Typically, data loading is achieved by setting the correct HTTP header fields and pushing binary data into the HTTP response.
You should take a look at cl_bsp_utility=>download .
This sets the correct content headers in your answer. You must specify your data (as XSTRING ) and indicate which Content-Type and Content-Disposition you want.
Content-Type is the type of mime file. So, for an Excel file, which could be application/vnd.ms-excel , or you can use something common, like application/octetstream .
Content-Disposition can be used to tell the browser the default file name. An approximate value might be attachment; filename=filexyz.xls attachment; filename=filexyz.xls .

Remember that browsers may have slightly different behavior based on a combination of Content-Type and Content-Disposition (i.e. offering the Save As ... dialog instead of showing it in a line).

+6
source

OPEN DATASET and related keywords only work with files on the server. There are various other options for downloading a file to the target computer from a background process.

  • If your server and client computers are running Windows, you can map the Windows path to AL11 and save the file there. (Note that you will need to open the target Windows firewall to allow this traffic).

  • You can run the FTP server on the target machine and ftp files there. SAP has functional modules to solve this problem. Look at the SFTP feature group.

  • If both machines run some version of UNIX, you can even have SCP files on the target machine (since most Unixes will include ssh and therefore scp). You will need to create an external command in SM49, and then configure the public key authentication from the server to the target computer, which is a little more complicated if you do not have administrator rights on the SAP server, but there are ways, too.

+5
source

As Turismo wrote: In the background, you cannot write to a PC. Writing to a PC requires a connected SAPGui (= Client).

OPEN DATASET and TRANSFER writes data to the server.

0
source

Source: https://habr.com/ru/post/1391835/


All Articles