08-09-2005 8:11 AM
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.
08-09-2005 8:23 AM
08-09-2005 8:23 AM
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.
08-09-2005 8:45 AM
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
08-09-2005 10:13 AM
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.