cancel
Showing results for 
Search instead for 
Did you mean: 

Download to Excel with Column Headings.

Former Member
0 Kudos

Hi All,

I have a very small issue.I want to download the Data from an internal table to an Excel Sheet Along with the Column heading of the corresponding Field...

I tried with ws_excel and gui_download... not reached to any conclusion,,,I cant go for OLE technique as i have huge amount of data in my internal table.

If anyone have faced the same problem ...please suggest something.

Thanks in advance,

Mayank.

Accepted Solutions (0)

Answers (4)

Answers (4)

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

Once I also faced the same problem.It was solved by the below coding.In my coding i_download is the internal table with two fields werks and matnr .w_download is its workarea.

PARAMETERS p_file LIKE rlgrap-filename.

"File name

  • Local Variable declaration

DATA lv_file TYPE string.

lv_file = p_file.

PERFORM f1710_populate_heading.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = lv_file

filetype = 'ASC'

write_field_separator = 'X'

TABLES

data_tab = i_download

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 i000 WITH text-005. "File downloded successfully

ELSE.

CASE sy-subrc.

WHEN 1.

MESSAGE i000 WITH text-014.

.....

WHEN 21.

MESSAGE i000 WITH text-071.

ENDCASE.

ENDIF.

ENDFORM. " f1500_download_data

*&----


*& Form f1710_populate_heading

*&----


  • Populate header records

*----


FORM f1710_populate_heading.

CLEAR w_download.

  • Design the text element to handle maximum length of

  • the output

w_download-werks = text-001.

w_download-matnr = text-002.

INSERT w_download INTO i_download INDEX 1.

ENDFORM. " f1710_populate_heading

Hope this is clear.

If your problem is solved,could you please reward useful answers and close the thread.

Rgds,

J.Jayanthi

athavanraja
Active Contributor
0 Kudos

alternative:

first download the header alone using gui_download to file abc.xls

then download the content using gui_download with parameter append eq 'X' to the same file (abc.xls).

Regards

Raja

Former Member
0 Kudos

Hi Har Mayank Sahai,

you can use the XXL_SIMPLE_API function.

With this function you can specified only one header.

The import parameters are all optional.

You can pass the ONLINE_TEXT and PRINT_TEXT table empty

in the DATA table pass yuor internal table and in the last one table COL_TEXT you pass the header.

I hope this help you

andreas_mann3
Active Contributor
0 Kudos

Hi,

here's a poss. solution for csv-file.

1) create fieldinfo with name of your itab-fields

with RFC_GET_NAMETAB or LVC_FIELDCATALOG_MERGE

2) before filling your output_tab with data:

loop at fieldinfo.
 concatenate header fieldinfo-name ';' into header.
endloop.
append header to output_tab.

regards Andreas

Former Member
0 Kudos

Hi Mayank,

I had once this requirement, and the only way to achieve it was to populate an internal table with the header in one row and the data in the following rows, and then download this <i>itab</i> via 'GUI_DOWNLOAD' as text separated by tabs.

I hope it helps. BR,

Alvaro