[英]Assigning Field Symbols to Internal Table
I'm trying upload Excel file to internal table in ABAP.我正在尝试将 Excel 文件上传到 ABAP 中的内部表。 I'm using function GUI_UPLOAD
and then SCMS_BINARY_TO_XSTRING
.我正在使用 function GUI_UPLOAD
然后SCMS_BINARY_TO_XSTRING
。 At last I have field sybmbol <gt_data>
with data from Excel file.最后,我有来自 Excel 文件的数据的字段 sybmbol <gt_data>
。
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>.
A [CString]一个 [CString] | B [CString] B [C字符串] |
---|---|
data1数据1 | data11数据11 |
data2数据2 | data22数据22 |
data3数据3 | data33数据33 |
How I can iterate <gt_data>
to internal table?如何将<gt_data>
迭代到内部表? I would try like below, but I received dump.我会尝试如下,但我收到了转储。
TYPES: BEGIN OF lty_test,
A TYPE string,
B TYPE string,
END OF lty_test.
DATA: lt_test_table TYPE STANDARD TABLE OF lty_test.
As far as I understood, you want to read excel rows with this code.据我了解,您想使用此代码读取 excel 行。
LOOP AT <gt_data> ASSIGNING FIELD-SYMBOL(<ls_data>).
ENDLOOP.
I am not sure struct of <ls_data> but I think you can read it with index for get to know main idea.我不确定 <ls_data> 的结构,但我认为您可以使用索引阅读它以了解主要思想。
Could you try it like below?你能像下面这样试试吗?
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.
Try this:尝试这个:
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.
So first you need to declare a structure for the internal table and each field in the structure should have type "string".因此,首先您需要为内部表声明一个结构,并且该结构中的每个字段都应具有“字符串”类型。
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>
Now internal table it_upload should have the data from the field value现在内部表 it_upload 应该有来自字段值的数据
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.