12-31-2014 11:24 AM
Hi,
Need one help with the below issue.
We are using FM 'GUI_DOWNLOAD' to download CSV file but if we use double quote and comma simultaneously in any text field (for ex. 6"yard ,Machine) , so downloaded file is splitting this field and shifting the text after comma into the next column in the file , so subsequent field are shifted to the next columns.
Do we have any reason for this and suggest if there is any solution to handle this situation.
Regards,
Anup
12-31-2014 11:35 AM
Hi Anup,
You can Use the SAP_CONVERT_TO_CSV_FORMAT Function Module to change the internal data information to csv format,
and then the same data table you download through GUI_DOWNLOAD function module.
Regards.
Praveer.
01-01-2015 10:50 AM
Hi Praveer,
We have already converted internal data fromat into the CSV format and using 'GUI_DOWNLOAD' FM to generate CSV file.
Still we tried with your suggestion but its not working.
Regards,
Anup
01-01-2015 1:12 PM
Hi Anup,
Pass the i_field_seperator = ';' in FM SAP_CONVERT_TO_CSV_FORMAT.
And then check.
Regards.
Praveer
01-01-2015 7:25 AM
hi anup,
since there is a comma in the text it is better you change delimiter to some other character then only it is possible to write correctly to the text file.
01-01-2015 1:42 PM
Hi,
Try this sample program .
It using cl_gui_frontend_services=>gui_download.
The output is tab separator.
In excel:
Regards.
01-01-2015 8:36 PM
hi eitan,
This attached example is giving tab delimited file.
But the requirement is comma delimited csv file.
01-02-2015 5:45 AM
Hi,
You are correct .
I am giving alternative solution so delimiters can be preserved . IMHO it is a good solution .
There is a way to create a CSV if you follows the rules of CSV:
see http://en.wikipedia.org/wiki/Comma-separated_values See the "Basic rules and examples".
regards.
01-02-2015 11:37 AM
hi Eitan,
Your solution solved the problem.
I could be able to generate the file without any issue following the rules mentioned in the site.
------------------------------------------
Sample source is attached for reference
REPORT ZR_CSV_DOWNLOAD.
TYPES: BEGIN OF TY,
MATNR TYPE MARA-MATNR,
WERKS TYPE WERKS,
LIFNR TYPE LIFNR,
REMARKS TYPE C LENGTH 50,
END OF TY.
DATA: WA TYPE TY,
WA1 TYPE TY,
ITAB LIKE STANDARD TABLE OF WA,
ITAB1 LIKE STANDARD TABLE OF WA.
types truxs_t_text_data(4096) type c occurs 0.
data: csv_converted_table type TRUXS_T_TEXT_DATA.
data: tbuffer type table of string .
data: buffer type string.
field-symbols: <fs>.
START-OF-SELECTION.
WA-MATNR = 'mat'.
WA-werks = 'unt'.
WA-lifnr = 'lif'.
WA-remarks = 'REMARKS'.
APPEND WA TO ITAB.
CLEAR WA.
WA-MATNR = 'mat1'.
WA-werks = 'unt1'.
WA-lifnr = 'lif1'.
WA-remarks = 'ITEM 6" yard, machine'.
APPEND WA TO ITAB.
CLEAR WA.
WA-MATNR = 'mat2'.
WA-werks = 'unt2'.
WA-lifnr = 'lif2'.
APPEND WA TO ITAB.
CLEAR WA.
WA-MATNR = 'mat3'.
WA-werks = 'unt3'.
WA-lifnr = 'lif3'.
APPEND WA TO ITAB.
CLEAR WA.
DATA: SEPARATOR TYPE C VALUE ','.
DATA: FNAME type SAPB-SAPPFAD VALUE 'TEST.CSV',
cNAME type SAPB-SAPPFAD VALUE 'C:\TEST.CSV'.
open dataset fname for output IN TEXT MODE ENCODING DEFAULT.
loop at itab into wa.
clear buffer.
do.
assign component sy-index of structure wa to <fs>.
if sy-subrc <> 0.
exit.
endif.
REPLACE ALL OCCURRENCES OF '"' IN <fs> WITH '""'.
SEARCH <fs> for ','.
IF SY-FDPOS NE 0.
CONCATENATE '"' <fs> INTO <fs>.
CONCATENATE <fs> '"' INTO <fs>.
ENDIF.
if sy-index = 1.
buffer = <fs>.
else.
concatenate buffer <fs> into buffer separated by ','.
endif.
enddo.
append buffer to tbuffer.
TRANSFER buffer to fname.
endloop.
CLOSE DATASET fname.
CALL FUNCTION 'ARCHIVFILE_SERVER_TO_CLIENT'
EXPORTING
path = FNAME
TARGETPATH = CNAME
EXCEPTIONS
ERROR_FILE = 1
OTHERS = 2
.