Report Z_BARRY_TEST.
DATA: filename TYPE string ,
openfile LIKE ibipparms-path ,
lf_rc TYPE c .
DATA: it_file TYPE filetable WITH HEADER LINE,
file_num TYPE i ,
action TYPE i,
encoding TYPE abap_encod.
PARAMETERS: filestr TYPE string OBLIGATORY DEFAULT 'c:\ZMM025.txt' .
AT SELECTION-SCREEN ON VALUE-REQUEST FOR filestr .
* CALL FUNCTION 'F4_FILENAME'
* EXPORTING
* program_name = syst-cprog
* dynpro_number = syst-dynnr
* field_name = ' '
* IMPORTING
* file_name = openfile.
* filestr = openfile.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = 'Title'
default_extension = 'XLS' " file_filter优先级高
file_filter = '文本文件(*.TXT)|*.TXT|Excel 文件 (*.XLS)|*.XLS;*.XLSX|所有文件 (*.*)|*.*|'
with_encoding = 'X'
initial_directory = 'C:\'
multiselection = 'X'
CHANGING
file_table = it_file[]
rc = file_num
user_action = action
file_encoding = encoding
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5.
IF action = 0 AND sy-subrc = 0 .
READ TABLE it_file INDEX 1.
filestr = it_file-filename.
ENDIF.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
mask = ',Excel文件(*.XLS;*.XLSX),*.XLS;*.XLSX,文本文件(*.TXT),*.TXT,所有文件(*.*),*.*.'
mode = 'O'
IMPORTING
filename = openfile
rc = lf_rc
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
OTHERS = 5.
IF lf_rc = ''.
filestr = openfile.
ENDIF.
AT SELECTION-SCREEN .
filename = filestr.
CALL METHOD cl_gui_frontend_services=>file_exist
EXPORTING
file = filename
RECEIVING
result = lf_rc
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
wrong_parameter = 3
not_supported_by_gui = 4
OTHERS = 5.
IF lf_rc = ''.
MESSAGE e000(oo) WITH '文件' filename '不存在!'.
ENDIF.
--------------------------------
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = filename
filetype = 'DAT'
TABLES
data_tab = it_upfile
EXCEPTIONS
OTHERS = 1.
IF sy-subrc = 1.
MESSAGE e000(oo) WITH '文件打开错误'.
ENDIF.
阅读(3272) | 评论(3) | 转发(0) |