SAP Function GUI_DOWNLOAD - Download an Internal Table to the PC

Parameter Reference Type Length Default Optional Text
APPEND CHAR01 C 1 SPACE X Writing mode (overwrite, append)
BIN_FILESIZE I I 4 X File length for binary files
CODEPAGE ABAP_ENCODING 0 SPACE X Character Representation for Output
COL_SELECT CHAR01 C 1 SPACE X Copy Single Columns of the Table Only
COL_SELECT_MASK CHAR255 C 255 SPACE X Vector Containing an 'X' for the Column To Be Copied
CONFIRM_OVERWRITE CHAR01 C 1 SPACE X Overwrite File Only After Confirmation
DAT_MODE CHAR01 C 1 SPACE X Numeric and Date Fields Written in ws_download 'DAT' Format
FILENAME STRING g 0 Name of file
FILETYPE CHAR10 C 10 'ASC' X File Type (ASC or BIN)
HEADER XSTRING y 0 '00' X Byte Chain Written in Binary Mode at the Start of the File
IGNORE_CERR ABAP_BOOL 0 ABAP_TRUE X Specifies whether to ignore errors converting character sets
NO_AUTH_CHECK CHAR01 C 1 SPACE X Switch off Check for Access Rights
REPLACEMENT ABAP_REPL C 1 '#' X Replacement Character for Non-Convertible Characters
SHOW_TRANSFER_STATUS ABAP_BOOL 0 ABAP_TRUE X
TRUNC_TRAILING_BLANKS CHAR01 C 1 SPACE X Do not Write Blank at the End of Char Fields
TRUNC_TRAILING_BLANKS_EOL CHAR01 C 1 'X' X Removes spaces at end of last column
WK1_N_FORMAT 0 SPACE X Format for value columns in files of the type WK1
WK1_N_SIZE 0 SPACE X Column width for value columns in files of the type WK1
WK1_T_FORMAT 0 SPACE X Format for text columns for files of the type WK1
WK1_T_SIZE 0 SPACE X Column width for text columns for files of the type WK1
WRITE_BOM ABAP_BOOL 0 SPACE X If set, writes a Unicode byte order mark
WRITE_FIELD_SEPARATOR CHAR01 C 1 SPACE X Separate Columns by Tabs in Case of ASCII Download
WRITE_LF CHAR01 C 1 'X' X Insert CR/LF at End of Line in Case of Char Download
WRITE_LF_AFTER_LAST_LINE ABAP_BOOL 0 ABAP_TRUE X Writes LF even after last line

Parameter Reference Type Length Text
FILELENGTH I I 4 Number of bytes transferred

Parameter Reference Length Optional Text
DATA_TAB 0 Transfer table
FIELDNAMES 0 X Field Names for the 'DBF' File Type

Exception Text
ACCESS_DENIED Access to File Denied
CONTROL_FLUSH_ERROR Error in Control Framework
DATAPROVIDER_EXCEPTION General Exception Error in Data Provider
DISK_FULL Storage Medium Full
DP_ERROR_CREATE Cannot Create Data Provider
DP_ERROR_SEND Error Sending Data with DataProvider
DP_ERROR_WRITE Error Writing Data with DataProvider
DP_OUT_OF_MEMORY Not Enough Memory in DataProvider
DP_TIMEOUT Timeout of DataProvider
FILESIZE_NOT_ALLOWED File Size Must Not Be Specified
FILE_NOT_FOUND Cannot Find File
FILE_WRITE_ERROR Cannot write to file
GUI_REFUSE_FILETRANSFER Incorrect Front End
HEADER_NOT_ALLOWED Header not Allowed
HEADER_TOO_LONG The header information is limited to 1023 bytes at present
INVALID_TYPE Invalid value for parameter FILETYPE
NO_AUTHORITY No Download Authorization
NO_BATCH Front-End Function Cannot Be Executed in Background
SEPARATOR_NOT_ALLOWED Separator not Allowed
UNKNOWN_DP_ERROR Error Calling Data Provider
UNKNOWN_ERROR

Functionality
Data transfer of an internal table form the server to a file on the PC.The Gui_Download module replaces the obsolete modules Ws_Download andDownload. The file dialog of the download module is available in theclass Cl_Gui_Frontend_Services.

