日常开发中遇到的批导开发程序,都是通过tcode:SMW0 将模板excel文件上传到服务器
界面上放置下载模板的工具栏按钮,用户使用时下载模板并编辑数据,然后上传文件进行导入处理
程序如下
REPORT zfile_upload. TABLES: sscrfields. SELECTION-SCREEN FUNCTION KEY 1. SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE t01. PARAMETERS:p_file TYPE localfile. SELECTION-SCREEN END OF BLOCK b1. DATA: gt_files TYPE filetable. TYPES: BEGIN OF ty_data, bukrs TYPE bukrs, vkorg TYPE vkorg, budat TYPE budat, refence TYPE char10, butxt TYPE char50, matnr TYPE matnr, price TYPE dec18_2, new_price TYPE dec18_2, END OF ty_data. TYPES: tty_data TYPE STANDARD TABLE OF ty_data. DATA: gt_data TYPE tty_data. INITIALIZATION. sscrfields-functxt_01 = '模板文件'. sscrfields-functxt_01+40 = icon_document. sscrfields-functxt_01+44 = '模板文件'. t01 = '文件上传'. %_p_file_%_app_%-text = '文件导入'. AT SELECTION-SCREEN. DATA: lv_filename TYPE string, lv_path TYPE string, lv_fullpath TYPE string, l_rc LIKE sy-subrc, l_objdata TYPE wwwdatatab, lv_dest TYPE localfile. CASE sscrfields-ucomm. WHEN 'FC01'. cl_gui_frontend_services=>file_save_dialog( EXPORTING window_title = 'Save the document' default_file_name = 'Document' default_extension = 'xls' file_filter = cl_gui_frontend_services=>filetype_excel CHANGING filename = lv_filename path = lv_path fullpath = lv_fullpath EXCEPTIONS cntl_error = 1 error_no_gui = 2 invalid_default_file_name = 3 not_supported_by_gui = 4 OTHERS = 5 ). IF lv_filename IS INITIAL. MESSAGE '已取消下载模板' TYPE 'W'. ENDIF. SELECT SINGLE relid,objid FROM wwwdata INTO CORRESPONDING FIELDS OF @l_objdata WHERE relid = 'MI' AND objid = 'ZSDR0031' . lv_dest = lv_fullpath. CALL FUNCTION 'DOWNLOAD_WEB_OBJECT' EXPORTING key = l_objdata destination = lv_dest IMPORTING rc = l_rc CHANGING temp = lv_dest. ENDCASE. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file. "两种方式 F4_FILENAME 或者 cl_gui_frontend_services=>file_open_dialog "通过file_open_dialog有更多的个性化参数 * CALL FUNCTION 'F4_FILENAME' * IMPORTING * file_name = p_file. "返回文件名 DATA:lt_files TYPE filetable, lv_rc TYPE i. cl_gui_frontend_services=>file_open_dialog( EXPORTING default_extension = 'xls' file_filter = cl_gui_frontend_services=>filetype_excel window_title = '请选择文件' multiselection = abap_false CHANGING file_table = gt_files rc = lv_rc ). IF lv_rc = 1. p_file = gt_files[ 1 ]-filename. ENDIF. START-OF-SELECTION. DATA(lo_excel) = NEW zcl_excel_reader_2007( )->zif_excel_reader~load_file( i_filename = gt_files[ 1 ]-filename ). lo_excel->get_worksheet_by_index( 1 )->get_table( EXPORTING iv_skipped_cols = 1 iv_skipped_rows = 2 iv_skip_bottom_empty_rows = abap_true IMPORTING et_table = gt_data ). cl_demo_output=>display( gt_data ).
标签:gt,data,lv,ABAP,批导,file,TYPE,模板 From: https://www.cnblogs.com/Lingcc/p/17528087.html