05-06-2013 6:54 PM
Hello everyone,
I am currently creating an ABAP report which selects certain back end tables and converts their output to CSV files. All is working but I am having issues with the .CSV files being formatted. I have tried many things & have done extensive research. From my understanding, I need a data separator such as a ',' or ';' . If this is the case could someone shed some light?
Thanks in advance!
🙂
05-06-2013 7:30 PM
Nader,
I don't see anything wrong with your code. Since you have specified filetype as DAT, the output CSV will have data separated by TAB. May be this is why you are seeing data in a cluttered format.
Note that when data is separated by tab you will not see contents of the same fields for all records does not align one below the other correctly.
a sample output for tab delimited o/p will look something like below:
Name age Sex
ABCDEFGH 10 M
XYZ 12 F
ROPTYU 13 F
TGHYUJKIK BNHJKYUI 23 M
Hope this answers your questions.
Thanks,
Vikram.M
05-06-2013 7:30 PM
Nader,
I don't see anything wrong with your code. Since you have specified filetype as DAT, the output CSV will have data separated by TAB. May be this is why you are seeing data in a cluttered format.
Note that when data is separated by tab you will not see contents of the same fields for all records does not align one below the other correctly.
a sample output for tab delimited o/p will look something like below:
Name age Sex
ABCDEFGH 10 M
XYZ 12 F
ROPTYU 13 F
TGHYUJKIK BNHJKYUI 23 M
Hope this answers your questions.
Thanks,
Vikram.M
05-06-2013 8:53 PM
Hello Vikram,
Should I be using another data layout other than tab delimited to properly align the data in the .csv file? I forgot to attach the screen shots of how the data appears. I will include them below:
Any extra tips would be greatly appreciated!
Thank you!
🙂
05-06-2013 9:02 PM
Nader,
I am not sure how the end user is using this file.
But since the file is tab delimited, you can open the file in excel for the below approach to get the formatting corrected.
Select column A.
Menu path Data -> Text to columns
Select delimited. Click next
Select the delimiter as TAB only. Uncheck the rest. Click Next and then finish.
The data will get formatted correctly.
Thanks,
Vikram.M
05-06-2013 8:15 PM
Nader,
To download CSV file with function module GUI_DOWNLOAD, check this Download CSV file
05-27-2013 11:29 AM
Hello Nader,
Refer this code,
* Get data from database
SELECT vbeln posnr UP TO 10 ROWS FROM vbap INTO TABLE itab.
CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'
EXPORTING
i_field_seperator = ';'
TABLES
i_tab_sap_data = itab
CHANGING
i_tab_converted_data = itab1
EXCEPTIONS
conversion_failed = 1
OTHERS = 2.
IF sy-subrc EQ 0.
clear: it_output[],
it_output.
it_output[] = itab1[].
* CONCATENATE s_fhd
* '.csv'
* INTO gd_filename.
*
* CALL FUNCTION 'GUI_DOWNLOAD'
* EXPORTING
* filename = gd_filename
* TABLES
* data_tab = itab1.
filepath = s_file.
OPEN DATASET filepath FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
LOOP AT it_output.
TRANSFER it_output TO filepath.
ENDLOOP.
CLOSE DATASET filepath.
message text-003 TYPE 'S'.
ELSE.
MESSAGE text-001 TYPE 'E'.
ENDIF. "IF sy-subrc EQ 0.
*----------------------------------------------------------------------
* End of main program
*----------------------------------------------------------------------