Writing Data to Presentation Server (Dialog)
To write data from an internal table to the presentation server using a user dialog, use the function module 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 (default value for user dialog) |
FILETYPE |
File type (default value for user dialog) |
ITEM |
Title for dialog box |
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.
Important Export Parameters
Parameter |
Function |
ACT_FILENAME |
File name (as entered in the user dialog) |
ACT_FILETYPE |
File type (as entered in the user dialog) |
FILESIZE |
Number of bytes transferred |
Tables Parameters
Parameter |
Function |
DATA_TAB |
Internal table containing data |
Exceptions Parameters
Parameter |
Function |
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: FNAME(128), FTYPE(3), FSIZE TYPE I.
TYPES: BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
TYPES ITAB TYPE LINE OCCURS 10.
DATA: LIN TYPE LINE,
TAB TYPE ITAB.
DO 5 TIMES.
LIN-COL1 = SY-INDEX.
LIN-COL2 = SY-INDEX ** 2.
APPEND LIN TO TAB.
ENDDO.
CALL FUNCTION 'DOWNLOAD'
EXPORTING
CODEPAGE = 'IBM'
FILENAME = 'd:\temp\saptest.xls'
FILETYPE = 'DAT'
ITEM = 'Test for Excel File'
IMPORTING
ACT_FILENAME = FNAME
ACT_FILETYPE = FTYPE
FILESIZE = FSIZE
TABLES
DATA_TAB = TAB
EXCEPTIONS
INVALID_FILESIZE = 1
INVALID_TABLE_WIDTH = 2
INVALID_TYPE = 3.
WRITE: 'SY-SUBRC:', SY-SUBRC,
/ 'Name :', (60) FNAME,
/ 'Type :', FTYPE,
/ 'Size :', FSIZE.
The program displays the following dialog box:
Here, the user can change the default values. When the user chooses Transfer, the system writes the data from the internal table TAB, filled in the program, into the file D:\temp\saptest.xls. If the file already exists, the system asks the user whether it should replace the existing version. The system inserts tabs between the columns, and line breaks at the end of each line.
The output appears as follows:
SY-SUBRC: 0
Name : d:\temp\saptest.xls
Type : DAT
Size : 27
You can now open the file D:\temp\saptest.xls using MS Excel on the presentation server. It looks like this: