TABLES: SSCRFIELDS.
1.模板上传:
输入事务代码smw0
2.模板下载
ls_key-relid = ‘MI’.
ls_key-objid = ‘Zxxxtest’. " Use TCODE:SMW0 to upload the template
IF lv_cancel EQ ‘X’ .
MESSAGE s001. " 用户取消了操作
RETURN.
ENDIF.
IF lv_file_path IS INITIAL.
MESSAGE s002. " 文件路径不能为空!
RETURN.
ENDIF.
CALL FUNCTION ‘DOWNLOAD_WEB_OBJECT’
EXPORTING
key = ls_key
destination = lv_file_path
IMPORTING
rc = lv_rc
- CHANGING
-
TEMP =
- 3.读取要导入的数据路径
- AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
PERFORM sub_frm_f4_for_file.
FORM sub_frm_f4_for_file .
DATA: l_rc TYPE i,
l_filetable TYPE filetable.
CONSTANTS:
cns_open_filter TYPE string VALUE ‘Microsoft Excel文件(.xls;.xlsx)|.xls;.xlsx|(.)|.|’. - Open The txt File
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = ‘请选择导入文件’
file_filter = cns_open_filter
multiselection = space
CHANGING
file_table = l_filetable
rc = l_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 AND l_rc = 1.
READ TABLE l_filetable INTO p_file INDEX 1.
ENDIF.
ENDFORM.
4.数据上传
FORM frm_uplod_data .
DATA: lt_exc_data TYPE STANDARD TABLE OF alsmex_tabline.
DATA: lw_exc_data TYPE alsmex_tabline.
DATA: lv_col TYPE i.
FIELD-SYMBOLS .
REFRESH gt_excel.
CALL FUNCTION ‘ALSM_EXCEL_TO_INTERNAL_TABLE’
EXPORTING
filename = p_file
i_begin_col = 1
i_begin_row = 2
i_end_col = 7
i_end_row = 65535
TABLES
intern = lt_exc_data
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc = 0. - 处理读取出的数据
SORT lt_exc_data BY row col.
LOOP AT lt_exc_data INTO lw_exc_data.
lv_col = lw_exc_data-col." + 1.
ASSIGN COMPONENT lv_col OF STRUCTURE gt_excel TO .
IF sy-subrc = 0.
= lw_exc_data-value.
ENDIF.
AT END OF row.
APPEND gt_excel.
CLEAR gt_excel.
ENDAT.
ENDLOOP.
ENDIF.
IF gt_excel[] IS INITIAL.
MESSAGE s005 DISPLAY LIKE ‘E’.
SET SCREEN 0.
ENDIF.
ENDFORM.