转:
*&---------------------------------------------------------------------*
*& Report Z_BARRY_FILE_SELECT
*&
*&---------------------------------------------------------------------*
*& 文件、路径选取模板
*&
*&---------------------------------------------------------------------*
REPORT z_barry_file_select.
TABLES rlgrap.
DATA: gd_path TYPE string.
DATA: it_tab TYPE filetable,
gd_subrc TYPE i.
DATA: ld_filename TYPE string,
ld_path TYPE string,
ld_fullpath TYPE string,
ld_result TYPE i,
gd_file TYPE c.
SELECT-OPTIONS openfile FOR rlgrap-filename.
PARAMETERS: savefile TYPE rlgrap-filename.
PARAMETERS: filepath LIKE rlgrap-filename.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR filepath.
CALL METHOD cl_gui_frontend_services=>directory_browse
EXPORTING
window_title = ‘File Directory‘
initial_folder = ‘C:‘
CHANGING
selected_folder = gd_path.
CALL METHOD cl_gui_cfw=>flush.
CONCATENATE gd_path ‘‘ INTO filepath.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR openfile-low.
REFRESH: it_tab.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = ‘Select File‘
default_filename = ‘*.txt‘
multiselection = ‘X‘
CHANGING
file_table = it_tab
rc = gd_subrc.
LOOP AT it_tab INTO openfile-low.
openfile-sign = ‘I‘.
openfile-option = ‘EQ‘.
APPEND openfile.
ENDLOOP.
CALL METHOD cl_gui_cfw=>flush.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR savefile.
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
default_extension = ‘XLS‘
default_file_name = ‘accountsdata‘
initial_directory = ‘c:/temp/‘
CHANGING
filename = ld_filename
path = ld_path
fullpath = ld_fullpath
user_action = ld_result.
savefile = ld_fullpath.
选择文件夹
PARAMETERS p_ifname TYPE rlgrap-filename. "import rfq file
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_efname.
CALL FUNCTION ‘TMP_GUI_BROWSE_FOR_FOLDER‘
EXPORTING
window_title = ‘Select Folder...‘(004)
initial_folder = ‘‘
IMPORTING
selected_folder = p_ifname
EXCEPTIONS
cntl_error = 1
OTHERS = 2.
FORM process_import_files USING p_file TYPE localfile.
DATA: l_dir TYPE string,
l_filecount TYPE i,
l_result.
DATA: lt_table TYPE STANDARD TABLE OF file_info.
l_dir = p_file.
"check path exist
CALL METHOD cl_gui_frontend_services=>directory_exist
EXPORTING
directory = l_dir
RECEIVING
result = l_result
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
wrong_parameter = 3
not_supported_by_gui = 4
OTHERS = 5.
IF sy-subrc = 0 AND l_result <> ‘X‘.
MESSAGE ‘The folder does not exist.‘(006) TYPE ‘S‘ DISPLAY LIKE ‘E‘.
RETURN.
* Implement suitable error handling here
ENDIF.
CALL METHOD cl_gui_frontend_services=>directory_list_files
EXPORTING
directory = l_dir
* filter = ‘*.*‘ "‘*.XLS;*.XLSX;*.XLSM‘
files_only = ‘X‘
* directories_only =
CHANGING
file_table = lt_table
count = l_filecount
EXCEPTIONS
cntl_error = 1
directory_list_files_failed = 2
wrong_parameter = 3
error_no_gui = 4
not_supported_by_gui = 5
OTHERS = 6.
IF sy-subrc <> 0 .
.......
ENDIF.
ENDFORM. " PROCESS_IMPORT_FILES