ABAP log

August 15, 2007

Reading a comma delimited file in ABAP (aka CSV file).

Filed under: ABAP, SAP — abaplog @ 8:51 pm

Download functions of SAP allow you to write data into a file on the presentation server in many different formats. However, reading files (uploading) is very limited. A common question asked on forums is how to upload a comma delimited file. This format, also known as CSV, is used by many programs including MS Excel. For example, you may want to save an Excel spreadsheet into CSV file and then upload it into SAP. Unfortunately, there is no function that can help you.

Few years ago I had to extend an ABAP program with a capability to read CSV files. I wrote a very simple parser that can read files with any delimiter, not only comma. (It actually has to be a printable character, control characters will most likely not work). The delimiter can be set as a constant in the body of the parser form. It can be easily changed to be a form parameter. The code of the parser can be downloaded here. NOTE: use “view source” function of your browser – there are field symbols that are interpreted as HTML tags (I’ll have to fix that…)

If you find any problems that have to be fixed, please send your suggestions (the best would be some working code), as a comment on this article.

Advertisements

4 Comments »

  1. Hi

    I have a problem in uploading CSV file into a internal table.
    Actualy , one of my field in CSV file is numeric but i want that
    in a form ’04’ But when i put 04 , it automatically delete leading
    zero. How to get this form and i want the file in CSV format only.

    Comment by Virender — May 5, 2008 @ 5:26 pm

  2. Your target field has to be character type. Or type N, and then you can move it into a character type field that will have the leading zero.

    Comment by abaplog — May 18, 2008 @ 8:08 pm

  3. Hello,

    Why is field symbols mentioned.

    What is the logic required for where ?????????? for this code. Please see my question marks.
    assign component m_column of structure po_ssheet to ?????????? .
    if sy-subrc = 0.
    ??????? = m_cell.

    Comment by dale haverkamp — December 22, 2008 @ 7:07 pm

    • Field symbols are used because we do not know how many fields are in the target structure.

      Comment by abaplog — January 7, 2009 @ 7:11 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: