利用 Method cl_gui_frontend_services=>file_open_dialog 打开文件。
*default_filename:如有value, 则优先此文件(1.doc)或类型(*.doc).如无值则ignore
* file_filter:与default_filename无直接关系,filename可以是filter未列出的文件类型。当filename为空时,则优先过滤第一个文件类型。
Example:
*----------------------------------------------------------------------*
FORM. open_file .
DATA:lt_file_name TYPE filetable,
wa_file_name TYPE file_table,
lt_rc TYPE i.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = 'Open file'
default_filename = '*.PDF'
file_filter = 'All Files (*.*)|*.*|Excel Files (*.xls)|*.xls|Word files(*.doc)|*.doc'
* default_filename = 'C:\TEST.txt' "默认打开的文件名
initial_directory = 'C:' "初始化的目录
multiselection = 'X' "是否可以同时打开多个文件
CHANGING
file_table = lt_file_name
rc = lt_rc
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
READ TABLE lt_file_name INDEX 1 INTO wa_file_name.
MOVE wa_file_name TO p_file.
ENDFORM. " OPEN_FILE
*----------------------------------------------------------------------*
Result:
![bb](http://img.blog.itpub.net/blog/attachments/2013/06/26817415_201306071611381.jpg?x-oss-process=style/bb)
![bb](http://img.blog.itpub.net/blog/attachments/2013/06/26817415_201306071612061.jpg?x-oss-process=style/bb)
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26817415/viewspace-763442/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/26817415/viewspace-763442/