【转自 http://blog.csdn.net/zhongguomao/article/details/6712576】
*----------------------- Method 1 --------------------------------------
PARAMETERS: f_file LIKE rfpdo1-febumsf OBLIGATORY.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR f_file.
DATA: files TYPE filetable,
h_files TYPE file_table,
rc LIKE sy-subrc.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = '下载到本地文件'
default_extension = 'XLS'
default_file_name = '默认文件名称'
file_filter = '文本文件(*.TXT)|*.TXT|Excel 文件 (*.XLS)|*.XLS;*.XLSX|所有文件 (*.*)|*.*|'
with_encoding = 'X'
initial_directory = 'C:\'
CHANGING
file_table = files
rc = rc
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
OTHERS = 4.
IF sy-subrc <> 0 OR rc < 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*---Get file name
READ TABLE files INDEX 1 INTO h_files.
f_file = h_files-filename.
*----------------------- Method 2 --------------------------------------
PARAMETER: p_file TYPE rlgrap-filename OBLIGATORY.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = ' '
IMPORTING
file_name = p_file.
*----------------------- Method 3 --------------------------------------
PARAMETERS: p_file LIKE rlgrap-filename MEMORY ID m01.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
DATA: lc_mask TYPE char30.
lc_mask = 'Excel Files,*.xls,All Files,*.*.'.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
def_filename = '*.xls'
mask = 'Excel Files,*.xls,All Files,*.*.'
mode = 'O'
title = '请选择文件'
IMPORTING
filename = p_file
EXCEPTIONS
selection_cancel = 1
OTHERS = 2.