11-04-2006 6:15 AM
Hi all,
Can someone please suggest me some function module for downloading the data to an excel sheet.
thanks
11-04-2006 7:05 AM
Hi Arun
You can use FM: <b>GUI_DOWNLOAD</b> for downloading data in a internal table to <b>presentation server</b> as an XLS file. You can searching the forum with the function module name to get some sample codes using the function module.
Incase you need to download the data to application server, you have to try using <b>OPEN DATASET, TRANSFER, CLOSE DATASET</b> statements.
Kind Regards
Eswar
11-04-2006 7:30 AM
Hi,
chk this.
<b>1.</b>
REPORT ZSRIM_GUI_DOWNLOAD_TO_EXCEL.
data : itab type mara occurs 0 with header line.
select * into itab
from mara
up to 10 rows.
append itab.
endselect.
data : begin of itab1 occurs 0,
line(50) type c,
end of itab1.
itab1-line = 'field1 description'.
append itab1.
itab1-line = 'field2 desc'.
append itab1.
itab1-line = 'field3 desc'.
append itab1.
*--and so on you have to add up the records in itab1.
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
BIN_FILESIZE = ' '
CODEPAGE = ' '
FILENAME = 'C:\ABCD.XLS '
FILETYPE = 'DAT'
MODE = ' '
WK1_N_FORMAT = ' '
WK1_N_SIZE = ' '
WK1_T_FORMAT = ' '
WK1_T_SIZE = ' '
COL_SELECT = ' '
COL_SELECTMASK = ' '
NO_AUTH_CHECK = ' '
IMPORTING
FILELENGTH = FILELENGTH
TABLES
DATA_TAB = ITAB
FIELDNAMES = ITAB1
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_WRITE_ERROR = 2
INVALID_FILESIZE = 3
INVALID_TYPE = 4
NO_BATCH = 5
UNKNOWN_ERROR = 6
INVALID_TABLE_WIDTH = 7
GUI_REFUSE_FILETRANSFER = 8
CUSTOMER_ERROR = 9
NO_AUTHORITY = 10
OTHERS = 11
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
<i><b>2. all excel FM</b></i>
REPORT ZZBGS010 .
----
Example: Interface between Microsoft Excel and ABAP/4 with up- and *
downloading of data plus executing Microsoft Excel. *
----
TABLES: USR04.
DATA: SIZE TYPE I.
DATA: BEGIN OF USER OCCURS 100.
INCLUDE STRUCTURE USR04.
DATA: END OF USER.
---------------------------------------------------------------------*
Example: Select some data into an internal table. *
---------------------------------------------------------------------*
SELECT * FROM USR04 INTO TABLE USER .
---------------------------------------------------------------------*
Example: Downloading data in Microsoft Excel Format with automatic *
prompt popup dialog. *
---------------------------------------------------------------------*
CALL FUNCTION 'DOWNLOAD'
EXPORTING
FILENAME = 'C:\tmp\SAPEXL1.XLS'
FILETYPE = 'WK1' "ASC, WK1, DBF, DAT, bin
MODE = ' ' "Mode ' ' = Rewrite Mode 'A' = Appending
TABLES
DATA_TAB = USER.
---------------------------------------------------------------------*
Example: Downloading data in Microsoft Excel Format without automatic*
prompt popup. *
---------------------------------------------------------------------*
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
FILENAME = 'C:\tmp\SAPEXL2.XLS'
FILETYPE = 'WK1' "ASC, WK1, DBF, DAT, bin
MODE = ' ' "Mode ' ' = Rewrite Mode 'A' = Appending
TABLES
DATA_TAB = USER.
CLEAR USER. "Clear buffer
REFRESH USER. "Refresh, empty internal table
----
Example: Uploading Microsoft Excel to ABAP/4 internal table. *
----
CALL FUNCTION 'UPLOAD'
EXPORTING
FILENAME = 'C:\tmp\SAPEXL.prn'
FILETYPE = 'ASC'
IMPORTING
FILESIZE = SIZE
TABLES
DATA_TAB = USER.
----
Example: Starting Microsoft Excel and load sheet. *
----
CALL FUNCTION 'WS_EXECUTE'
EXPORTING
COMMANDLINE = 'C:\tmp\SAPEXL1.XLS'
PROGRAM = 'F:\APPL\WINDOWS\EXCEL5DK\EXCEL.EXE'
.
----
Example: Starting Microsoft Excel and load internal table as sheet *
----
CALL FUNCTION 'WS_EXCEL'
EXPORTING
FILENAME = 'C:\tmp\SAPEXL.XLS'
SYNCHRON = ' '
TABLES
DATA = USER.
-
rgds
anver
11-06-2006 9:09 AM
Hi,
Refer this link
http://www.sapdevelopment.co.uk/file/file_updown.htm
Try this one
FORM f9008_f4_hlp_for_pc_file.
DATA: li_filetable TYPE STANDARD TABLE OF file_table,
lv_return TYPE i,
lw_filetable TYPE file_table.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = 'Select file for download'
default_extension = '.xls'
initial_directory = 'C:'
CHANGING
file_table = li_filetable
rc = lv_return
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
OTHERS = 4
.
IF sy-subrc <> 0.
MESSAGE e006 WITH text-077.
ELSE.
READ TABLE li_filetable INTO lw_filetable INDEX 1.
v_fnam = lw_filetable-filename.
ENDIF.
FORM f9007_download_file TABLES p_output.
DATA: lv_size TYPE i.
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
filename = v_fnam
filetype = 'DAT'
IMPORTING
filelength = lv_size
TABLES
data_tab = p_output
EXCEPTIONS
file_open_error = 1
file_write_error = 2
invalid_filesize = 3
invalid_type = 4
no_batch = 5
unknown_error = 6
invalid_table_width = 7
gui_refuse_filetransfer = 8
customer_error = 9
OTHERS = 10.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " f9007_download_file
Reward points if this helps you.