2009 Oct 29 10:55 AM
Hey folks,
i want to upload a CSV file into a internal table of my own defined type using the TYPES command. The idea is that i define a type corresponding to the columns of the CSV, so during the upload the values are moved into the right fields of the table. And i can use the internal table with simply adressing the correct field names.
Is this possible with the function module "'ALSM_EXCEL_TO_INTERNAL_TABLE'" ?
e.g.
Contents CSV:
Name_first | Name_last | Street |
ABAP Code:
TYPES:
BEGIN OF owntype,
name_first(30) TYPE c,
name_last(30) TYPE c,
street(30) TYPE c,
END OF owntype.
DATA:
it_table TYPE TABLE OF owntype.
CALL FUNCTION ALSM_EXCEL_TO_INTERNAL_TABLE
.....
TABLES
i_table = it_table
....
Thanks for your help!
2009 Oct 29 1:38 PM
Hi,
<li>In SAP CSV means ; (colon) separated file.
<li>We have TEXT_CONVERT_CSV_TO_SAP function module but if you see inside the function module field separator defaulted to ;.
<li>Try this way.
Thanks
Venkat.OREPORT ztest.
TYPES:
BEGIN OF owntype,
name_first(30) TYPE c,
name_last(30) TYPE c,
street(30) TYPE c,
END OF owntype.
DATA:
it_table TYPE TABLE OF owntype,
wa_table TYPE owntype.
TYPE-POOLS:truxs.
DATA:i_tab_raw_data TYPE truxs_t_text_data.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'C:\temp\test.txt'
filetype = 'ASC'
TABLES
data_tab = i_tab_raw_data.
CALL FUNCTION 'TEXT_CONVERT_CSV_TO_SAP'
EXPORTING
i_tab_raw_data = i_tab_raw_data
TABLES
i_tab_converted_data = it_table.
LOOP AT it_table INTO wa_table.
WRITE:/ wa_table-name_first,
wa_table-name_last,
wa_table-street.
ENDLOOP.
2010 Jan 29 5:39 AM
But if your data is comma separated (NOT semicolon separated) i.e. every field is separated by ',' - then call to the below function module would possibly be helpful to get the raw data into your own format (within an internal table) for further processing. Hope some of yous may find this useful.
CALL FUNCTION 'TEXT_CONVERT_TEX_TO_SAP'
EXPORTING
i_field_seperator = ','
i_tab_raw_data = lt_raw_data
TABLES
i_tab_converted_data = lt_tab_mydata
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
Cheers,
Sougata.
2009 Oct 29 4:15 PM