‎2010 Mar 23 11:02 AM
hi!
i've got the following problem:
I have to load lots of data and have to write them by "open dataset" to a csv file.
The problem is, that i don't know how to build the csv lines.
I tried to concatenate them and seperate them by ";" or TAB, but the problem is, that some fields make problems --> after opening the whole transfered file in excel some lines are corrupted (fields are displaced)
Does anyone know how to handle that problem.
I can't use SAP_CONVERT_TO_CSV_FORMAT to the whole internal (too big, each line is created - written - discarded)
regards jacko
‎2010 Mar 23 11:18 AM
Daniel, you've found a basic problem with comma-separated-values. If you have texts, you must enclose them in quotes so that the commas can be treated as part of the text, and not the separator, or you can go through the text fields and strip out the commas, replacing with blank spaces, then make it a comma-delimited file.
I don't immediately recall how I did this, whether it's a single quote or double quote (double, I think)...
So, try setting a constant equal to ". Then for text fields concatentate the quote textstring quote into your output line.
‎2010 Mar 23 11:07 AM
Hi Daniel,
You can try as given below,
let us assume ITAB1 is the table that has all the data, that you need to transfer to a CSV file.
declare a variable - l_string of type string.
1) Open dataset to write a file.
2) Loop at itab into wtab.
3) concatenate wtab-field1 wtab-field2 wtab-field3.....into l_string separated by ','.
4) transfer l_string to filepath.
5) clear: l_string.
6) Endloop for itab.
7) close dataset.
This should do.
Regards,
Chen
Edited by: Chen K V on Mar 23, 2010 12:08 PM
‎2010 Mar 23 11:10 AM
thanks for your answer but thats my problem:
first problem: i haven't got the whole data in itab because of size and performance issues - after writing the line, it is discarded.
when i do:
3) concatenate wtab-field1 wtab-field2 wtab-field3.....into l_string separated by ','.
my problem is, that the lines in my output are corrupted because there are the seperators also in some description-fields ...
‎2010 Mar 23 11:20 AM
If your field separator is also being used in some text, try to use another character as field separator, e.g. @.
When opening in XLS, you can enter that character as field separator.
‎2010 Mar 23 11:18 AM
Daniel, you've found a basic problem with comma-separated-values. If you have texts, you must enclose them in quotes so that the commas can be treated as part of the text, and not the separator, or you can go through the text fields and strip out the commas, replacing with blank spaces, then make it a comma-delimited file.
I don't immediately recall how I did this, whether it's a single quote or double quote (double, I think)...
So, try setting a constant equal to ". Then for text fields concatentate the quote textstring quote into your output line.