02-17-2009 6:32 AM
Hi Experts,
I got a requirement regarding gui_download where im downloading internal table data into word document i.e's ".DOC" format, but my question is if i have a tabular structure drawn already in my word doc, (like excel sheet ) rows and columns , will the internal table data go and sit in that table structure. is there any way we can fulfill this requirement .
02-17-2009 6:38 AM
Hi,
Refer to the following code for help.
report zmurli_handson1_download no standard page heading
message-id z_msg_hands.
tables: ekko.
type-pools : slis.
type-pools: abap.
set pf-status 'ZDWNLD'.
data:begin of itab occurs 0,
ebeln like ekko-ebeln,
bukrs like ekko-bukrs,
end of itab.
selection-screen begin of block 01 with frame title text-001.
select-options: so_ebeln for ekko-ebeln obligatory.
selection-screen end of block 01.
top-of-page.
write:/'Requester: ',sy-uname,100 'Page: ',sy-pagno,
/'Program: ',sy-repid,100 'Date: ',sy-datum.
uline.
skip 3.
write:/45 'Title: ', sy-title.
uline.
skip 3.
start-of-selection.
perform get_data.
end-of-selection.
perform display.
&----
*& Form display
&----
text
----
form display.
uline (40).
write:/ sy-vline, 'Purchase No.',
20 sy-vline, 'Company Code.',
40 sy-vline.
uline (40).
loop at itab.
write:/ sy-vline, itab-ebeln,
20 sy-vline, itab-bukrs,
40 sy-vline.
uline (40).
endloop.
endform. "display
at user-command.
perform download.
&----
*& Form Get_Data
&----
text
----
--> p1 text
<-- p2 text
----
form get_data .
select * from ekko into corresponding fields of table itab
where ebeln in so_ebeln.
endform. " Get_Data
&----
*& Form download
&----
text
----
form download.
if sy-ucomm = 'DOWNLOAD' and sy-lsind = 1.
data: fullpath type string,
filename type string,
path type string,
user_action type i,
encoding type abap_encoding.
call method cl_gui_frontend_services=>file_save_dialog
exporting
window_title = 'Gui_Download Demo'
with_encoding = 'X'
initial_directory = 'C:\'
changing
filename = filename
path = path
fullpath = fullpath
user_action = user_action
file_encoding = encoding
exceptions
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
others = 4.
if sy-subrc <> 0.
exit.
endif.
if user_action <> cl_gui_frontend_services=>action_ok.
exit.
endif.
Ascii download
call function 'GUI_DOWNLOAD'
exporting
filename = fullpath
filetype = 'DAT'
tables
data_tab = itab.
endif.
endform. "download
Regards
Rajesh Kumar
02-17-2009 6:38 AM
Hi,
Refer to the following code for help.
report zmurli_handson1_download no standard page heading
message-id z_msg_hands.
tables: ekko.
type-pools : slis.
type-pools: abap.
set pf-status 'ZDWNLD'.
data:begin of itab occurs 0,
ebeln like ekko-ebeln,
bukrs like ekko-bukrs,
end of itab.
selection-screen begin of block 01 with frame title text-001.
select-options: so_ebeln for ekko-ebeln obligatory.
selection-screen end of block 01.
top-of-page.
write:/'Requester: ',sy-uname,100 'Page: ',sy-pagno,
/'Program: ',sy-repid,100 'Date: ',sy-datum.
uline.
skip 3.
write:/45 'Title: ', sy-title.
uline.
skip 3.
start-of-selection.
perform get_data.
end-of-selection.
perform display.
&----
*& Form display
&----
text
----
form display.
uline (40).
write:/ sy-vline, 'Purchase No.',
20 sy-vline, 'Company Code.',
40 sy-vline.
uline (40).
loop at itab.
write:/ sy-vline, itab-ebeln,
20 sy-vline, itab-bukrs,
40 sy-vline.
uline (40).
endloop.
endform. "display
at user-command.
perform download.
&----
*& Form Get_Data
&----
text
----
--> p1 text
<-- p2 text
----
form get_data .
select * from ekko into corresponding fields of table itab
where ebeln in so_ebeln.
endform. " Get_Data
&----
*& Form download
&----
text
----
form download.
if sy-ucomm = 'DOWNLOAD' and sy-lsind = 1.
data: fullpath type string,
filename type string,
path type string,
user_action type i,
encoding type abap_encoding.
call method cl_gui_frontend_services=>file_save_dialog
exporting
window_title = 'Gui_Download Demo'
with_encoding = 'X'
initial_directory = 'C:\'
changing
filename = filename
path = path
fullpath = fullpath
user_action = user_action
file_encoding = encoding
exceptions
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
others = 4.
if sy-subrc <> 0.
exit.
endif.
if user_action <> cl_gui_frontend_services=>action_ok.
exit.
endif.
Ascii download
call function 'GUI_DOWNLOAD'
exporting
filename = fullpath
filetype = 'DAT'
tables
data_tab = itab.
endif.
endform. "download
Regards
Rajesh Kumar
02-17-2009 8:27 AM
HI Rajesh,
I executed your program, but unable to download data into internal table, do this program download into word exactly how it prints the output with rows and columns drawn? in your program for download did you created a button on output of list and on click of that download happens?
02-17-2009 8:50 AM
Hi friend,
Try this simple report.
This may help you.
Report ztest.
*Types
TYPES: BEGIN OF g_r_mara,
matnr LIKE mara-matnr,
ersda LIKE mara-ersda,
laeda LIKE mara-laeda,
mtart LIKE mara-mtart,
mbrsh LIKE mara-mbrsh,
END OF g_r_mara.
*Data
DATA: g_t_mara TYPE TABLE OF g_r_mara,
filename TYPE string.
*Tables
TABLES: mara, sscrfields.
*Selection Screen
SELECT-OPTIONS: s_matnr FOR mara-matnr.
SELECTION-SCREEN BEGIN OF LINE.
*SELECTION-SCREEN COMMENT 10(20) text-001 FOR FIELD p1.
SELECTION-SCREEN PUSHBUTTON 12(20) word USER-COMMAND uc.
SELECTION-SCREEN END OF LINE.
*Initilizing data.
INITIALIZATION.
word = 'word'.
filename = 'C:\Testing.doc'.
AT SELECTION-SCREEN.
CASE sscrfields-ucomm.
WHEN 'UC'.
*Data retrival
SELECT matnr ersda laeda mtart mbrsh
INTO CORRESPONDING FIELDS OF TABLE g_t_mara
FROM mara
WHERE matnr IN s_matnr.
*Downloading data from internal table to word
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = filename
filetype = 'ASC'
write_field_separator = 'X'
TABLES
data_tab = g_t_mara.
ENDCASE.
Final Word file in C:\Testing.doc
Thanks..
Edited by: Guest77 on Feb 17, 2009 9:50 AM
02-17-2009 8:07 AM
Hi friend,
I dont think its is possible to download data to word in rows and columns.
Do it in excel.
For excel if u need help, let me know..
Thanks....
02-17-2009 8:56 AM
>
> Hi Experts,
> I got a requirement regarding gui_download where im downloading internal table data into word document i.e's ".DOC" format, but my question is if i have a tabular structure drawn already in my word doc, (like excel sheet ) rows and columns , will the internal table data go and sit in that table structure. is there any way we can fulfill this requirement .
No, you can't do it like that. If you want to have word formatting, you'll have to use OLE, or Desktop Office Integration (DOI). Search the forums for details about these.
matt