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

ABAP - Creating .CSV file with OPEN DATASET (table fields separated per column in MS Excel)

Former Member
0 Likes
8,184

Hi experts,

My requirement is to create .csv file which when opened in excel, the fields in the table are aligned in each cell (e.g. A, B. C.), and when opened in notepad, the fields are delimited by ';'. So far I was successful in notepad; the excel part is unsuccessful. Need your opinion, thanks in advance, here is my code:

CONCATENATE c_fexfolder v_l_date '.csv' INTO fpath.



OPEN DATASET fpath FOR OUTPUT IN TEXT MODE ENCODING UTF-8.

IF sy-subrc NE 0.

  MESSAGE 'ERROR CREATING FILE' TYPE 'E'.

ENDIF.



LOOP AT gt_tab.

*CLEAR v_l_str.

        wa_l_tab-markt = gt_tab-markt.

        wa_l_tab-brand  = gt_tab-brand.

        wa_l_tab-matkl  = gt_tab-matkl.

        wa_l_tab-matnr  = gt_tab-matnr.

        wa_l_tab-normt  = gt_tab-normt.

        wa_l_tab-maktx  = gt_tab-maktx.

        wa_l_tab-stock  = gt_tab-stock.

        wa_l_tab-stpal  = gt_tab-stpal.

        wa_l_tab-netpr  = gt_tab-netpr.

        wa_l_tab-indat  = gt_tab-indat.

        wa_l_tab-oudat  = gt_tab-oudat.

        wa_l_tab-destr  = gt_tab-destr.

        wa_l_tab-costs  = gt_tab-costs.

        wa_l_tab-prdha  = gt_tab-prdha.

        wa_l_tab-meins  = gt_tab-meins.

        wa_l_tab-daterun = v_l_date.



        CONCATENATE

        wa_l_tab-markt

        wa_l_tab-brand

        wa_l_tab-matkl

        wa_l_tab-matnr

        wa_l_tab-normt

        wa_l_tab-maktx

        wa_l_tab-stock

        wa_l_tab-stpal

        wa_l_tab-netpr

        wa_l_tab-indat

        wa_l_tab-oudat

        wa_l_tab-destr

        wa_l_tab-costs

        wa_l_tab-prdha

        wa_l_tab-meins

        wa_l_tab-daterun

        v_l_date INTO v_l_str SEPARATED BY ';'.



        TRANSFER v_l_str TO fpath.

ENDLOOP.



CLOSE DATASET fpath.

1 ACCEPTED SOLUTION
Read only

hemanth_kumar21
Contributor
0 Likes
4,370

After downloading into Notepad file. Open the same file With Excel.

Then click on Data -> Text to columns (as show below)

3 REPLIES 3
Read only

hemanth_kumar21
Contributor
0 Likes
4,371

After downloading into Notepad file. Open the same file With Excel.

Then click on Data -> Text to columns (as show below)

Read only

Former Member
0 Likes
4,370

Hi Jack,

as the file looks correct in notepad, this is no file-export-ABAP-problem but an file-import issue with Excel. To make Excel use the correct separator you could try the following:

  • set the correct delimiter for your region in Windows Control Panel -> RegionalSettings->ListSeparator  
    or
  • add an "sep=;" as first line to your file. Double-clicking an .csv starting with this tag will cause excel to override the standard regional settings

At least one of theese should work for you.

Regards,

markus

Read only

rosenberg_eitan
Active Contributor
0 Likes
4,370

Hi,

Just create a file following the rules of CSV http://en.wikipedia.org/wiki/Comma-separated_values

Look at the "Basic rules and examples"

   

Regards.