Skip to Content

GUI_UPLOAD reads csv as one line.

Hello,

I have a requirement of reading a .csv file, in an ABAP report, that looks like this(dummy values are used for obvious reasons):

Notice that each row is stored in the first column cell.

I am currently using the GUI_UPLOAD function module to do the above operation. It is called as following:

CALL FUNCTION 'GUI_UPLOAD'EXPORTING<br>
 filename = lv_filename<br>
 filetype = 'ASC'TABLES<br>
 data_tab = lt_filedataEXCEPTIONS<br>
 file_open_error = 1<br>
 file_read_error = 2<br>
 no_batch = 3<br>
 gui_refuse_filetransfer = 4<br>
 invalid_type = 5<br>
 no_authority = 6<br>
 unknown_error = 7<br>
 bad_data_format = 8<br>
 header_not_allowed = 9<br>
 separator_not_allowed = 10<br>
 header_too_long = 11<br>
 unknown_dp_error = 12<br>
 access_denied = 13<br>
 dp_out_of_memory = 14<br>
 disk_full = 15<br>
 dp_timeout = 16OTHERS = 17.
 filename = lv_filename
 filetype = 'ASC'TABLES
 data_tab = lt_filedataEXCEPTIONS
 file_open_error = 1
 file_read_error = 2
 no_batch = 3
 gui_refuse_filetransfer = 4
 invalid_type = 5
 no_authority = 6
 unknown_error = 7
 bad_data_format = 8
 header_not_allowed = 9
 separator_not_allowed = 10
 header_too_long = 11
 unknown_dp_error = 12
 access_denied = 13
 dp_out_of_memory = 14
 disk_full = 15
 dp_timeout = 16OTHERS = 17.

I would expect lt_filedata to have 4 rows, each one containing one line from the above .csv file.

However, it contains only one line, consisting of all above lines as a single continuous line, as such:

val1,val2,"val3","val4" # val5,val6,"val7","val8"# val9,"val10","val11"# val12,"val13","","","","val14"

Notice that, in the positions where the line breaks should be, they are replaced by the ‘#’ character.

Any ideas on what could be responsible for this behavior and how to make the function module parse the file correctly and output a table with a row for each of the lines in the .csv file?

Thank you in advance.

abap-issue.png (10.2 kB)
Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Posted on Aug 22 at 01:51 AM

    Run your program in debug, display lt_filedata[1], what hexadecimal value do you see for the character # ?

    I suspect that it's 000A or 0A00 (character known as Line Feed or LF, or even newline).

    It's possible that SAP expects two characters CR/LF (Carriage Return/Line Feed).

    Recreate the CSV file with Notepad application for Windows for instance, press Enter at the end of the line, and save it. Try again.

    If you want to leave the file unchanged, you may split the lines using:

    DATA(one_line) = lt_filedata[ 1 ].
    SPLIT one_line AT cl_abap_char_utilities=>newline INTO TABLE DATA(lines).
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Aug 21 at 03:22 PM

    Hi,

    Looking at your CSV file you have multiple lines but with a different amount of columns. According to the documentation this is not supported. (info available in function module GUI_UPLOAD parameter HAS_FIELD_SEPARATOR)

    This might be a matter of formatting your CSV file properly so that each line contains an equal number of columns.

    Another thing that caught my eye is that your fields are sometimes surrounded by quotes and sometimes they're not. I would suggest to format your CSV file in a uniform way (either all fields are surrounded by quotes or none of them are).

    Best regards,

    Geert-Jan Klaps


    doc.png (54.8 kB)
    doc.png (54.8 kB)
    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.