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 to xls file

Former Member
0 Kudos

Hi all,

Iam downloading data from sap tables to appln server.

its working perfectly.But I want to add the field names also to the file header.

Please help me regarding this matter.

regards

sai chand.

4 REPLIES 4

Former Member
0 Kudos

Hi,

Chk these links:

Regards,

Anjali

jayanthi_jayaraman
Active Contributor
0 Kudos

Hi,

Check this sample code.

DATA lv_file TYPE string.

TYPES: BEGIN OF ty_download,

werks(5) TYPE c, "Plant

matnr(18) TYPE c, "Product number

END OF ty_download.

data : i_download TYPE STANDARD TABLE OF ty_download,

w_download TYPE ty_download.

lv_file = p_file.

CLEAR w_download.

w_download-werks = 'Plant'.

w_download-matnr = 'Material'.

INSERT w_download INTO i_download INDEX 1.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = lv_file

filetype = 'ASC'

write_field_separator = c_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 it is useful,kindly reward points by clicking the star on the left side of the reply.

andreas_mann3
Active Contributor
0 Kudos

Hi,

try this (dynamic: for internal tables with many fields)

before appending your itab to down_load_tab:

 descr_ref ?= cl_abap_typedescr=>describe_by_data( my_data ).

  LOOP AT descr_ref->components ASSIGNING <comp_wa>.
    CONCATENATE header <comp_wa>-name ';' INTO header.
  ENDLOOP.

  append header to down_tab.

Andreas

Former Member
0 Kudos

Hi,

While downloading file, u wont get the header part, u have to append the header part before the data. Then u pass the final output table with header to the function module.

So that it will read the first line that will be header and then remaning data.

U can create an internal table.

TYPES: begin of ty_itab ,  
name(4) TYPE c,  
sex(3)  Type c, 
end of ty_itab.
DATA: i_itab type standard table of ty_itab, 
     w_itab type ty_itab.

Then do as below. 
w_itab-name = 'NAME'. 
w_itab-sex  = 'SEX'. 
APPEND w_itab to i_output_final. 
i_output[] = i_output_final. 
APPEND i_output_final.

Now pass this final table to the functionmodule, so it is now with header.