DATA: l_path TYPE string.
DATA:BEGIN OF t_fieldnames OCCURS 0,
name TYPE char20,
END OF t_fieldnames.
""lt_data 为导出内表
CLEAR t_fieldnames[].
LOOP AT it_field INTO data(wa_field).
t_fieldnames-name = wa_field-seltext_l.
APPEND t_fieldnames.
ENDLOOP.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* BIN_FILESIZE =
filename = l_path
filetype = 'DAT'
"这里一般用DAT,如果用ASC则1000-不会显示为-1000,而dat会显示为-1000,如果用DBF则不会有缩进,
即字符前面的空格会被除去,而且字符的前导0也会输出。
* APPEND = ' '
write_field_separator = 'X' "列由制表符分隔 该参数仅对文件类型值ASC、DAT和IBM有意义;对于DAT,它是隐式设置的。
* HEADER = '00'
* TRUNC_TRAILING_BLANKS = ' '
* write_lf = 'X' "每一行的结尾处插入行分隔符
* COL_SELECT = ' '
* COL_SELECT_MASK = ' '
* DAT_MODE = ' '
* CONFIRM_OVERWRITE = ' '
no_auth_check = 'X'
codepage = '8404'
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* WRITE_BOM = ' '
* TRUNC_TRAILING_BLANKS_EOL = 'X'
* WK1_N_FORMAT = ' '
* WK1_N_SIZE = ' '
* WK1_T_FORMAT = ' '
* WK1_T_SIZE = ' '
* WRITE_LF_AFTER_LAST_LINE = ABAP_TRUE
* SHOW_TRANSFER_STATUS = ABAP_TRUE
* VIRUS_SCAN_PROFILE = '/SCET/GUI_DOWNLOAD'
* IMPORTING
* FILELENGTH =
TABLES
data_tab = lt_data
fieldnames = t_fieldnames[]
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.
IF sy-subrc <> 0.
MESSAGE '导出异常' TYPE 'E'.
ENDIF.
附:文件路径选择
DATA: l_filetable TYPE filetable,
ls_filetable TYPE file_table,
ls_rc TYPE i.
CLEAR: l_filetable,ls_rc,l_path.
*文件路径选择
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = '请选择本地文件' "对话框的标题
default_extension = 'XLS' "默认的文件后缀名
* default_filename = 'defaultfilename' "默认打开的文件名
* file_filter = 'Excel文件(*.XLSX)|*.XLSX|全部文件 (*.*)|*.*|' "文件打开的filter
file_filter = 'XLS文件(*.XLS)|全部文件 (*.*)|*.*|' "文件打开的filter
* INITIAL_DIRECTORY = "初始化的目录
* MULTISELECTION = "是否可以同时打开多个文件
* WITH_ENCODING =
CHANGING
file_table = l_filetable
rc = ls_rc
* USER_ACTION =
* FILE_ENCODING =
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5.
*读取路径
LOOP AT l_filetable INTO ls_filetable.
l_path = ls_filetable-filename.
ENDLOOP.