Notes
TYPE-POOLS: ABAP.
* Binary download table
DATA: BEGIN OF line_bin,
data(1024) TYPE X,
END OF line_bin.
DATA: data_tab_bin LIKE STANDARD TABLE OF line_bin.
* Ascii download table
DATA: BEGIN OF line_asc,
text(1024) TYPE C,
END OF line_asc.
DATA: data_tab_asc LIKE STANDARD TABLE OF line_asc.
* DAT download table
DATA: BEGIN OF line_dat,
Packed TYPE P,
Text(10) TYPE C,
Number TYPE I,
Date TYPE D,
Time TYPE T,
Float TYPE F,
Hex(3) TYPE X,
String TYPE String,
END OF line_dat.
DATA: data_tab_dat LIKE STANDARD TABLE OF line_dat.
* Get filename
DATA: fullpath TYPE String,
filename TYPE String,
path TYPE String,
user_action TYPE I,
encoding TYPE ABAP_ENCODING.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
EXPORTING
WINDOW_TITLE = 'Gui_Download Demo'
WITH_ENCODING = 'X'
INITIAL_DIRECTORY = 'C:\'
CHANGING
FILENAME = filename
PATH = path
FULLPATH = fullpath
USER_ACTION = user_action
FILE_ENCODING = encoding
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
NOT_SUPPORTED_BY_GUI = 3
others = 4.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
IF user_action <> CL_GUI_FRONTEND_SERVICES=>ACTION_OK.
EXIT.
ENDIF.
* Download variables
DATA: length TYPE I.
* Binary download
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = fullpath
FILETYPE = 'BIN'
IMPORTING
FILELENGTH = length
TABLES
DATA_TAB = data_tab_bin
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22.
* Ascii download
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = fullpath
FILETYPE = 'ASC'
IMPORTING
FILELENGTH = length
TABLES
DATA_TAB = data_tab_asc
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22.
* DAT download
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = fullpath
FILETYPE = 'DAT'
IMPORTING
FILELENGTH = length
TABLES
DATA_TAB = data_tab_dat
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22.

Description
Number of bytes transferred.

Value range
Any natural number including zero.

Description
By default, existing local files are overwritten by new versions. Bysetting APPEND to 'X', the downloaded data is appended to an existingfile. If the file does not yet exist, it is created.

Value range
'X' = Data is appended.
SPACE = Data is overwritten if the file already exists.

Default
SPACE

Description
When creating a binary file, you must specify the file length, becausethe transfer table (single-column, type X) in the last row must not beabsolutely valid.
If the parameter is set in a text download, the exceptionFILESIZE_NIT_ALLOWED is triggered.

Value range
Any natural number including zero.

Default
The entire data table is downloaded.

Description
Use parameter CODEPAGE to specify the desired target codepage. If thisparameter is not set, the codepage of the SAP GUI is used as the targetcodepage.

Value range
4-digit number of the SAP codepage. The function moduleSCP_CODEPAGE_BY_EXTERNAL_NAME returns the SAP codepage number for anexternal character set name, for example, "iso-8859-1". The functionmodule NLS_GET_FRONTEND_CP returns the appropriate non-Unicode frontendcodepage for a language.
You can determine the desired codepage interactively, if the parameterwith_encoding of method file_save_dialog is set bycl_gui_frontend_services.
SPACE: Codepage of the SAP GUI

Default
SPACE

Description
Activate column selection. You use column selection to select thecolumns to be transferred to the file. This parameter is available onlyfor FILETYPE 'DAT' and 'DBF'.

Value range
'X': Activate selection
SPACE: Do not activate selection

Default
SPACE

Description
Masking the columns selection. In connection with COL_SELECT a columnselection becomes possible.

Value range
Character field of up to 128 characters, consisting of SPACE and 'x'.Every character represents a column of the table. A SPACE represents acolumn to be omitted, any other character represents a column to beinserted.
Example: COL_SELECT = 'X'
COL_SELECTMASK = 'X X X'
The columns 1,3,5 are downloaded.

Default
SPACE

Description
If this parameter is set, a file is overwritten only after aconfirmation by the user.

Value range
'X': Confirmation required.
SPACE: No confirmation required.

Default
SPACE

Description
If parameter DAT_MODE is set, the file is stored in 'DAT' format. Noconversion exits are performed. Number and date fields are stored in astandard format which makes it possible, to later import the file usinggui_upload.

Value range
'X': DAT_MODE is switched on.
SPACE: DAT_MODE is not switched on.

Default
SPACE

Description
Name of the file to be created locally (if required with path name as aprefix). If the path is invalid or the file cannot be opened forwriting, the respective exceptions are triggered.

Value range
A valid file name.

Default

Description
During download, the data can be transferred in different formats,depending on the value of the FILETYPE parameter.

Value range
'ASC' :
ASCII format. The table is transferred as text. Conversion exits areperformed. The output format additionally depends on the parametersCODEPAGE, TRUNC_TRAILING_BLANKS, and TRUNC_TRAILING_BLANKS_EOL.
'IBM' :
ASCII format with IBM codepage conversion (DOS). This format correspondsto the 'ASC' format when using target codepage 1103. This codepage isfrequently used for data exchange via floppy disk.
'DAT' :
Column-by-column transfer. With this format, the data is transferred astext as with ASC. However, no conversion exits are performed and thecolumns are separated by tab characters. This format generates filesthan can be uploaded again using gui_upload or ws_upload.
'DBF' :
Data is downloaded in dBase format. Since in this format the data typesof the individual columns are stored as well, you can often avoid importproblems, for example, into Microsoft Excel, especially wheninterpreting numeric values.
'WK1' :
Data is downloaded in Lotus 1-2-3 format.
'BIN' :
Binary format. Data is transferred binarily. There is no formatting andno codepage conversion. The data is interpreted row by row; it is notformatted by columns. Specify the data length in parameter BIN_FILESIZE.The table should consist of a column of type X, because especially inUnicode systems, the conversion of structured into binary data causeserrors.

