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

CSV formatted output

Former Member
0 Likes
2,459

Hi Every one,

I have at present ALV report.In ALV we donot have CSV format option, so my requirement is i need to get the out put file in CSV format.So can any help me on this requirement.

answered

8 REPLIES 8
Read only

Former Member
0 Likes
1,550

Hi Krishna ,

When you are downloading to CSV you can use the FM SAP_CONVERT_TO_CSV_FORMAT or SAP_CONVERT_TO_TXT_FORMAT.

Add a new button in the ALV Mneu which will download the data to CSV format.

Regards,

Arun

Read only

0 Likes
1,550

How can we add a button to ALV .

Read only

mohammed_moqeeth
Active Participant
0 Likes
1,550

Hi,

To download file in CSV format, first convert internal table data into csv format using function module "SAP_CONVERT_TO_TEX_FORMAT" and then use function module "GUI_DOWNLOAD" as shown below

CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'

EXPORTING

i_field_seperator = ','

TABLES

i_tab_sap_data = t_output

CHANGING

i_tab_converted_data = t_output_csv

EXCEPTIONS

conversion_failed = 1

OTHERS = 2.

IF sy-subrc 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

DATA: lv_file TYPE string, lv_sep TYPE c.

lv_file = 'c:\data.csv.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = lv_file

filetype = 'ASC'

write_field_separator = lv_sep

TABLES

data_tab = t_output_csv

EXCEPTIONS

file_write_error = 1

no_batch = 2

gui_refuse_filetransfer = 3

invalid_type = 4.

Regards,

Moqeeth.

Read only

0 Likes
1,550

What should be the types of internal tables t_output and t_output_csv.

Read only

0 Likes
1,550

hi,

t_output <<< Your data any format

t_output_csv declare type truxs_t_text_data

or

you can also try like below:

declare a table like below:

data: begin of t_con occurs 0,

line(255),

end of t_con.

then concatenate all the field values into this line with separator as comma like below:


data: lv_sep value ','.

loop at it_data  <-----your data internal table.

concatenate it_data-field1 it_data-field2...into t_con-line
  separated by lv_sep.

append t_con.

then call the GUI_DOWNLOAD and download the file.

I hope it helps

regards,

Himanshu

Read only

Sandra_Rossi
Active Contributor
0 Likes
1,550

"how to add a button in alv" : please don't abuse, search forum !

"alv does not save as CSV format" : within ALV, when you export data as excel format, it saves a file which is like CSV, but with tabs instead of commas. Provided that the user saves it with the .csv option (like with commas by the way), when the user opens this file later, Excel opens it as if it had commas.

Read only

Former Member
0 Likes
1,550

answered

Read only

0 Likes
1,550

Hi. Could you just give us a feedback, what were the answers to your questions ?