Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to upload a CSV in a internal table of own type ?

Former Member
0 Kudos
10,362

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!

3 REPLIES 3

venkat_o
Active Contributor
0 Kudos
1,695

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.

REPORT 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.
Thanks Venkat.O

Sougata
Active Contributor
0 Kudos
1,695

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.

Former Member
0 Kudos
1,695

Thank you, it works fine.