<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Reading a CSV file in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/reading-a-csv-file/m-p/1832101#M354514</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;&lt;CODE&gt;type-pools: kcde.
parameters: p_file like rlgrap-filename default 'C:STOCK.csv'.
data: it_data type kcde_intern ,
       wa_data type line of kcde_intern.
data : begin of it_data1 occurs 0,
          field1(10),
          field2(10),
          field3(10),
          field4(10),
       end of it_data1.

call function 'KCD_CSV_FILE_TO_INTERN_CONVERT'
exporting
i_filename = p_file
i_separator = ','
tables
e_intern = it_data
exceptions
upload_csv = 1
upload_filetype = 2
others = 3
.
if sy-subrc &amp;lt;&amp;gt; 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.

loop at it_data into wa_data.

  case wa_data-col.
    when '0001'.
      it_data1-field1 = wa_data-value.
    when '0002'.
      it_data1-field2 = wa_data-value.
    when '0003'.
     it_data1-field3 = wa_data-value.
    when '0004'.
     it_data1-field4 = wa_data-value.
  endcase.
at end of row.
  append it_data1  .
  clear it_data1.
endat.
endloop.

loop at it_data1.
  write :/ it_data1-field1, it_data1-field2,it_data1-field3,it_data1-field4.
endloop.&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 31 Jan 2007 11:51:06 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-01-31T11:51:06Z</dc:date>
    <item>
      <title>Reading a CSV file</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reading-a-csv-file/m-p/1832099#M354512</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi guys,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; can some one help how to read a CSV file especially reading columns in CSV file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If possible please help me by sending some sample code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thank you and waiting for your reply&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; Pavan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Jan 2007 11:41:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reading-a-csv-file/m-p/1832099#M354512</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-01-31T11:41:44Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a CSV file</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reading-a-csv-file/m-p/1832100#M354513</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Pavan,&lt;/P&gt;&lt;P&gt;   One method is to use the fm GUI_UPLOAD to upload the data along with the commas and then use split statement to get the actual columns.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data: begin of it_data occurs 0,&lt;/P&gt;&lt;P&gt;           data(1000),&lt;/P&gt;&lt;P&gt;        end of it_data.&lt;/P&gt;&lt;P&gt;data: begin of itab occurs 0,&lt;/P&gt;&lt;P&gt;           field1....&lt;/P&gt;&lt;P&gt;           field2.......&lt;/P&gt;&lt;P&gt;           field3........&lt;/P&gt;&lt;P&gt;         end of itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CALL FUNCTION 'GUI_UPLOAD'&lt;/P&gt;&lt;P&gt;  EXPORTING&lt;/P&gt;&lt;P&gt;   filename                      = l_filename&lt;/P&gt;&lt;P&gt;  TABLES&lt;/P&gt;&lt;P&gt;   data_tab                      = it_data&lt;/P&gt;&lt;P&gt; EXCEPTIONS&lt;/P&gt;&lt;P&gt;   file_open_error               = 1&lt;/P&gt;&lt;P&gt;   file_read_error               = 2&lt;/P&gt;&lt;P&gt;   no_batch                      = 3&lt;/P&gt;&lt;P&gt;   gui_refuse_filetransfer       = 4&lt;/P&gt;&lt;P&gt;   invalid_type                  = 5&lt;/P&gt;&lt;P&gt;   no_authority                  = 6&lt;/P&gt;&lt;P&gt;   unknown_error                 = 7&lt;/P&gt;&lt;P&gt;   bad_data_format               = 8&lt;/P&gt;&lt;P&gt;   header_not_allowed            = 9&lt;/P&gt;&lt;P&gt;   separator_not_allowed         = 10&lt;/P&gt;&lt;P&gt;   header_too_long               = 11&lt;/P&gt;&lt;P&gt;   unknown_dp_error              = 12&lt;/P&gt;&lt;P&gt;   access_denied                 = 13&lt;/P&gt;&lt;P&gt;   dp_out_of_memory              = 14&lt;/P&gt;&lt;P&gt;   disk_full                     = 15&lt;/P&gt;&lt;P&gt;   dp_timeout                    = 16&lt;/P&gt;&lt;P&gt;   OTHERS                        = 17.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loop at it_data.&lt;/P&gt;&lt;P&gt;split it_data-data at ',' into itab-field1 &lt;/P&gt;&lt;P&gt;                                      itab-field2&lt;/P&gt;&lt;P&gt;                                      itab-field3&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;append itab.&lt;/P&gt;&lt;P&gt;clear itab.&lt;/P&gt;&lt;P&gt;endloop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Ravi&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Jan 2007 11:46:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reading-a-csv-file/m-p/1832100#M354513</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-01-31T11:46:25Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a CSV file</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reading-a-csv-file/m-p/1832101#M354514</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;&lt;CODE&gt;type-pools: kcde.
