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: 

How to add a header line to excel sheet?

Former Member
0 Kudos
3,707

Hi Guru's

I have download the scheduling agreement report in a excel sheet, I want to know how to add the header line to that excel sheet.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
684

hi,

please refer this link

TYPES: BEGIN OF ty_head,

h(10) TYPE c,

END OF ty_head.

DATA: it_head TYPE TABLE OF ty_head WITH HEADER LINE.

it_head-h = 'Field1'.

APPEND it_head.

it_head-h = 'Field2'.

APPEND it_head.

it_head-h = 'Field3'.

APPEND it_head.

it_head-h = 'Field4'.

APPEND it_head.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = p_file

filetype = 'ASC'

write_field_separator = 'X'

header = '00'

TABLES

data_tab = it_tab

fieldnames = it_head[]

EXCEPTIONS

OTHERS = 1.

https://www.sdn.sap.com/irj/scn/wiki?path=/display/snippets/download%252bdata%252binto%252bexcel%252...

thanks

10 REPLIES 10

Former Member
0 Kudos
684

Hi,

[]

[]

[]

Former Member
0 Kudos
685

hi,

please refer this link

TYPES: BEGIN OF ty_head,

h(10) TYPE c,

END OF ty_head.

DATA: it_head TYPE TABLE OF ty_head WITH HEADER LINE.

it_head-h = 'Field1'.

APPEND it_head.

it_head-h = 'Field2'.

APPEND it_head.

it_head-h = 'Field3'.

APPEND it_head.

it_head-h = 'Field4'.

APPEND it_head.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = p_file

filetype = 'ASC'

write_field_separator = 'X'

header = '00'

TABLES

data_tab = it_tab

fieldnames = it_head[]

EXCEPTIONS

OTHERS = 1.

https://www.sdn.sap.com/irj/scn/wiki?path=/display/snippets/download%252bdata%252binto%252bexcel%252...

thanks

0 Kudos
684

Hi,

While trying with the code you have given I was able to get all the selected fields and header in a single column , I want merge header fields and selected fields in a seperate column.

0 Kudos
684

hi,

TYPES: BEGIN OF ty_head,

h1

h2

h3

(upto the number of columns in your internal table which u want header)

END OF ty_head.

DATA: it_head TYPE TABLE OF ty_head WITH HEADER LINE.

it_head-h1 = 'Field1'.

it_head-h2 = 'Field2'.

it_head-h3 = 'Field3'.

it_head-h4 = 'Field4'.

append it_head

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = p_file

filetype = 'ASC'

write_field_separator = 'X'

header = '00'

TABLES

data_tab = it_tab

fieldnames = it_head[]

EXCEPTIONS

OTHERS = 1.

reg

Ramya

0 Kudos
684

Hi ,

I have completed the program with your guidence , thanks for your response.

0 Kudos
684

Hi,

I have completed the program with your guidence , thanks for your response.

Former Member
0 Kudos
684

Hi,

I had a similar requirement but wat I did was i inserted a row in the Internal Table (obviously the first row with index 1) with all the header contents. And after that I appended the desired data to the Internal Table.

Regards,

Sakkthiss.R

Former Member
0 Kudos
684

hi,

Use GUI_DOWNLOAD and the tables parameter

FIELDNAMES is used to get the header in the file.

Give the file extension as "xls" and field separator 'X' for proper download of your data

Thanks

Sharath

satsrockford
Active Participant
0 Kudos
684

Hi

See this sample code:

Tables : zacg_cca,zacg_exsh.

data: P_file like RLGRAP-FILENAME.

Data: Begin of it_header occurs 0,

Header(15) ,

end of it_header.

Data : begin of it_final occurs 0,

ccode type zacg_cca-ccode,

mat_cd type zacg_cca-mat_cd,

ingr_desc type zacg_cca-ingr_desc,

conc type zacg_cca-conc,

quantity type zacg_cca-quantity,

percqty type zacg_cca-percqty,

flag ,

APP_DATE type zacg_cca-app_date,

rsamnos type zacg_cca-rsamnos,

end of it_final.

SELECTION-SCREEN : BEGIN OF BLOCK blk WITH FRAME TITLE text-000.

select-options : s_Date for zacg_cca-app_date.

SELECTION-SCREEN : END OF BLOCK blk.

it_header-Header = 'Samp_code'.

Append it_header.

it_header-Header = 'Mat_code'.

Append it_header.

it_header-Header = 'Ingr_Desc'.

Append it_header.

it_header-Header = 'Conc'.

Append it_header.

it_header-Header = 'Quan'.

Append it_header.

it_header-Header = 'Perc'.

Append it_header.

it_header-Header = 'Flag'.

Append it_header.

it_header-Header = 'Date'.

Append it_header.

it_header-Header = 'Rsamnos'.

Append it_header.

it_header-Header = 'Mat_code'.

Append it_header.

select ccode

mat_cd

ingr_desc

conc

quantity

percqty

app_date

rsamnos

from zacg_cca into corresponding

fields of table

it_final where zacg_cca~app_date in s_date.

loop at it_final.

it_final-flag = 'T'.

modify it_final.

it_final-quantity = it_final-quantity * 2 .

Modify it_final.

endloop.

CALL FUNCTION 'MS_EXCEL_OLE_STANDARD_DAT'

EXPORTING

FILE_NAME = 'E:\IT\P_FILE'

CREATE_PIVOT = 0

DATA_SHEET_NAME = ' '

PIVOT_SHEET_NAME = ' '

PASSWORD = ' '

PASSWORD_OPTION = 0

TABLES

PIVOT_FIELD_TAB =

DATA_TAB = it_final[]

FIELDNAMES = it_header[]

EXCEPTIONS

FILE_NOT_EXIST = 1

FILENAME_EXPECTED = 2

COMMUNICATION_ERROR = 3

OLE_OBJECT_METHOD_ERROR = 4

OLE_OBJECT_PROPERTY_ERROR = 5

INVALID_PIVOT_FIELDS = 6

DOWNLOAD_PROBLEM = 7

OTHERS = 8

.

IF SY-SUBRC 0.

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

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

regards

Satish

Former Member
0 Kudos
684

Hi,

you can use FM GUI_DOWNLOAD to down load excel file.

1. create a internal table with 1 record containing all the headers only.

2. call GUI_DOWNLOAD and down load the file with headers only.

3. create internal table with subsequent data records with same column sequence as above internal table.

4.call GUI_DOWNLAOD with same file name as of above and this time set exporting PARAMETER 'APPEND' of GUI_DOWNLOAD with 'X'.

5.this will appand the second output to the same excel file downlaoded before.