Writing Data to Presentation Server (no Dialog)
To write data from an internal table to the presentation server without using a user dialog, use the function module WS_DOWNLOAD. The most important parameters are listed below. For more information, refer to the function module documentation in the Function Builder (Transaction SE37).
Important Import Parameters
Parameter |
Function |
BIN_FILESIZE |
File length for binary files |
CODEPAGE |
Only for download under DOS: Value IBM |
FILENAME |
Filename |
FILETYPE |
File type |
MODE |
Write mode (blank = overwrite, ‘A’ = append) |
Use the FILETYPE parameter to specify the transfer mode. Possible values:
Binary files: You must specify the file length. The internal table must consist of a single column with data type X.
ASCII files:
Excel files: The columns are separated using tabs. The lines are separated with line breaks.
Excel and Lotus files: The files are saved in a WK1 spreadsheet.
Export Parameter
Parameter |
Function |
FILELENGTH |
Number of bytes transferred |
Tables Parameters
Parameter |
Function |
DATA_TAB |
Internal table containing data |
Exceptions Parameters
Parameter |
Function |
FILE_OPEN_ERROR |
Unable to open the file |
FILE_WRITE_ERROR |
Unable to write to file |
INVALID_FILESIZE |
Invalid parameter BIN_FILESIZE |
INVALID_TABLE_WIDTH |
Invalid table structure |
INVALID_TYPE |
Value of FILETYPE parameter is incorrect |
Suppose the presentation server is running under Windows NT, and you have written the following program:
PROGRAM SAPMZTST.
DATA: FLENGTH TYPE I.
DATA TAB(80) OCCURS 5.
APPEND 'This is the first line of my text. ' TO TAB.
APPEND 'The second line. ' TO TAB.
APPEND ' The third line. ' TO TAB.
APPEND ' The fourth line. ' TO TAB.
APPEND ' Fifth and final line. ' TO TAB.
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
CODEPAGE = 'IBM'
FILENAME = 'd:\temp\saptest.txt'
FILETYPE = 'ASC'
IMPORTING
FILELENGTH = FLENGTH
TABLES
DATA_TAB = TAB
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_WRITE_ERROR = 2
INVALID_FILESIZE = 3
INVALID_TABLE_WIDTH = 4
INVALID_TYPE = 5.
WRITE: 'SY-SUBRC :', SY-SUBRC,
/ 'File length:', FLENGTH.
The output appears as follows:
SY-SUBRC : 0
File length: 151
The system has written the five lines of the table TAB into the ASCII file D:\temp\saptest.txt. You can now use the Windows Explorer to check that the file exists:
You can now open the file D:\temp\saptest.xls using any editor on the presentation server. Here, we have used the DOS Editor.