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: 

Download to excel

Former Member
0 Kudos
151

Hi,

I have data in internal table and lets suppose internal table have 10 fields/columns. Now i want to download this internal table to excel.

But the requirement is, let's suppose 5 columns are blank and 5 columns have the data, then only those columns should be dowloaded to excel which has data.

In this example, only 5 columns should be downloaded to excel.

Can any body tell me how to do this.

Thanks

8 REPLIES 8

Former Member
0 Kudos
127

Hi,

Check out the below FM's


Use Function Module:GUI_DOWNLOAD

CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = 'C:TEMPDATA.XLS'
WRITE_FIELD_SEPARATOR = 'X'
tables
data_tab = itab "Internal table


REPORT ZSBK_DOWNLOAD_IT_TO_XL_FILE.

PARAMETERS: p_file LIKE rlgrap-filename DEFAULT 'c:	mp	est.xls'.

DATA: t100_Lines TYPE STANDARD TABLE OF t001 WITH DEFAULT KEY.

SELECT * FROM t001 INTO TABLE t100_Lines.

CALL FUNCTION 'SAP_CONVERT_TO_XLS_FORMAT'

EXPORTING
i_filename = p_file
TABLES
i_tab_sap_data = t100_Lines.


you can use the FM 'EXCEL_OLE_STANDARD_DAT ' for this purpose.

this FM 'EXCEL_OLE_STANDARD_DAT' can be used to start Excel with a new sheet and transfer data from an internal table to the sheet.

Here are some of the parameters:

file_name: Name and path of the Excel worksheet file e.g. ‘C:TEMPZTEST’

data_tab: Name of the internal table that should be uploaded to Exvcel

fieldnames: Internal tabel with column headers

How to build the field names table:

data: begin of i_fieldnames occurs 20,

field(60), end of i_fieldnames. 
i_fieldnames-field = ‘This is column 1’. append i_fieldnames-field.
i_fieldnames-field = ‘This is column 2’. append i_fieldnames-field.

Regards,

Chandru

Former Member
0 Kudos
127

HI,

U can use this logic...

Loop at it_excel into is_excel.

if is_excel-field is not initial.

append is_excel to it_excel1.

endif.

endloop.

Use GUI_DOWNLOAD using it_excel1.

Regards...

Former Member
0 Kudos
127

there is no such FM which will automatically detect the empty column s for internal table.

oyu may have to think to do it programatically.

fill the internal table at runtime with those columns having the values and pass to any excel converting function module.

0 Kudos
127

Ok, i have this data in ALV and i have created download to exl button on ALV. Suppose there are total 10 columns but user has selected a layout of 5 columns, now i want that only these five columns will be downloaded. Is it possible..?

0 Kudos
127

I am not sure if i am going correct but you can try this.

Add your own excel button to download.

in user command handle the down laod to excel event.

Try to access the existing layout using varients function module, and access current layout.

then process further.

0 Kudos
127

Hi,

You can use FM List_Download

Regards,

Waseem

Former Member
0 Kudos
127

Hi

Yes you can do this.

Through selection screen get the colums for which the user wants to see the output.

say output1 contains the column number on the ALV for Field 1

if not output1 is initial.

Build the Field Catalogue for the Field1.

Move Field1 into an internal table itab1.

endif.

loop at itab2 (the internal table with values).

loop at itab1.

assign component itab1-field to <FS> casting type c.

endloop.

endloop.

This will resolve your issue.

0 Kudos
127

Hi,

I only want to download the fields which are in the selected layout.

I already have the information which fields are parts of current layout.

How to proceed, pls help