02-13-2008 10:32 AM
i need to download contents of internal table to excel file provided the first entry(row) in excel file should be the fieldname(ex: matnr,ersda) and rest entries should be the content of internal table. im using version 4.7
02-13-2008 10:38 AM
In Gui_download put filetype = 'DBT'
'DBF' :
Data is downloaded in dBase format. Since in this format the data types
of the individual columns are stored as well, you can often avoid import
problems, for example, into Microsoft Excel, especially when
interpreting numeric values.
in tables ull have a parameter fieldname put all ur header feild names in dat.
Short Text
Field Names for the 'DBF' File Type
Description
Optional table with column names for the individual columns.
o 'DBF': The column names are entered into the structure definition of
the DBF file.
Cheers,
jose.
Edited by: jose on Feb 13, 2008 11:39 AM
02-13-2008 10:38 AM
In Gui_download put filetype = 'DBT'
'DBF' :
Data is downloaded in dBase format. Since in this format the data types
of the individual columns are stored as well, you can often avoid import
problems, for example, into Microsoft Excel, especially when
interpreting numeric values.
in tables ull have a parameter fieldname put all ur header feild names in dat.
Short Text
Field Names for the 'DBF' File Type
Description
Optional table with column names for the individual columns.
o 'DBF': The column names are entered into the structure definition of
the DBF file.
Cheers,
jose.
Edited by: jose on Feb 13, 2008 11:39 AM
02-13-2008 11:32 AM
hi jose,
it goes to dump. pls can u give me sample GUI_DOWNLOAD FM , filled with required parameters.
many thanks
02-13-2008 11:44 AM
data : Begin of t_header occurs 0,
name(30) type c,
end of t_header.
data : Begin of itab occurs 0,
fld1 type char10,
fld2 type char10,
fld3 type char10,
end of itab.
DATA: v_pass_path TYPE string.
append itab.
itab-fld1 = 'Hi'.
itab-fld2 = 'hello'.
itab-fld3 = 'welcome'.
append itab.
append itab.
append itab.
append itab.
append itab.
t_header-name = 'Field1'.
append t_header.
t_header-name = 'Field2'.
append t_header.
t_header-name = 'Field3'.
append t_header.
CALL FUNCTION 'GUI_FILE_SAVE_DIALOG'
EXPORTING
default_extension = 'XLS'
IMPORTING
fullpath = v_pass_path.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = v_pass_path
filetype = 'DBF'
TABLES
data_tab = itab
FIELDNAMES = t_header
.
02-13-2008 11:55 AM
Hi Jose,
im getting this dump, PARAMETER Fieldnames not defined
thanks.
02-13-2008 12:03 PM
goto gui_download in se37->display>tables tab...
see if u hav fieldnames parameter der...........if it is der...this pgm ll work..........
check WS_DOWNLOAD also...
02-13-2008 12:05 PM
02-13-2008 12:21 PM
Hi,
try like dis...........
data : Begin of itab occurs 0,
fld1 type char10,
fld2 type char10,
fld3 type char10,
end of itab.
data t_header like table of itab with header line.
DATA: v_pass_path TYPE string.
append itab.
itab-fld1 = 'Hi'.
itab-fld2 = 'hello'.
itab-fld3 = 'welcome'.
append itab.
append itab.
append itab.
append itab.
append itab.
t_header-fld1 = 'Field1'.
t_header-fld2 = 'Field2'.
t_header-fld3 = 'Field3'.
append t_header.
CALL FUNCTION 'GUI_FILE_SAVE_DIALOG'
EXPORTING
default_extension = 'XLS'
IMPORTING
fullpath = v_pass_path.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = v_pass_path
filetype = 'DAT'
TABLES
data_tab = t_header
.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = v_pass_path
filetype = 'DAT'
APPEND = 'X'
TABLES
data_tab = itab
.
02-13-2008 12:42 PM
02-13-2008 10:41 AM
Hi,
U need to call that function module twice.
For the first time u need to pass the contents with header data.
For the second time u need to pass the intenal table with the data,but set the append option.
APPEND = 'X'.
This will surley solves ur problem...
Regards,
Dayakar
02-13-2008 11:34 AM
hi,
i did the same, but the header entries are got in column wise. i need the fieldname to appear row wise, i.e tab limited in excel sheet first row.
thanks.
02-13-2008 11:41 AM
hi,
check the below sample code..
Often we face situations where we need to download internal table contents onto an Excel sheet. We are familiar with the function module GUI_DOWNLOAD. Though this function module downloads the contents onto the Excel sheet, there cannot be any column headings or we cannot differentiate the primary keys just by seeing the Excel sheet.
For this purpose, we can use the function module XXL_FULL_API. The Excel sheet which is generated by this function module contains the column headings and the key columns are highlighted with a different color. Other options that are available with this function module are we can swap two columns or supress a field from displaying on the Excel sheet. The simple code for the usage of this function module is given below.
Program code :
-
REPORT Excel.
TABLES:
sflight.
header data................................
DATA :
header1 LIKE gxxlt_p-text VALUE 'Suresh',
header2 LIKE gxxlt_p-text VALUE 'Excel sheet'.
Internal table for holding the SFLIGHT data
DATA BEGIN OF t_sflight OCCURS 0.
INCLUDE STRUCTURE sflight.
DATA END OF t_sflight.
Internal table for holding the horizontal key.
DATA BEGIN OF t_hkey OCCURS 0.
INCLUDE STRUCTURE gxxlt_h.
DATA END OF t_hkey .
Internal table for holding the vertical key.
DATA BEGIN OF t_vkey OCCURS 0.
INCLUDE STRUCTURE gxxlt_v.
DATA END OF t_vkey .
Internal table for holding the online text....
DATA BEGIN OF t_online OCCURS 0.
INCLUDE STRUCTURE gxxlt_o.
DATA END OF t_online.
Internal table to hold print text.............
DATA BEGIN OF t_print OCCURS 0.
INCLUDE STRUCTURE gxxlt_p.
DATA END OF t_print.
Internal table to hold SEMA data..............
DATA BEGIN OF t_sema OCCURS 0.
INCLUDE STRUCTURE gxxlt_s.
DATA END OF t_sema.
Retreiving data from sflight.
SELECT * FROM sflight
INTO TABLE t_sflight.
Text which will be displayed online is declared here....
t_online-line_no = '1'.
t_online-info_name = 'Created by'.
t_online-info_value = 'SURESH KUMAR PARVATHANENI'.
APPEND t_online.
Text which will be printed out..........................
t_print-hf = 'H'.
t_print-lcr = 'L'.
t_print-line_no = '1'.
t_print-text = 'This is the header'.
APPEND t_print.
t_print-hf = 'F'.
t_print-lcr = 'C'.
t_print-line_no = '1'.
t_print-text = 'This is the footer'.
APPEND t_print.
Defining the vertical key columns.......
t_vkey-col_no = '1'.
t_vkey-col_name = 'MANDT'.
APPEND t_vkey.
t_vkey-col_no = '2'.
t_vkey-col_name = 'CARRID'.
APPEND t_vkey.
t_vkey-col_no = '3'.
t_vkey-col_name = 'CONNID'.
APPEND t_vkey.
t_vkey-col_no = '4'.
t_vkey-col_name = 'FLDATE'.
APPEND t_vkey.
Header text for the data columns................
t_hkey-row_no = '1'.
t_hkey-col_no = 1.
t_hkey-col_name = 'PRICE'.
APPEND t_hkey.
t_hkey-col_no = 2.
t_hkey-col_name = 'CURRENCY'.
APPEND t_hkey.
t_hkey-col_no = 3.
t_hkey-col_name = 'PLANETYPE'.
APPEND t_hkey.
t_hkey-col_no = 4.
t_hkey-col_name = 'SEATSMAX'.
APPEND t_hkey.
t_hkey-col_no = 5.
t_hkey-col_name = 'SEATSOCC'.
APPEND t_hkey.
t_hkey-col_no = 6.
t_hkey-col_name = 'PAYMENTSUM'.
APPEND t_hkey.
populating the SEMA data..........................
t_sema-col_no = 1.
t_sema-col_typ = 'STR'.
t_sema-col_ops = 'DFT'.
APPEND t_sema.
t_sema-col_no = 2.
APPEND t_sema.
t_sema-col_no = 3.
APPEND t_sema.
t_sema-col_no = 4.
APPEND t_sema.
t_sema-col_no = 5.
APPEND t_sema.
t_sema-col_no = 6.
APPEND t_sema.
t_sema-col_no = 7.
APPEND t_sema.
t_sema-col_no = 8.
APPEND t_sema.
t_sema-col_no = 9.
APPEND t_sema.
t_sema-col_no = 10.
t_sema-col_typ = 'NUM'.
t_sema-col_ops = 'ADD'.
APPEND t_sema.
CALL FUNCTION 'XXL_FULL_API'
EXPORTING
DATA_ENDING_AT = 54
DATA_STARTING_AT = 5
filename = 'TESTFILE'
header_1 = header1
header_2 = header2
no_dialog = 'X'
no_start = ' '
n_att_cols = 6
n_hrz_keys = 1
n_vrt_keys = 4
sema_type = 'X'
SO_TITLE = ' '
TABLES
data = t_sflight
hkey = t_hkey
online_text = t_online
print_text = t_print
sema = t_sema
vkey = t_vkey
EXCEPTIONS
cancelled_by_user = 1
data_too_big = 2
dim_mismatch_data = 3
dim_mismatch_sema = 4
dim_mismatch_vkey = 5
error_in_hkey = 6
error_in_sema = 7
file_open_error = 8
file_write_error = 9
inv_data_range = 10
inv_winsys = 11
inv_xxl = 12
OTHERS = 13
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Regards,
Nagaraj