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: 

Adding Header details in Excel sheet

pintoo_d
Participant
0 Kudos

I was able to download data from internal table to Excel File using GUI_DOWNLOAD.

However i would like to add first line of excel sheet with Field name Details.

for eg if below is excel sheet, it should display Field name and under that all field values.

Customer Number Country City

0000000001 India Hy

0000000002 US NJ

0000000003 Uk NS

etc..

How do i go about it ?

I tried searching in SDN, but no luck. help me on this.

Thanks

1 ACCEPTED SOLUTION

kesavadas_thekkillath
Active Contributor
0 Kudos

data:begin of it_heading occurs 0,

text(20) type c,

end of excel_heading.

it_heading-text = 'Customer Number'.

append it_heading.

it_heading-text = 'Country'.

append it_heading.

it_heading-text = 'City'.

append it_heading.

call function 'GUI_DOWNLOAD'

exporting

filename = p_pfile

filetype = 'DAT'

write_field_separator = '#'

header = '00'

trunc_trailing_blanks = 'X'

show_transfer_status = 'X'

tables

data_tab = p_it_final[]

fieldnames = it_heading[]. <----


if sy-subrc <> 0.

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

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

endif.

4 REPLIES 4

Former Member
0 Kudos

Hi,

What's the data type of fields in your internal table? Is it char or string? If yes just try the following way.

You define your internal table which will be download as 3 fields type string. And first append one

header record of three fields: 'Customer' 'Number' 'Country City' to the internal table, then append data

record to the internal table. After that call 'GUI_DOWNLOAD' to download the table to excel.

Former Member
0 Kudos

hi,

use OLE rather than gui_download.

many examples are present how to download the data in excel sheet with column headings search in sdn with the keyword OLE you will get the answer.

For your assistance check the below link

https://www.sdn.sap.com/irj/scn/advancedsearch?query=ole+heading&cat=sdn_all

Cheers!!

VEnk@

kesavadas_thekkillath
Active Contributor
0 Kudos

data:begin of it_heading occurs 0,

text(20) type c,

end of excel_heading.

it_heading-text = 'Customer Number'.

append it_heading.

it_heading-text = 'Country'.

append it_heading.

it_heading-text = 'City'.

append it_heading.

call function 'GUI_DOWNLOAD'

exporting

filename = p_pfile

filetype = 'DAT'

write_field_separator = '#'

header = '00'

trunc_trailing_blanks = 'X'

show_transfer_status = 'X'

tables

data_tab = p_it_final[]

fieldnames = it_heading[]. <----


if sy-subrc <> 0.

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

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

endif.

pintoo_d
Participant
0 Kudos

Thank you everyone to help me out.

Points already given