2006 Mar 01 4:15 AM
hello all,
I have to upload data from 5 internal tables from my report into an excel sheet.Is there any function module available for doin this. Actually there are 5 internal tales in my report.and i want to keep a track of the records in these tables as some problem has come up.and hence i need to upload this data into excel sheets.can someone please tell me the function module i can use or some other way to do this.
Thanks and Regards.
seema.
hello all,
I have to upload data from 5 internal tables from my report into an excel sheet.Is there any function module available for doin this. Actually there are 5 internal tales in my report.and i want to keep a track of the records in these tables as some problem has come up.and hence i need to upload this data into excel sheets.can someone please tell me the function module i can use or some other way to do this.
Thanks and Regards.
seema.
2006 Mar 01 4:19 AM
data: begin of itab occurs 0,
vbeln like vbak-vbeln,
posnr like vbap-posnr,
end of itab.
select vbeln
posnr
from vbap
up to 20 rows
into table itab.
* EXCEL sheet using OLE automation.
INCLUDE OLE2INCL.
* handles for OLE objects
DATA: H_EXCEL TYPE OLE2_OBJECT, " Excel object
H_WORK TYPE OLE2_OBJECT,
H_SHEET TYPE OLE2_OBJECT,
H_CELL TYPE OLE2_OBJECT,
V_COL LIKE SY-TABIX. " column number of the cell
DATA:
V_STEP(30),
V_FILE LIKE RLGRAP-FILENAME.
* tell user what is going on
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
* PERCENTAGE = 0
TEXT = 'Creating Excel...'
EXCEPTIONS
OTHERS = 1.
* start Excel
V_STEP = 'Starting Excel'.
CREATE OBJECT H_EXCEL 'EXCEL.APPLICATION'.
PERFORM ERR_HDL.
SET PROPERTY OF H_EXCEL 'Visible' = 1.
* CALL METHOD OF H_EXCEL 'OPEN' EXPORTING #1 = 'C:DMC_REC.XLS'.
* PERFORM ERR_HDL.
* tell user what is going on
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
* PERCENTAGE = 0
TEXT = 'Adding Data to Excel...'
EXCEPTIONS
OTHERS = 1.
* Get the list of workbooks
V_STEP = 'Preaparing Excel'.
CALL METHOD OF H_EXCEL 'WORKBOOKS' = H_WORK.
PERFORM ERR_HDL.
** Add new workbook (create a file)
CALL METHOD OF H_WORK 'ADD'.
PERFORM ERR_HDL.
* Get the created worksheet
************************Sheet Number
CALL METHOD OF H_EXCEL 'WORKSHEETS' = H_SHEET EXPORTING #1 = 3.
************************Sheet Number
PERFORM ERR_HDL.
* Activate (select) the first sheet
CALL METHOD OF H_SHEET 'ACTIVATE'.
PERFORM ERR_HDL.
* tell user what is going on
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
* PERCENTAGE = 0
TEXT = 'Adding Data to Excel...'
EXCEPTIONS
OTHERS = 1.
* output column headings to active Excel sheet
V_STEP = 'Adding data to Excel'.
LOOP AT ITAB.
V_COL = SY-TABIX.
PERFORM FILL_CELL USING 1 V_COL ITAB-vbeln.
PERFORM FILL_CELL USING 2 V_COL ITAB-posnr.
ENDLOOP.
V_STEP = 'Releasing Excel'.
FREE OBJECT H_EXCEL.
PERFORM ERR_HDL.
H_EXCEL-HANDLE = -1.
*&---------------------------------------------------------------------*
*& Form ERR_HDL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
*----------------------------------------------------------------------*
FORM ERR_HDL.
IF SY-SUBRC <> 0.
WRITE: / 'Error in processing Excel File:', V_STEP.
STOP.
ENDIF.
ENDFORM. " ERR_HDL
*&---------------------------------------------------------------------*
*& Form FILL_CELL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_1 text
* -->P_1 text
* -->P_1 text
*----------------------------------------------------------------------*
FORM FILL_CELL USING ROW COL VAL.
CALL METHOD OF H_EXCEL 'Cells' = H_CELL
EXPORTING #1 = ROW #2 = COL.
PERFORM ERR_HDL.
SET PROPERTY OF H_CELL 'Value' = VAL .
PERFORM ERR_HDL.
ENDFORM. " FILL_CELL
2006 Mar 01 4:23 AM
U can use 'GUI_DOWNLOAD' to download data from internal tables to any file.
to upload from excel to internal table, u can use GUI_UPLOAD OR 'ALSM_EXCEL_TO_INTERNAL_TABLE'.
PS: pls dont use (urgent) in ur subject, which is in one of the rules. u can read the rules which is the 2nd post in first page
2006 Mar 01 4:25 AM
Hi seema,
1. I have to upload data from 5 internal tables
Is it necessary to upload ALL
5 internal tables in ONE excel file only?
2. Bcos it will include ole technology
and is a little cumbersome.
3. I personally prefer to use
GUI_DOWNLOAD
and make 5 files (with the name of internal table itself)
These files will be , by default,
tab delimited,
and can be opened in excel.
regards,
amit m.
2006 Mar 01 5:23 AM
HI
YOU CAN USE THE FM <u>GUI_DOWNLOAD</u> to DOWNLOAD INTERNAL TABLE TO xl sheetS.
OR
GO THROUGH THE GIVEN LINK ON <u>code for create a multiple sheet Excel document:</u>
<a href="http://www.sapdevelopment.co.uk/ms/ms_excel.htm">http://www.sapdevelopment.co.uk/ms/ms_excel.htm</a>
IF THESE FIND USEFUL PLEASE REWARD POINTS.
REGARDS,
ANOOP
2006 Mar 01 6:33 AM
Hi,
You can use a Function Module EXCEL_OLE_STANDARD_DAT also to upload internal table to Excel .
Here are some of the parameters:
file_name: Name and path of the Excel worksheet file e.g. 'C:\TEMP\ZTEST'
data_tab: Name of the internal table that should be uploaded to Exvcel
fieldnames: Internal tabel with column headers
Cheers
Sunny
Rewrd points, if helpful
2006 Mar 01 6:56 AM
Hai seema,
i think this will work out...<b>'SAP_CONVERT_TO_XLS_FORMAT'</b>
Here is an example
REPORT ZCONVERTTOXLS .
parameters: p_file like rlgrap-filename default 'c:\tmp\test.xls'.
data: itab like t001 occurs 0 with header line.
select * from t001 into table itab.
CALL FUNCTION 'SAP_CONVERT_TO_XLS_FORMAT'
EXPORTING
I_FILENAME = p_file
TABLES
I_TAB_SAP_DATA = itab
.
Regards
Srikanth.
Please reward points if it is useful.Thanks in advance
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |