具体参考:
ABAP EXCEL 下载摸板
FORM fm_get_filepath .
DATA: lv_filename TYPE string,
lv_path TYPE string,
lv_fullpath TYPE string,
lv_title TYPE string.
co_objid = 'ZMMRP002'.
CONCATENATE co_objid '-' sy-datum sy-uzeit INTO lv_title .
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
window_title = '模板保存为EXCEL'
default_extension = 'xls'
default_file_name = lv_title
* file_filter = '.xls'
file_filter = 'Excel 文件 (*.XLS)'
initial_directory = 'D:/'
* DEFAULT_FILE_NAME = p_filename
CHANGING
filename = lv_filename
path = lv_path
fullpath = gv_fullpath
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.
IF sy-subrc <> 0.
STOP .
ENDIF.
ENDFORM.
下载功能主要调用 FM ‘DOWNLOAD_WEB_OBJECT’
传入上述定义的模板名称以及文件保存的路径
返回下载的状态
DATA: ls_indcatortxt TYPE string,
p_filename TYPE sapb-sappfad.
DATA: lo_objdata LIKE wwwdatatab,
lo_mime LIKE w3mime,
ls_destination LIKE rlgrap-filename,
ls_objnam TYPE string,
li_rc LIKE sy-subrc,
ls_errtxt TYPE string.
p_filename = gv_fullpath.
”ABAP 进度条设置
ls_indcatortxt = '程序正在下载模板' .
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
percentage = 0
text = ls_indcatortxt.
CONCATENATE co_objid '.XLS' INTO ls_objnam.
CONDENSE ls_objnam NO-GAPS.
"判断模板文件是否存在
SELECT SINGLE relid objid FROM wwwdata
INTO CORRESPONDING FIELDS OF lo_objdata
WHERE srtf2 = 0
AND relid = 'MI'
AND objid = co_objid .
IF sy-subrc NE 0 OR lo_objdata-objid EQ space .
CONCATENATE '模板文件:' ls_objnam '不存在,请用TCODE:SMW0进行加载' INTO ls_errtxt.
MESSAGE ls_errtxt TYPE 'E' .
ENDIF.
"下载文件功能"
ls_destination = gv_fullpath.
CALL FUNCTION 'DOWNLOAD_WEB_OBJECT
EXPORTING
key = lo_objdata
destination = ls_destination
IMPORTING
rc = li_rc.
IF li_rc NE 0.
CONCATENATE '模板文件:' ls_objnam '下载失败' INTO ls_errtxt.
MESSAGE ls_errtxt TYPE 'E' .
ENDIF.