一:事物码smw0
二:步骤
注:“包”为项目的包的名称。
三:下载代码
*&---------------------------------------------------------------------*
* 初始化
*&---------------------------------------------------------------------*
selection-screen:
function key ."定义按钮1 *&---------------------------------------------------------------------*
* initialization:启动程序开始执行,初始话数据
*&---------------------------------------------------------------------*
initialization.
sscrfields-functxt_01 = '下载配置导入模板'. at selection-screen.
"下载模板
case sscrfields-ucomm.
when 'fc01'.
perform frm_downlaod_excel." 下载模板
when others.
endcase.
*&---------------------------------------------------------------------*
*& form frm_downlaod_excel
*&---------------------------------------------------------------------*
* 下载模板
*----------------------------------------------------------------------*
form frm_downlaod_excel.
data:lv_fname type string,
lv_init_path type string,
lv_title type string,
lv_path type string," value 'd:/',
lv_fpath type string," value 'd:/',
lv_file type rlgrap-filename. data:lv_objid type char20,
ls_wdatb like wwwdatatab,
lv_subrc type sy-subrc,
lv_msg type string. lv_objid = 'zrmm492'.
lv_fname = '配置设计确认导入模板'.
concatenate lv_fname '下载' into lv_title. "获取桌面路径
call method cl_gui_frontend_services=>get_desktop_directory
changing
desktop_directory = lv_init_path
exceptions
cntl_error =
error_no_gui =
not_supported_by_gui =
others = .
if sy-subrc <> .
exit.
endif. "保存文件
call method cl_gui_frontend_services=>file_save_dialog
exporting
window_title = lv_title
default_extension = 'xls'
default_file_name = lv_fname
initial_directory = lv_init_path
file_filter = 'excel文件(*.xls)||全部文件(*.*)||'
prompt_on_overwrite = 'x'
changing
filename = lv_fname
path = lv_path
fullpath = lv_fpath
exceptions
cntl_error =
error_no_gui =
not_supported_by_gui =
others = .
if sy-subrc <> .
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
else.
clear:lv_file.
lv_file = lv_fpath.
if lv_file is not initial.
"判断文件模板是否存在
select single
relid
objid
from wwwdata
into corresponding fields of ls_wdatb
where srtf2 =
and relid = 'mi'
and objid = lv_objid. if ls_wdatb is initial.
message '模板不存在' type 'e'.
else. call function 'download_web_object'
exporting
key = ls_wdatb
destination = lv_file
importing
rc = lv_subrc.
if lv_subrc <> .
message '模板下载失败' type 'e'.
else.
clear:lv_msg.
concatenate '模板下载到本地文件' lv_file into lv_msg.
message lv_msg type 's'.
endif.
endif.
else.
message '用户取消操作' type 's' .
return.
endif.
endif.
endform. "frm_downlaod_excel