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

problem with .csv file

Former Member
0 Likes
1,918

Hi,

I am downloading the contents of my internal table into csv file by separating the contents with a ',' (comma).

But, the problem is that if the data already has a comma, then the system treats it as a separator and causes a problem.

Please let me know how to avoid this.

Regards.

7 REPLIES 7
Read only

Former Member
0 Likes
1,402

Hi David,

If it is a .csv file then we cannot have the , (comma) in between the data as it will be always treated as a separator.

Read only

Former Member
0 Likes
1,402

Hi David,

U can achieve it in multiple steps. Firstly u need to have a new itab with a string typed variable like this

Step: 1

DATA: BEGIN OF itab OCCURS 0,

document TYPE string,

END OF itab.

Step: 2

move ur comma seperated data into this itab through a loop and for the field which u feel has already a comma in it

write an if statement for it and move ur data in which u already have a comma to the itab without comma seperation.

Step: 3

Download this new itab as ur .csv file

I hope it will work for u

Cheers

Read only

Former Member
0 Likes
1,402

Hi,

Isn't there any way to handle a character in the data which is the same as the separator used while downloading data to a file?

Regards.

Read only

0 Likes
1,402

Hello,

I never use delimiters in text files I always use fixed width.

I know this takes 10 minutes longer to program in the subsystem because you need to define the structure there and is a little bit less flexible but it always works.

Now you have probably already lost more time in finding a work around for the delimiter that is also used in your actual data fields.

Solution -> use fixed width alphanumeric text files.

Wim

Read only

0 Likes
1,402

Hi,

My user insists on .csv file.

Please let me know if there is any solution.

Regards.

Read only

0 Likes
1,402

Hi David,

- you may remove all commas or replace with another character

- you may enclose the fields with comma in quotes, like "field, with, comma", like this

field-symbols:
  <rec> type any,
  <fld> type any.
loop at itab assigning <rec>.
  do.
    assign component sy-index of structure <rec> to <fld>.
    if not sy-subrc = 0.
      exit."do loop
    endif.
    if <fld> ca ','.
      concatenate '"' <fld> '"' into <fld>. 
    endif.
  enddo.
endloop.

Excel will ignore the field delimiter , if it is enclosed in quotes.

Regards,

Clemens

Read only

Sandra_Rossi
Active Contributor
0 Likes
1,402

David, I have compiled rules to make "universal" CSV files (so that anybody in the world can open them using Excel 2003 and 2007) in this [wiki|http://wiki.sdn.sap.com/wiki/display/ABAP/Excelfiles-CSVformat] (hope it's clear enough) where it shows the solution mentioned by Clemens.

It also shows that comma, as field separator, is not universally recognized.