今天给大家分享一个函数,可以用来下载Excel和TXT格式的文件,非常好用
所需的变量:
DATA:lv_filename TYPE string,lv_path TYPE string,lv_fullpath TYPE string,lv_destination LIKE rlgrap-filename,ls_objdata LIKE wwwdatatab,lv_objid TYPE wwwdatatab-objid,lv_fname TYPE string.
首先调用一个类的方法,用来选取我们下载的保存的地址:
CALL METHOD cl_gui_frontend_services=>file_save_dialogEXPORTINGdefault_file_name = lv_fnameCHANGINGfilename = lv_filenamepath = lv_pathfullpath = lv_fullpathEXCEPTIONScntl_error = 1error_no_gui = 2not_supported_by_gui = 3OTHERS = 4.
接下来我们调用下载的函数:
CALL FUNCTION 'GUI_DOWNLOAD'EXPORTINGfilename = lv_filename "文件名filetype = 'ASC' "文件类型write_field_separator = 'X'codepage = '8404' "gbk格式TABLESdata_tab = gt_xml "下载的数据FIELDNAMES = gt_head "抬头EXCEPTIONSfile_write_error = 1no_batch = 2gui_refuse_filetransfer = 3invalid_type = 4no_authority = 5unknown_error = 6header_not_allowed = 7separator_not_allowed = 8filesize_not_allowed = 9header_too_long = 10dp_error_create = 11dp_error_send = 12dp_error_write = 13unknown_dp_error = 14access_denied = 15dp_out_of_memory = 16disk_full = 17dp_timeout = 18file_not_found = 19dataprovider_exception = 20control_flush_error = 21OTHERS = 22.