TABLES: alsmex_tabline,ztraining_wxj.
DATA: BEGIN OF iexcel OCCURS 0.
INCLUDE STRUCTURE alsmex_tabline.
DATA: END OF iexcel.
DATA: BEGIN OF itab OCCURS 0.
INCLUDE STRUCTURE ztraining_wxj.
DATA: END OF itab.
DATA wa LIKE LINE OF itab.
* No of columns
DATA: BEGIN OF data_tab OCCURS 0,
value_0001(003) TYPE c,
value_0002(004) TYPE c,
value_0003(010) TYPE c,
value_0004(002) TYPE c,
value_0005(020) TYPE c.
DATA: END OF data_tab. "存放excel里的数据
DATA: tind(4) TYPE n.
DATA: zwfeld(19).
FIELD-SYMBOLS: <fs1>.
DATA: filenm LIKE rlgrap-filename.
call function 'WS_FILENAME_GET'
exporting
title = '请选择目标文件文件 '
importing
filename = filenm
exceptions
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
others = 5.
*PARAMETERS: filenm LIKE rlgrap-filename MEMORY ID m01,
* noheader AS CHECKBOX.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = filenm
i_begin_col = 1
i_begin_row = 1
i_end_col = 100
i_end_row = 30000
TABLES
intern = iexcel "excel数据所在的内表
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
WRITE: / 'EXCEL UPLOAD FAILED ', filenm, sy-subrc.
ELSE.
SORT iexcel BY row col.
LOOP AT iexcel FROM 6. "从第6个字段开始读取,第五个是地址
tind = iexcel-col.
CONCATENATE 'DATA_TAB-VALUE_' tind INTO zwfeld.
ASSIGN (zwfeld) TO <fs1>. "
<fs1> = iexcel-value.
AT END OF row.
APPEND data_tab.
* move-corresponding data_tab to wa.
wa-zpid = data_tab-value_0002.
wa-mandt = data_tab-value_0001.
wa-zpname = data_tab-value_0003.
wa-zpage = data_tab-value_0004.
wa-zpaddress = data_tab-value_0005.
APPEND wa TO itab.
* WRITE:/ data_tab-value_0001, data_tab-value_0002,
* data_tab-value_0003, data_tab-value_0004.
* write : / wa-zpid, wa-zpname.
INSERT into ztraining_wxj values wa.
IF sy-subrc = 0.
MESSAGE '成功更新' TYPE 'I'.
ELSE.
MESSAGE '更新失败' TYPE 'I'.
ENDIF.
CLEAR data_tab.
ENDAT.
ENDLOOP.
ENDIF.