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

Inserting Field Names as Header

Former Member
0 Likes
1,526

Hi,

I am downloading few records from one internal table.But While downloading I want to add the filed names(to identify which record belongs to which field) too.Can anyone help me with some sample code for this?Thanks.

1 ACCEPTED SOLUTION
Read only

venkat_o
Active Contributor
0 Likes
1,179

Hi, Do this way. <li>Take headers in one table. Download that table using cl_gui_frontend_services=>gui_download. Here u need to set Append parameter as ' '. <li>Take data in another table. Download that table using cl_gui_frontend_services=>gui_download. Here u need to set Append parameter as 'X'. <li>When you call cl_gui_frontend_services=>gui_download method first time it creates file and keeps the header and when u call second time it appends to the existing file. File path should be same. I hope that it solves your problem. Thanks Venkat.O

Hi,

I am downloading few records from one internal table.But While downloading I want to add the filed names(to identify which record belongs to which field) too.Can anyone help me with some sample code for this?Thanks.

5 REPLIES 5
Read only

Former Member
0 Likes
1,179

Hi

Before downloading the internal table.

First transfer all heading into one area and insert into u r internal table with index 1.

Read only

sarbajitm
Contributor
0 Likes
1,179

Hi,

Are you downloading the internal table to a excel sheet? Then use FM 'GUI_DOWNLOAD'.In that FM,in the TABLES parameter list,set the parameterFIELDNAMES. like the following way.

TYPES : BEGIN OF ty_header,

fieldname(100) TYPE c,

END OF ty_header.

DATA:it_head TYPE TABLE OF ty_header,

wa_head TYPE ty_header.

then call a subroutine like the following one before calling the FM.

form BUILD_HEADING .

CLEAR wa_head.

wa_head-fieldname = 'PersonnelId'.

APPEND wa_head TO it_head.

CLEAR wa_head.

wa_head-fieldname = 'StartDate'.

APPEND wa_head TO it_head.

CLEAR wa_head.

wa_head-fieldname = 'EndDate'.

APPEND wa_head TO it_head.

CLEAR wa_head.

wa_head-fieldname = 'Reason'.

APPEND wa_head TO it_head.

CLEAR wa_head.

wa_head-fieldname = 'WageType'.

APPEND wa_head TO it_head.

CLEAR wa_head.

wa_head-fieldname = 'NewHourlyRate'.

APPEND wa_head TO it_head.

CLEAR wa_head.

wa_head-fieldname = 'NewAnnualSalary'.

APPEND wa_head TO it_head.

CLEAR wa_head.

endform. " BUILD_HEADING

finally call the FM where you have to set..........

Tables

FIELDNAMES = it_head.

Hope it helps you.

Regards.

Sarbajit.

Read only

Former Member
0 Likes
1,179

Hi,

You need to append the header names.

Check this Wiki

[https://wiki.sdn.sap.com/wiki/display/Snippets/downloaddataintoexcelwith+header]

Link

Regards

Sarves

Read only

0 Likes
1,179

Hi All,

Thanks for the reply.But I am downloading one tab delimated file using cl_gui_frontend_services=>gui_download.

Read only

venkat_o
Active Contributor
0 Likes
1,180

Hi, Do this way. <li>Take headers in one table. Download that table using cl_gui_frontend_services=>gui_download. Here u need to set Append parameter as ' '. <li>Take data in another table. Download that table using cl_gui_frontend_services=>gui_download. Here u need to set Append parameter as 'X'. <li>When you call cl_gui_frontend_services=>gui_download method first time it creates file and keeps the header and when u call second time it appends to the existing file. File path should be same. I hope that it solves your problem. Thanks Venkat.O