03-19-2009 6:40 PM
Hi All,
I have a problem in transfering data from internal table into the excel. Problem is before transferring data I have to transfer the header line then transfer the data. How do I do it.
I created to internal tables for header and data, both have different length of records. is it possible to transfer the header first then data into the excel.
Thanks
Ravi
Edited by: Julius Bussche on Mar 19, 2009 9:24 PM
Please dont use CAPS-LOCK. It is generally interpreted as SHOUTING
03-20-2009 1:45 PM
Hi,
Add one more parameter in header 'GUI_DOWNLOAD'.
Header data:
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
write_field_separator = 'X'.
U will get in separate columns.
03-19-2009 6:41 PM
HI,
Use the GUI_DOWNLOAD FM
TYPES: BEGIN OF ty_head, "Structure for header
h(10) TYPE c,
END OF ty_head.
DATA: it_head TYPE TABLE OF ty_head WITH HEADER LINE.
"Adding header details
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 = filepath
filetype = 'DAT'
TABLES
data_tab = itab
fieldnames = it_head
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.
Edited by: Avinash Kodarapu on Mar 20, 2009 12:14 AM
03-19-2009 7:57 PM
Hi Avinash,
I tried yours but it is throughing some debug error while calling the function module. if running with out eheader it is working fine. I created the header as you suggested but still creating problem. can you suggest what may be reason.
Ravi
03-19-2009 8:01 PM
Avinash,
I given the code as follows
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = filename
filetype = 'DAT'
TABLES
data_tab = itab
fieldnames = itab_header
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.
I am getting dump as
Error analysis
The call to the function module "GUI_DOWNLOAD" is incorrect:
The function module interface allows you to specify only fields
of a particular type under "FILENAME". The field "FILENAME" specified here
has a different field type.
Ravi
03-19-2009 9:19 PM
Hi, Ravi
Test the Sample Code Bellow it will work for you. i have tested and it is working fine for me, it will create abc.xls on the local Drive C Please Check this Excel File.
TYPES: BEGIN OF ty_it1,
mm(15),
amount1 TYPE i,
amount2 TYPE i,
END OF ty_it1.
TYPES: BEGIN OF ty_heading,
h(15),
END OF ty_heading.
DATA: it TYPE STANDARD TABLE OF ty_it1 WITH HEADER LINE,
it_heading TYPE STANDARD TABLE OF ty_heading WITH HEADER LINE.
it-mm = 'AAA'. it-amount1 = 123. it-amount2 = 321. APPEND it.
it-mm = 'BBB'. it-amount1 = 213. it-amount2 = 211. APPEND it.
it-mm = 'CCC'. it-amount1 = 543. it-amount2 = 332. APPEND it.
it_heading-h = 'Name'.APPEND it_heading. it_heading-h = 'Amount 1'.APPEND it_heading. it_heading-h = 'Amount 2'. APPEND it_heading.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = 'c:\abc.xls'
filetype = 'DAT'
TABLES
data_tab = it[]
fieldnames = it_heading
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 sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Best Regards,
Faisal
03-19-2009 6:47 PM
Hi,
Use function module GUI_DOWNLOAD
2 times,
1)for header table
2)same file name with item table with I_APPEND = 'X'.
or try with
FM '*XXL_FULL_API*'
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
Bala Krishna
Edited by: Bala Krishna on Mar 20, 2009 12:24 AM
03-19-2009 6:51 PM
Hi, Ravi,
Please don't use ALL CAPS in your Subject next time
you can use CALL METHOD cl_gui_frontend_services=>gui_download too.
Best Regards,
Faisal
03-20-2009 4:42 AM
03-20-2009 4:51 AM
Hi
Do two changes.
1. Declare 'filename' as data type string.
2. Change filetype to either 'ASC' or 'BIN'.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = filename <---- 'filename' type string.
filetype = 'DAT' <----- 'ASC' or 'BIN'
TABLES
data_tab = itab
fieldnames = itab_header
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.
03-20-2009 4:52 AM
Hi Ravi,
The error is because the data type of the variable filename that you are passing is different from the interface parameter in the function module. Make sure that the datatype for both is same.The filename should be of type string. If you are using as type rlgrap-filenmae pass this into a string variable and then pass that to the function module.
Hope this helps.
Regards,
Sachin
03-20-2009 6:20 AM
REPORT ZOLE_ABAP.
INCLUDE ole2incl.
&----
*& TYPES *
&----
TYPES: BEGIN OF ty_spfli,
kunnr TYPE kna1-kunnr,
land1 TYPE kna1-land1,
NAME1 TYPE KNA1-NAME1,
ORT01 TYPE KNA1-ORT01,
REGIO TYPE KNA1-REGIO,
ADRNR TYPE KNA1-ADRNR,
END OF ty_spfli.
TYPES: BEGIN OF ty_titles,
title(20) TYPE c,
field(20) TYPE c,
END OF ty_titles.
&----
*& INTERNAL TABLES *
&----
DATA: t_spfli TYPE STANDARD TABLE OF ty_spfli,
t_titles TYPE STANDARD TABLE OF ty_titles.
&----
*& FIELD-SYMBOLS *
&----
FIELD-SYMBOLS: <fs_spfli> LIKE LINE OF t_spfli,
<fs_titles> LIKE LINE OF t_titles,
<fs> TYPE ANY.
&----
*& VARIABLES *
&----
DATA: w_tabix TYPE sy-tabix,
w_titles TYPE sy-tabix,
w_line TYPE sy-tabix,
w_field TYPE string,
filename TYPE string,
path TYPE string,
fullpath TYPE string.
DATA: data_titles TYPE REF TO data.
DATA: e_sheet TYPE ole2_object,
e_activesheet TYPE ole2_object,
e_newsheet TYPE ole2_object,
e_appl TYPE ole2_object,
e_work TYPE ole2_object,
e_cell TYPE ole2_object,
e_color TYPE ole2_object,
e_bold TYPE ole2_object.
&----
*& SELECTION-SCREEN *
&----
SELECTION-SCREEN BEGIN OF BLOCK b1.
PARAMETERS: p_file TYPE rlgrap-filename.
SELECTION-SCREEN END OF BLOCK b1.
&----
*& START-OF-SELECTION *
&----
START-OF-SELECTION.
PERFORM get_titles.
PERFORM get_data.
PERFORM create_excel.
&----
*& AT SELECTION-SCREEN *
&----
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
window_title = 'Select archivo'
default_extension = 'xls'
file_filter = '*.xls'
CHANGING
filename = filename
path = path
fullpath = fullpath.
IF sy-subrc EQ 0.
p_file = fullpath.
ENDIF.
&----
*& Form get_titles *
&----
FORM get_titles.
CREATE DATA data_titles TYPE ty_titles.
ASSIGN data_titles->* TO <fs_titles>.
<fs_titles>-title = 'Customer Number 1'.
<fs_titles>-field = 'KUNNR'.
APPEND <fs_titles> TO t_titles.
<fs_titles>-title = 'Country Key'.
<fs_titles>-field = 'LAND1'.
APPEND <fs_titles> TO t_titles.
<fs_titles>-title = 'Name 1'.
<fs_titles>-field = 'NAME1'.
APPEND <fs_titles> TO t_titles.
<fs_titles>-title = 'City'.
<fs_titles>-field = 'ORT01'.
APPEND <fs_titles> TO t_titles.
<fs_titles>-title = 'Region'.
<fs_titles>-field = 'REGIO'.
APPEND <fs_titles> TO t_titles.
<fs_titles>-title = 'Address'.
<fs_titles>-field = 'ADRNR'.
APPEND <fs_titles> TO t_titles.
ENDFORM. "get_titles
&----
*& Form get_data *
&----
FORM get_data.
SELECT KUNNR LAND1 NAME1 ORT01 REGIO ADRNR
INTO TABLE t_spfli
FROM KNA1
WHERE LAND1 EQ 'IN'
and KUNNR EQ '0000700008'.
ENDFORM. " get_data
&----
*& Form create_excel *
&----
FORM create_excel.
w_line = 1.
CREATE OBJECT e_appl 'EXCEL.APPLICATION'.
SET PROPERTY OF e_appl 'VISIBLE' = 1.
CALL METHOD OF e_appl 'WORKBOOKS' = e_work.
CALL METHOD OF e_work 'Add' = e_work.
GET PROPERTY OF e_appl 'ActiveSheet' = e_activesheet.
SET PROPERTY OF e_activesheet 'Name' = 'Customer Details'.
LOOP AT t_spfli ASSIGNING <fs_spfli>.
w_tabix = sy-tabix.
w_line = w_line + 1.
LOOP AT t_titles ASSIGNING <fs_titles>.
w_titles = sy-tabix.
CALL METHOD OF e_appl 'Cells' = e_cell
EXPORTING
#1 = 1
#2 = w_titles.
SET PROPERTY OF e_cell 'Value' = <fs_titles>-title.
GET PROPERTY OF e_cell 'Interior' = e_color.
SET PROPERTY OF e_color 'ColorIndex' = 35.
GET PROPERTY OF e_cell 'Font' = e_bold.
SET PROPERTY OF e_bold 'Bold' = 1.
CALL METHOD OF e_appl 'Cells' = e_cell
EXPORTING
#1 = w_line
#2 = w_titles.
CONCATENATE '<fs_spfli>-' <fs_titles>-field
INTO w_field.
ASSIGN (w_field) TO <fs>.
SET PROPERTY OF e_cell 'Value' = <fs>.
GET PROPERTY OF e_cell 'Interior' = e_color.
SET PROPERTY OF e_cell 'ColumnWidth' = 20.
SET PROPERTY OF e_color 'ColorIndex' = 0.
GET PROPERTY OF e_cell 'Font' = e_bold.
SET PROPERTY OF e_bold 'Bold' = 0.
ENDLOOP.
ENDLOOP.
***************
CALL METHOD OF e_work 'SAVEAS'
EXPORTING
#1 = p_file.
CALL METHOD OF e_work 'close'.
CALL METHOD OF e_appl 'QUIT'.
FREE OBJECT e_appl.
ENDFORM. " create_excel
03-20-2009 8:28 AM
03-20-2009 9:45 AM
Error is becase of datatype mismatch in file nmae .
file name declare a s string.
Regards
03-20-2009 1:21 PM
Hi Faisal, SAP Fan,
In the 'GUI_DOWNLOAD' function module I dont find fieldnames parameter in the table where we give the header. Please let me know where to declare header
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE =
FILENAME =
FILETYPE = 'ASC'
APPEND = ' '
WRITE_FIELD_SEPARATOR = ' '
HEADER = '00'
TRUNC_TRAILING_BLANKS = ' '
WRITE_LF = 'X'
COL_SELECT = ' '
COL_SELECT_MASK = ' '
DAT_MODE = ' '
IMPORTING
FILELENGTH =
TABLES
DATA_TAB =
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 SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Ravi
03-20-2009 1:33 PM
Hi,
It is available in ECC 6,
or tyr below way.
DATA : w_file TYPE string.
w_file = p_file.
" For Header
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* BIN_FILESIZE =
filename = w_file
filetype = 'DBF'
* append = ' '
TABLES
data_tab = it_header
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 sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
" For Item Data
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* BIN_FILESIZE =
filename = w_file
filetype = 'DBF'
append = 'X' " <------ Set this for Item, so that item is loaded to same file
TABLES
data_tab = it_extractchar
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 sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Regards
Bala Krishna
03-20-2009 1:28 PM
Hi
IN 'GUI_DOWNLOAD' no table parameter exists for header data.
Only 'DATA_TAB' parameter in tables.
Make header data as first row of the internal table and then populate internal table with item data.
03-20-2009 1:33 PM
Hi,
Best way is to just download only item data to excel by mentioning only 'DATA_TAB' parameter in tables.
After downloading, in excel manually go and insert a header row before first item.
Hope helps.
03-20-2009 1:38 PM
Hi,
Check out this:
TYPES: BEGIN OF s_tab,
f1 TYPE i,
f2 TYPE i,
f3 TYPE char1,
f4 TYPE i,
END OF s_tab.
DATA: it_tab TYPE TABLE OF s_tab,
wa_tab TYPE s_tab.
DATA : var1 TYPE i,
var2 TYPE i,
sgn TYPE c.
DATA: T_NAME TYPE RLGRAP-FILENAME.
FREE it_tab. CLEAR wa_tab.
PARAMETER: F_NAME TYPE STRING.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR F_NAME.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
IMPORTING
FILE_NAME = T_NAME.
wa_tab-f1 = '1000'.
wa_tab-f2 = '001'.
wa_tab-f3 = '+'.
wa_tab-f4 = '10'.
APPEND wa_tab TO it_tab.
CLEAR wa_tab.
wa_tab-f1 = '1000'.
wa_tab-f2 = '001'.
wa_tab-f3 = '+'.
wa_tab-f4 = '10'.
APPEND wa_tab TO it_tab.
CLEAR wa_tab.
wa_tab-f1 = '1000'.
wa_tab-f2 = '001'.
wa_tab-f3 = '-'.
wa_tab-f4 = '5'.
APPEND wa_tab TO it_tab.
CLEAR wa_tab.
wa_tab-f1 = '2000'.
wa_tab-f2 = '001'.
wa_tab-f3 = '-'.
wa_tab-f4 = '5'.
APPEND wa_tab TO it_tab.
CLEAR wa_tab.
wa_tab-f1 = '2000'.
wa_tab-f2 = '001'.
wa_tab-f3 = '+'.
wa_tab-f4 = '10'.
APPEND wa_tab TO it_tab.
CLEAR wa_tab.
wa_tab-f1 = '2000'.
wa_tab-f2 = '001'.
wa_tab-f3 = '-'.
wa_tab-f4 = '20'.
APPEND wa_tab TO it_tab.
CLEAR wa_tab.
wa_tab-f1 = '1000'.
wa_tab-f2 = '002'.
wa_tab-f3 = '+'.
wa_tab-f4 = '10'.
APPEND wa_tab TO it_tab.
CLEAR wa_tab.
wa_tab-f1 = '1000'.
wa_tab-f2 = '002'.
wa_tab-f3 = '-'.
wa_tab-f4 = '5'.
APPEND wa_tab TO it_tab.
CLEAR wa_tab.
.
*LOOP AT it_tab INTO wa_tab.
*
WRITE: / wa_tab-f1, wa_tab-f2, wa_tab-f3, wa_tab-f4.
*ENDLOOP.
CALL FUNCTION 'SAP_CONVERT_TO_XLS_FORMAT'
EXPORTING
I_FIELD_SEPERATOR =
I_LINE_HEADER =
i_filename = T_NAME
I_APPL_KEEP = ' '
tables
i_tab_sap_data = IT_TAB
CHANGING
I_TAB_CONVERTED_DATA =
EXCEPTIONS
CONVERSION_FAILED = 1
OTHERS = 2
.
IF sy-subrc EQ 0.
Message 'File saved in location' TYPE 'I'.
ENDIF.
Cheers,
Rudhir
03-20-2009 1:41 PM
HI Bala Krishna, sap fan,
When I using the gui download by creating a internal table for header line, I am getting all the data in one coloumn of excel, but my requirement is to get the header data as each coloumn for each internal field.
SAP Fan:
We are not authorised to write the heder line manually. If you have any idea please suggest me. I have one header table and one data table but both the table record lengths are different. How to work on this,
Needed this help. Please any one can help me in this problem.
Ravi
03-20-2009 1:43 PM
Hi Rudhir,
I obtained the data in the excel , now working a way to get the heade on the excel.
Ravi
03-20-2009 1:45 PM
Hi,
Add one more parameter in header 'GUI_DOWNLOAD'.
Header data:
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
write_field_separator = 'X'.
U will get in separate columns.
03-20-2009 1:59 PM
Problem is solved my friends. Thanks a lot for each and everyone.
Ravi