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

Comma Separated File

Former Member
0 Likes
4,722

Hello Experts,

I am working on Interface, where i have the data in Internal Table. Now I am required to transfer the internal table data into Comma separated file with extension '.csv' .

I used the FM 'SAP_CONVERT_TO_CSV_FORMAT' and provided the de-limiter as ',' . When i downloaded the file in '.xls' format , all fields in row appeared in single cell of excel sheet.

example : in 1 cell A1 the data was : abc,123,thr,456

But the needed thing is 'abc' should appear in A1 cell , '123' should appear in B1 column etc...

Please help me to attain the solution.

Thanks in advance.

Regards.

9 REPLIES 9
Read only

Former Member
0 Likes
1,932

Hi shital,

You need the to format the downloaded excel sheet by using conditional formatting and split the columns where there is a comma into different cells.

Thanks,

Sudheer

Read only

Former Member
0 Likes
1,932

You can concatenate all your field into a string, separated by ',' and then save the file.

otherwise, you can save file into a csv where field are separated by tabulator, using the following:

call function 'GUI_DOWNLOAD'

exporting

filename = i_filename

filetype = 'ASC'

write_field_separator = 'X'

dat_mode = 'X'

tables

data_tab = i_data

fieldnames = i_header

exceptions

file_write_error = 1

no_batch = 2

gui_refuse_filetransfer = 3

invalid_type = 4

no_authority = 5

unknown_error = 6

header_not_allowed = 7

separator_not_allowed = 8

filesize_not_allowed = 9

header_too_long = 10

dp_error_create = 11

dp_error_send = 12

dp_error_write = 13

unknown_dp_error = 14

access_denied = 15

dp_out_of_memory = 16

disk_full = 17

dp_timeout = 18

file_not_found = 19

dataprovider_exception = 20

control_flush_error = 21

others = 22.

if sy-subrc <> 0.

message id sy-msgid type sy-msgty number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

endif.

Regards

Andrea

Read only

0 Likes
1,932

Hello,

Thanks for your answers.

But I need to save the comma separated file in application server.

Using Open data set Statements i am able to transfer Internal Table data in to normal .txt file in application server.

I know to transfer internal table data in to a file and make it tab separated file .

My question is how do i transfer internal table data in to a file and make it comma separated file to be saved in application server.

Then we use Transaction CG3Y to download the file saved in application server to our desktop (Presentation server) in

excel format. During this time the comma separated file is not appearing proper rather all string in one cell of Excel.

I dont have to use 'GUI DOWNLOAD' in abap program to download the file.

Thanks in advance.

Read only

0 Likes
1,932

Data: l_string type string.

Loop at itab.

clear l_string

concatenate itab-field1 itab-field2 .... itab-fieldN

into l_string

separated by ','.

endloop.

Read only

0 Likes
1,932

Shital,

I too had faced the same problem long time back. The requirement was something like:

A file from application server was picked and was comma separated

 data :c_delim       TYPE c VALUE cl_abap_char_utilities=>horizontal_tab.

OPEN DATASET p_appli FOR INPUT IN TEXT MODE ENCODING DEFAULT.
  IF sy-subrc <> 0.
    WRITE: 'Error opening input file :', p_appli.
    STOP.
  ENDIF.
  IF sy-subrc NE 0.
  ELSE.
    DO.
      READ DATASET p_appli INTO wa_upload-data.
      IF sy-subrc NE 0.
        EXIT.
      ELSE.
        SPLIT wa_upload-data AT c_delim INTO
                        wa_it_data-ktokd
                        wa_it_data-kunnr
                        wa_it_data-name1
                        wa_it_data-vkorg
                        wa_it_data-vtweg
                        wa_it_data-spart
                        wa_it_data-name2
                        wa_it_data-country.
        APPEND wa_it_data TO it_data.
      ENDIF.
    ENDDO.
  ENDIF.
  CLOSE DATASET p_appli.

  IF p_test IS INITIAL.
    DELETE DATASET p_appli.
  ENDIF.

  DESCRIBE TABLE it_data LINES no_rec.
  IF no_rec = 0.
    WRITE: 'No data in the inbound file:', p_appli.
    STOP.
  ENDIF

Read only

Former Member
0 Likes
1,932

Hi Sheetal,

As I told you earlier, you need to format your downloaded comma seperated file.

For this you need follow the below steps.

first place your excel file on desktop.

then in the excel file select the column in which you have data and

in menu, go to Data -> Text to Columns.

there you select the radio button 'Delimited' and click on next.

there you need to select the check box 'Comma' and click on next and then you click on finish.

you have to do this for the first time when download the file and for each file.

Hope this will solve your problem.

Thanks,

Sudheer

Read only

0 Likes
1,932

Hi,

The Data of Internasl table is taking the correct format.. (separated by comma)... While downloading the Excel file to Local system Just put file extension as '.CSV' instead '.XLS' ...it should work.

Thanks,

Preyansh

Read only

Former Member
0 Likes
1,932

Hi,

Try this.

 
   CALL METHOD cl_gui_frontend_services=>gui_download
      EXPORTING
        filename                  = v_filename2
        write_field_separator     = 'X'
      CHANGING
        data_tab                  = it_string[].

Regards,

Manica

Read only

MrWhan
Participant
0 Likes
1,932

Even though that function appears to allow you to send a ',' to delimit the file, there is a line in that function that makes the ';' a constant and uses that as the delimiter no matter what. I have gotten around this by:


  CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'
    TABLES
      i_tab_sap_data       = whattable
    CHANGING
      i_tab_converted_data = i_tab_converted_data
    EXCEPTIONS
      conversion_failed    = 1
      OTHERS               = 2.

  LOOP AT i_tab_converted_data INTO i_tab_converted_data_rec.
    REPLACE ALL OCCURRENCES OF ';' IN i_tab_converted_data_rec WITH ','.
    APPEND i_tab_converted_data_rec TO i_tab_all_converted_data.
  ENDLOOP.

I download the file as '.dat' or '.csv' and then Excel will open it.