Application Development 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: 

Intern developer - ABAP Report to .CSV file

Former Member
0 Kudos

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!

🙂

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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

5 REPLIES 5

Former Member
0 Kudos

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

0 Kudos

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!

🙂

0 Kudos

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

TuncayKaraca
Active Contributor
0 Kudos

Nader,

To download CSV file with function module GUI_DOWNLOAD, check this Download CSV file

Former Member
0 Kudos

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
*----------------------------------------------------------------------