Application Development and Automation 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: 
Read only

GUI_UPLOAD reads csv as one line.

0 Likes
3,721

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.

4 REPLIES 4
Read only

geert-janklaps
SAP Mentor
SAP Mentor
0 Likes
2,938

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

Read only

2,938

Thanks a lot for Your help. It was really fruitful.

Best regards,

Elena

Read only

Sandra_Rossi
Active Contributor
2,938

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).
Read only

0 Likes
2,938

Thanks a lot for Your help. It was really fruitful.

Best regards,

Elena