一、效果
二、模板上传
2.1 、T-code为:SMW0
2.2、选择包
2.3、点击创建、并上传附件!
三、代码实现
*定义按钮 SELECTION-SCREEN BEGIN OF BLOCK blk2 WITH FRAME TITLE text02. SELECTION-SCREEN PUSHBUTTON /1(10) button USER-COMMAND cli1 MODIF ID m02. SELECTION-SCREEN END OF BLOCK blk2. *初始化 INITIALIZATION. gv_objid = 'Z_SECSTO_UPDATE'. AT SELECTION-SCREEN. IF sy-ucomm = 'CLI1'. PERFORM frm_download_file USING gv_objid. ENDIF. *调用模板 FORM frm_download_file USING p_gv_objid. DATA: lv_filename TYPE string, lv_path TYPE string, lv_fullpath TYPE string, lv_user_action TYPE i, lv_destination LIKE rlgrap-filename, ls_objdata LIKE wwwdatatab, lv_objid TYPE wwwdatatab-objid, lv_rc TYPE sy-subrc. IF sy-ucomm = 'CLI1'. lv_filename = '安全库存更新模板'. CONCATENATE sy-datum '_' sy-uzeit '_' lv_filename INTO lv_filename. CALL METHOD cl_gui_frontend_services=>file_save_dialog EXPORTING default_extension = 'XLSX' default_file_name = lv_filename initial_directory = lv_path CHANGING filename = lv_filename path = lv_path fullpath = lv_fullpath user_action = lv_user_action EXCEPTIONS cntl_error = 1 error_no_gui = 2 not_supported_by_gui = 3 OTHERS = 4. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ELSE. CLEAR: lv_destination. lv_destination = lv_fullpath. ENDIF. CHECK lv_user_action <> 9. SELECT SINGLE relid objid FROM wwwdata INTO CORRESPONDING FIELDS OF ls_objdata WHERE srtf2 = 0 AND objid = p_gv_objid AND relid = 'MI'. IF sy-subrc = 0. CLEAR: lv_rc. CALL FUNCTION 'DOWNLOAD_WEB_OBJECT' "#EC * EXPORTING key = ls_objdata destination = lv_destination IMPORTING rc = lv_rc. IF lv_rc NE 0. MESSAGE '该数据模板不存在!' TYPE 'E'. ELSE. MESSAGE '模板下载成功' TYPE 'S'. ENDIF. ELSE. MESSAGE '该数据模板不存在!' TYPE 'E'. ENDIF. ENDIF. CLEAR sy-ucomm. ENDFORM.