给内部表分配字段符号



我正在尝试将Excel文件上传到ABAP的内部表。我用函数GUI_UPLOADSCMS_BINARY_TO_XSTRING。最后我有字段符号<gt_data>与数据从Excel文件。

DATA(lo_data_ref) = lo_excel_ref->if_fdt_doc_spreadsheet~get_itab_from_worksheet(
lv_woksheetname ).
*-- Excel work sheet data in dyanmic internal table
ASSIGN lo_data_ref->* TO <gt_data>.
<表类>(装运箱)B(装运箱)tbody><<tr>data1data11data2data22data3data33

据我所知,您希望使用此代码读取excel行。

LOOP AT <gt_data> ASSIGNING FIELD-SYMBOL(<ls_data>).
ENDLOOP.

我不确定但我认为你可以带着索引阅读,以了解主要思想。

你能像下面这样试试吗?

CHECK <gt_data> IS ASSIGNED.
"It's column count for excel file. It can be found dynamically.
DATA(lv_column_count) = 10.
"Loop for rows.
LOOP AT <gt_data> ASSIGNING FIELD-SYMBOL(<ls_data>).
"Loop for columns
DO lv_column_count.
ASSIGN COMPONENT sy-index OF <ls_dat> TO FIELD-SYMBOL(<lfs_value>).
ENDDO.
ENDLOOP.

因此,首先需要为内部表声明一个结构,并且该结构中的每个字段的类型应为"字符串"。

Types:begin of ty_upload,
Field1 type string,
Field2 type string,
End of ty_upload.
Data:it_upload type standard table of ty_upload.
It_upload[] = <gt_data>

现在内部表it_upload应该有来自字段值

的数据

试试这个:

file = 'C:xyz.XLS'.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename                = file
i_begin_col             = '1'
i_begin_row             = '1'
i_end_col               = '5'
i_end_row               = '6000'
TABLES
intern                  = xcel
EXCEPTIONS
inconsistent_parameters = 1
upload_ole              = 2
OTHERS                  = 3.
LOOP AT xcel.
" xcel is an internal table and has field xcel-value
ENDLOOP.

最新更新