DATA: lc_ref TYPE REF TO cx_root.
DATA:
dref_i TYPE REF TO data,
elem_type TYPE REF TO cl_abap_elemdescr.
DATA:
dref_str TYPE REF TO data,
struct_type TYPE REF TO cl_abap_structdescr,
comp_tab TYPE cl_abap_structdescr=>component_table WITH HEADER LINE.
DATA:
dref_tab TYPE REF TO data,
itab_type TYPE REF TO cl_abap_tabledescr,
table_type TYPE REF TO cl_abap_tabledescr.
DATA: lt_intern TYPE alsmex_tabline OCCURS 0 .
DATA: lt_row TYPE alsmex_tabline OCCURS 0.
IF p_fname IS INITIAL .
MESSAGE '请选择数据文件' TYPE 'I' DISPLAY LIKE 'E' .
LEAVE LIST-PROCESSING.
ENDIF .
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_fname
i_begin_col = 1
i_begin_row = 1
i_end_col = 20
i_end_row = 9999
TABLES
intern = lt_intern[]
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO DATA(lv_msgtxt).
MESSAGE e001(zfi) WITH TEXT-e05 lv_msgtxt.
STOP.
ENDIF.
"扩展结构字段
**表头行
DATA: lt_head TYPE alsmex_tabline OCCURS 0 WITH HEADER LINE.
DATA: lt_head_name TYPE alsmex_tabline OCCURS 0 WITH HEADER LINE.
LOOP AT lt_intern INTO DATA(ls_intern) WHERE row = '0001'.
lt_head = ls_intern.
APPEND lt_head.
CLEAR:lt_head_name.
ENDLOOP.
LOOP AT lt_intern INTO ls_intern WHERE row = '002'.
lt_head_name = ls_intern.
APPEND lt_head_name.
CLEAR:lt_head_name.
ENDLOOP.
CHECK lt_head[] IS NOT INITIAL.
*"动态赋值
LOOP AT lt_intern INTO DATA(wa) WHERE row > 0002 GROUP BY ( key = wa-row ) ASSIGNING FIELD-SYMBOL(<fs_row>).
* 同一行的所有列字段信息
lt_row = VALUE #( FOR m IN GROUP <fs_row> ( m ) ).
* 循环列索引填充到动态表,基于索引完整一致性
LOOP AT lt_row INTO DATA(ls_col).
TRY.
DATA(head) = lt_head[ col = ls_col-col ].
ASSIGN COMPONENT head-value OF STRUCTURE gs_table TO FIELD-SYMBOL(<fs_colum>).
IF <fs_colum> IS ASSIGNED .
<fs_colum> = ls_col-value.
IF head-value = 'SEQ'.
IF ls_col-value > 999.
MESSAGE TEXT-014 TYPE 'I' DISPLAY LIKE 'E'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDIF.
ENDIF.
CATCH cx_root.
DATA(head_name) = lt_head_name[ col = ls_col-col ].
gt_error = VALUE #( BASE gt_error ( |excel内容存在错误格信息:行{ <fs_row>-key }列:{ head_name-value }| ) ).
ENDTRY.
ENDLOOP.
APPEND gs_table TO gt_table.
CLEAR:gs_table.
ENDLOOP.
IF gt_error[] IS NOT INITIAL.
not_pass = 'X'.
ENDIF.