Skip to Content
author's profile photo Former Member
Former Member

Intern developer - ABAP Report to .CSV file

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!

:-)

REPORT_UI.png (45.7 kB)
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on May 06, 2013 at 06: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

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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

  • Posted on May 06, 2013 at 07:15 PM

    Nader,

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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 27, 2013 at 10: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
    *----------------------------------------------------------------------

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.