파일 다운로드
cl_gui_frontend_services=>gui_download(
EXPORTING
* bin_filesize = " File length for binary files
filename = " Name of file
* filetype = 'ASC' " File type (ASCII, binary ...)
* append = SPACE " Character Field of Length 1
* write_field_separator = SPACE " Separate Columns by Tabs in Case of ASCII Download
* header = '00' " Byte Chain Written to Beginning of File in Binary Mode
* trunc_trailing_blanks = SPACE " Do not Write Blank at the End of Char Fields
* write_lf = 'X' " Insert CR/LF at End of Line in Case of Char Download
* col_select = SPACE " Copy Only Selected Columns of the Table
* col_select_mask = SPACE " Vector Containing an 'X' for the Column To Be Copied
* dat_mode = SPACE " Numeric and date fields are in DAT format in WS_DOWNLOAD
* confirm_overwrite = SPACE " Overwrite File Only After Confirmation
* no_auth_check = SPACE " Switch off Check for Access Rights
* codepage = " Character Representation for Output
* ignore_cerr = ABAP_TRUE " Ignore character set conversion errors?
* replacement = '#' " Replacement Character for Non-Convertible Characters
* write_bom = SPACE " If set, writes a Unicode byte order mark
* trunc_trailing_blanks_eol = 'X' " Remove Trailing Blanks in Last Column
* wk1_n_format = SPACE
* wk1_n_size = SPACE
* wk1_t_format = SPACE
* wk1_t_size = SPACE
* show_transfer_status = 'X' " Enables suppression of transfer status message
* fieldnames = " Table Field Names
* write_lf_after_last_line = 'X' " Writes a CR/LF after final data record
* virus_scan_profile = '/SCET/GUI_DOWNLOAD' " Virus Scan Profile
* IMPORTING
* filelength = " Number of bytes transferred
CHANGING
data_tab = " Transfer table
* 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
* not_supported_by_gui = 22
* error_no_gui = 23
* others = 24
).
CO CL_GUI_FRONTEND_SERVICES GUI_DOWNLOAD
____________________________________________________
내역
Download Data to Client PC
Functionality
The file transfer function is used to load data from an internal table
on the back end into a file in the file system of the presentation
server.
Parameters
o BIN_FILESIZE (importing)
This parameter specifies the number of bytes to be stored in the
file during the next binary download of the data table. The
length of the header, if any, is not included in this value.
Value range: Any natural number including zero
Default: The entire data table is downloaded.
o FILENAME (importing)
This parameter contains the name of the data file on the
frontend.
Value range: A valid file name
o FILETYPE (importing)
This parameter describes how the download file is created.
Value range: ASC or BIN
Filetype = 'BIN': The system writes a binary representation of
the internal table into the file. The individual fields are not
interpreted in this case. When mixed tables are transferred in
binary mode, note that bytes used for the alignment are
transferred as well.
Filetype = 'ASC': The system writes the table on a
component-by-component basis. Fields of type 'C' are transferred
in their entire defined length in this case. If the table also
contains fields of other types, you should set the parameter
WRITE_FIELD_SEPARATOR. Otherwise, you cannot upload the data
later. No conversion exits are executed when the individual
fields are written. If you need these exits, you should use
WRITE to explicitly write the internal table to a table with a
character field before the module is called. Note that you
normally cannot upload files created in this way.
o APPEND (importing)
This parameter specifies whether the data contained in the
interal table should be appended to the file.
Value range: 'X' means that the data is appended to the file.
SPACE means that the new data overwrites the old data.
Default: SPACE
o WRITE_FIELD_SEPARATOR (importing)
This parameter specifies whether tabs should be output between
the fields of a row in the internal table. This is necessary if
the table contains fields of types other than 'C' and you want
to upload the table later.
Value range: 'X' means that a separator is used; SPACE means
that no separator is used.
Default: SPACE
o HEADER (importing)
This parameter contains an optional header which is written at
the beginning of the file during a binary download. You can use
this header to add information about the code page and the byte
sequence if the internal table was created through code page
conversion using GUI_CONVERT_CODEPAGE.
Value range: A hexadecimal string with a length of at most 1023
bytes.
Default: '00' (= empty header)
o TRUNC_TRAILING_BLANKS (importing)
o WRITE_LF (importing)
o COL_SELECT (importing)
This parameter activates the column selection for multi-column
tables. Currently, this option is only available for FILETYPE =
'DAT'.
Value range: SPACE means that this function is not active;
otherwise, it is active
o COL_SELECTMASK
This parameter allows column selection in combination with
COL_SELECT.
Each character represents a column of the table. SPACE means
that the column should be omitted, any other character means
that the column should be inserted.
Example: COL_SELECT = 'X'
COL_SELECTMASK = 'X X X'
Columns 1, 3, and 5 are downloaded.
Value range: Character field up to 128 characters, consisting of
SPACE and 'x'.
o FILELENGTH (exporting)
This parameter specifies the number of bytes transferred.
Value range: Any natural number including zero.
o DATA_TAB (changing)
This parameter determines the data table which contains the data
to be downloaded.
Value range: An internal table with any number of fields which
must be of the elementary type. Important: If you want to carry
out a binary download, the download table must be of the HEX
type. Otherwise, a code page conversion takes place.
Notes
Differences between the old and new function modules
BIN mode: No longer supported. The bin_filesize is now a required entry.
DAT mode: No longer supported. Use ASC instead.
ASC mode: Still supported
VSS mode: No longer supported. Use ASC instead. In the internal table,
there should be a line-end character..
IBM mode: No longer supported.
WK1 mode: No longer supported.
DBF mode: No longer supported.
HQX mode: No longer supported.
CODEPAGE parameter: Convert data first. Use CL_ABAP_CONV_OUT_CE.
Restriction: In the old function modules, you could specify a default
download path. This is no longer possible.
Below you can find a "cookbook" for migrating from the old function
modules to the new ones based on the download function:
METHOD export_document.
DATA lineno TYPE i.
DATA size TYPE i.
DATA filename TYPE string.
DATA pathname TYPE string.
data fullpath type string.
data filefilter type string.
data user_action type i.
DATA picture TYPE sdydo_picture.
DATA files TYPE TABLE OF bapifiles.
DATA wa TYPE bapifiles.
DATA my_bds TYPE REF TO cl_bds_document_set.
DATA existing TYPE abap_bool.
* 1 Get the filename and path for saving.
class CL_GUI_FRONTEND_SERVICES definition load.
concatenate CL_GUI_FRONTEND_SERVICES=>filetype_html
CL_GUI_FRONTEND_SERVICES=>FILETYPE_ALL
into filefilter.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
EXPORTING
DEFAULT_EXTENSION = 'htm'
* The default extension is used if all file types are selected in
* the dialog window and no extension is added to the file name.
FILE_FILTER = filefilter
CHANGING
FILENAME = filename
PATH = pathname
FULLPATH = fullpath
USER_ACTION = user_action
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
others = 3
.
IF SY-SUBRC <> 0.
RAISE export_error.
ENDIF.
* If the user has not cancelled the file name and path input,
* save the files.
if not user_action = CL_GUI_FRONTEND_SERVICES=>ACTION_CANCEL.
DESCRIBE TABLE html_table LINES lineno.
size = lineno * 255.
* 2. Download HTML Table
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE = size
FILENAME = fullpath
FILETYPE = 'BIN'
TABLES
DATA_TAB = html_table
EXCEPTIONS
OTHERS = 1
.
IF SY-SUBRC <> 0.
RAISE export_error.
ENDIF.
* 3. Download pictures if necessary
SORT table_of_pictures.
DELETE ADJACENT DUPLICATES FROM table_of_pictures.
LOOP AT table_of_pictures INTO picture.
CONCATENATE pathname picture-object_internal INTO filename.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_EXIST
EXPORTING
FILE = filename
RECEIVING
RESULT = existing
EXCEPTIONS
others = 1
.
IF SY-SUBRC <> 0.
RAISE export_error.
ENDIF.
IF existing = abap_false.
* picture not already in the download directory
* -> download from BDS
IF my_bds IS INITIAL.
CREATE OBJECT my_bds.
ENDIF.
wa-comp_count = 1.
wa-directory = pathname.
wa-mimetype = 'IMAGE/GIF'.
APPEND wa TO files.
IF picture-object_id(5) EQ 'ICON_'.
CALL METHOD my_bds->get_with_files
EXPORTING classname = 'SAP_ICONS'
classtype = 'OT'
object_key = picture-object_id
CHANGING files = files
EXCEPTIONS OTHERS = 1.
ELSE.
CALL METHOD my_bds->get_with_files
EXPORTING classname = 'PICTURES'
classtype = 'OT'
object_key = picture-object_id
CHANGING files = files
EXCEPTIONS OTHERS = 1.
ENDIF.
IF sy-subrc NE 0.
RAISE export_error.
ENDIF.
CLEAR files.
APPEND wa TO files.
ENDIF.
ENDLOOP.
endif. "if not fullpath is initial
ENDMETHOD.