parameters: p_file like rlgrap-filename default 'C:STOCK.csv'.
data: it_data type kcde_intern ,
       wa_data type line of kcde_intern.
data : begin of it_data1 occurs 0,
          field1(10),
          field2(10),
          field3(10),
          field4(10),
       end of it_data1.

call function 'KCD_CSV_FILE_TO_INTERN_CONVERT'
exporting
i_filename = p_file
i_separator = ','
tables
e_intern = it_data
exceptions
upload_csv = 1
upload_filetype = 2
others = 3
.
if sy-subrc &amp;lt;&amp;gt; 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.

loop at it_data into wa_data.

  case wa_data-col.
    when '0001'.
      it_data1-field1 = wa_data-value.
    when '0002'.
      it_data1-field2 = wa_data-value.
    when '0003'.
     it_data1-field3 = wa_data-value.
    when '0004'.
     it_data1-field4 = wa_data-value.
  endcase.
at end of row.
  append it_data1  .
  clear it_data1.
endat.
endloop.

loop at it_data1.
  write :/ it_data1-field1, it_data1-field2,it_data1-field3,it_data1-field4.
endloop.&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Jan 2007 11:51:06 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reading-a-csv-file/m-p/1832101#M354514</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-01-31T11:51:06Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a CSV file</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reading-a-csv-file/m-p/1832102#M354515</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the file is CSV file then declare a internal table like this:&lt;/P&gt;&lt;P&gt;DATA: begin of itab occurs 0,&lt;/P&gt;&lt;P&gt;             field(255) TYPE c,&lt;/P&gt;&lt;P&gt;           end if itab.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Upload the data into internal table using GUI_UPLOAD if file is on Presentation server or Read it using Open Dataset. And then loop the table &amp;amp; split the data into other work area &amp;amp; append it to ohter table in which you have specified particular fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;E.g.:&lt;/P&gt;&lt;P&gt;DATA: v_string type string.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;  LOOP AT it_itab INTO v_string.&lt;/P&gt;&lt;P&gt;    SPLIT v_string&lt;/P&gt;&lt;P&gt;    AT    ','&lt;/P&gt;&lt;P&gt;    INTO  x_struct-v2  x_struct-v3  x_struct-v4&lt;/P&gt;&lt;P&gt;          x_struct-v5  x_struct-v6  x_struct-v7&lt;/P&gt;&lt;P&gt;          x_struct-v8  x_struct-v9  x_struct-v10&lt;/P&gt;&lt;P&gt;          x_struct-v11 x_struct-v12 x_struct-v13&lt;/P&gt;&lt;P&gt;          x_struct-v14 x_struct-v15.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Append x_struct to it_struct.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reward points if helpful answer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ashvender&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Jan 2007 11:52:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reading-a-csv-file/m-p/1832102#M354515</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-01-31T11:52:36Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a CSV file</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reading-a-csv-file/m-p/1832103#M354516</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is a sample code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; call function 'GUI_UPLOAD'&lt;/P&gt;&lt;P&gt;   exporting&lt;/P&gt;&lt;P&gt;     filename                = chafile&lt;/P&gt;&lt;P&gt;     filetype                = 'ASC'&lt;/P&gt;&lt;P&gt;     has_field_separator     = 'X'&lt;/P&gt;&lt;P&gt;   tables&lt;/P&gt;&lt;P&gt;     data_tab                = it_data&lt;/P&gt;&lt;P&gt;   exceptions&lt;/P&gt;&lt;P&gt;     file_open_error         = 1&lt;/P&gt;&lt;P&gt;     file_read_error         = 2&lt;/P&gt;&lt;P&gt;     no_batch                = 3&lt;/P&gt;&lt;P&gt;     gui_refuse_filetransfer = 4&lt;/P&gt;&lt;P&gt;     invalid_type            = 5&lt;/P&gt;&lt;P&gt;     no_authority            = 6&lt;/P&gt;&lt;P&gt;     unknown_error           = 7&lt;/P&gt;&lt;P&gt;     bad_data_format         = 8&lt;/P&gt;&lt;P&gt;     header_not_allowed      = 9&lt;/P&gt;&lt;P&gt;     separator_not_allowed   = 10&lt;/P&gt;&lt;P&gt;     header_too_long         = 11&lt;/P&gt;&lt;P&gt;     unknown_dp_error        = 12&lt;/P&gt;&lt;P&gt;     access_denied           = 13&lt;/P&gt;&lt;P&gt;     dp_out_of_memory        = 14&lt;/P&gt;&lt;P&gt;     disk_full               = 15&lt;/P&gt;&lt;P&gt;     dp_timeout              = 16&lt;/P&gt;&lt;P&gt;     others                  = 17.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Jan 2007 11:52:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reading-a-csv-file/m-p/1832103#M354516</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-01-31T11:52:39Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a CSV file</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reading-a-csv-file/m-p/1832104#M354517</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI,&lt;/P&gt;&lt;P&gt;Write the code as normal as a upload program do for a text file,  calli the GUI_UPLOAD function module like below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CALL FUNCTION 'GUI_UPLOAD'&lt;/P&gt;&lt;P&gt;  EXPORTING&lt;/P&gt;&lt;P&gt;    FILENAME                      = 'C:\test.csv'&lt;/P&gt;&lt;P&gt;   FILETYPE                      = 'ASC'&lt;/P&gt;&lt;P&gt;  TABLES&lt;/P&gt;&lt;P&gt;    DATA_TAB                      = itab&lt;/P&gt;&lt;P&gt; EXCEPTIONS&lt;/P&gt;&lt;P&gt;   FILE_OPEN_ERROR               = 1&lt;/P&gt;&lt;P&gt;   FILE_READ_ERROR               = 2&lt;/P&gt;&lt;P&gt;   NO_BATCH                      = 3&lt;/P&gt;&lt;P&gt;   GUI_REFUSE_FILETRANSFER       = 4&lt;/P&gt;&lt;P&gt;   INVALID_TYPE                  = 5&lt;/P&gt;&lt;P&gt;   NO_AUTHORITY                  = 6&lt;/P&gt;&lt;P&gt;   UNKNOWN_ERROR                 = 7&lt;/P&gt;&lt;P&gt;   BAD_DATA_FORMAT               = 8&lt;/P&gt;&lt;P&gt;   HEADER_NOT_ALLOWED            = 9&lt;/P&gt;&lt;P&gt;   SEPARATOR_NOT_ALLOWED         = 10&lt;/P&gt;&lt;P&gt;   HEADER_TOO_LONG               = 11&lt;/P&gt;&lt;P&gt;   UNKNOWN_DP_ERROR              = 12&lt;/P&gt;&lt;P&gt;   ACCESS_DENIED                 = 13&lt;/P&gt;&lt;P&gt;   DP_OUT_OF_MEMORY              = 14&lt;/P&gt;&lt;P&gt;   DISK_FULL                     = 15&lt;/P&gt;&lt;P&gt;   DP_TIMEOUT                    = 16&lt;/P&gt;&lt;P&gt;   OTHERS                        = 17.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt; Sudheer&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Jan 2007 11:53:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reading-a-csv-file/m-p/1832104#M354517</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-01-31T11:53:44Z</dc:date>
    </item>
    <item>
      <title>Re: Reading a CSV file</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/reading-a-csv-file/m-p/1832105#M354518</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thanks very much chandrasekhar, but i still got some doubts regarding this -&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;what is the significance of funcion module &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;call function 'KCD_CSV_FILE_TO_INTERN_CONVERT'.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and i tried using gui_upload but problem is i am using split command since values in CSV are separated by comma but since numeric fields  are this way 42,000 its splitting 42 and 000 and putting them in separate fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but i think this funcion module will resolve my problem can you please give bit more detail on this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thank you very much and waiting for your reply.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;      pavan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Jan 2007 12:28:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/reading-a-csv-file/m-p/1832105#M354518</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-01-31T12:28:23Z</dc:date>
    </item>
  </channel>
</rss>