Default
'ASC'

Description
This parameter allows you to prefix the data with individual bytesduring a binary download.

Value range
Hexadecimal string with a length of up to 1023 bytes.

Default
'00'

Description
Specifies whether errors during a character set conversion shall beignored.

Value range
ABAP_FALSE
Errors during a character set conversion, which result in using thereplacement character, are not ignored but trigger an exception.
ABAP_TRUE
If a character cannot be converted correctly and must be represented bythe replacement character, no exception is triggered.

Default
ABAP_TRUE

Description
This parameter is transferred to the customer exit to check the accessrights.

Value range
'X': Switch check off
SPACE: Keep check switched on

Default
SPACE

Description
Specifies the replacement character to be used when during a characterset conversion a character cannot be converted.

Value range
An individual character.

Default
'#'

Description
By default, possible blanks at the end of a text column are nottransferred. You can use this parameter to change the behavior to keepthe blanks. However, this does not include the blanks at the end of thelast column. If you want to keep them as well, use parameterTRUNC_TRAILING_BLANKS_EOL instead.

Value range
'X': Blanks are removed.
SPACE: Blanks are transferred.

Default
'X'

Description
By default, possible blanks at the end of a text column are nottransferred. You can use this parameter to change this behavior for thelast column of the table so that the blanks are kept. The parameter doesnot influence the other columns of the table. To keep them, useparameter TRUNC_TRAILING_BLANKS.

Value range
'X': Blanks in the last column are removed.
SPACE: Blanks in the last column are transferred.

Default
'X'

Description
Format for value columns of WK1 file type

Value range
'0' : Standard format
'1x' : Fixed point format with x decimal places
'2x' : Currency format with x decimal places

Default
SPACE

Description
Column width for value columns of WK1 file type
Sets the column width for value columns. If WK1_N_SIZE is not set, forevery value column the output length of the field is set as width.

Default
SPACE

Description
Format for text columns of WK1 file type

Value range
'0' : Left-justified
'1' : Right-justified
'2' : centered

Default
SPACE

Description
Column width for text columns of WK1 file type
Determines the column width for text columns. If WK1_T_SIZE is not set,for every text column the output length of the field is used as width.

Value range
Maximum value is 240, otherwise the value is reduced to 240.

Default
SPACE

Description
If the data is written in a Unicode codepage, at the beginning of thefile the respective byte order mark (BOM) is inserted.
Unicode - Little Endian Codepage 4103, binary values 'FFFE'
Unicode - Big Endian Codepage 4102, binary values 'FEFF'
UTF-8 Codepage 4110, binary values 'EFBBBF'
Note: Microsoft Excel only supports Unicode data if they have beenwritten in the format Unicode - Little Endian.

Value range
'X': Write BOM.
SPACE: Do not write BOM.

Default
SPACE

Description
In the downloaded file, the columns are separated by tab characters(cl_abap_char_utilities=>horizontal_tab). You should use this setting ifyou want to upload the data from the file at a later time, because thisis the only way of identifying individual columns.
The parameter makes sense only for the FILETYPE values ASC, DAT and IBM;for DAT it is set implicitly.

Value range
'X' : Write separator.
SPACE : Do not write separator.

Default
SPACE

Description
If this parameter is set, at the end of each row a row separator isinserted by CL_ABAP_CHAR_UTILITIES=>CR_LF. This parameter makes senseonly for FILETYPE 'ASC', 'DAT' and 'IBM'. If this parameter is not set,blanks at the end of a row are not removed.

Value range
'X': Row separator is inserted.
SPACE: Row separator is not inserted.

Default
'X'

Description
Data table which contains the data to be downloaded.

Value range
An internal table with any number of fields which must be of theelementary type.

Description
Optional table with column names for the individual columns.

  • 'DBF': The column names are entered into the structure definition of the
  • DBF file.
    • 'DAT': An additional row with the column names is inserted at the
    • beginning of the table.

1793179SAP GUI: GUI_DOWNLOAD is not able to append the large files
1073779setting the Frontend Up-/Download Codepage
1543940Crash after second upload/download of the same "doc"-file
513435Windows code page setup for non-Unicode text files
1248933VIES 390 RO - Cannot Run on Background
1150217Showcase ENCODING: Editor bug - or - Codepage issue?
1088209Help for troubleshooting: Code page display problems
752835Usage of the file interfaces in Unicode systems
991520Note Assistant: External PDF display in the note log
915756NC-9901: Wage figures and employee count not separated
843753GUI_DOWNLOAD and blended code page and release >= 6.10
747615Tool for converting files from one code page to another
798365ITS Up/Down: Folders are not created during the download
695907Syslog CP7 ... rscpc 180
709813VETS: Call to WS_DOWNLOAD replaced by Call to GUI_DOWNLOAD
687754BP_TR2: FM FTBU_START_EXCEL terminates with a runtime error
617872DMEE: Runtime error during upload/download of XML tree
606217DMEE: Error with creation of XML file