Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Want to know a function module(urgent)

Former Member
0 Likes
764

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.

6 REPLIES 6
Read only

Former Member
0 Likes
736
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
Read only

hymavathi_oruganti
Active Contributor
0 Likes
736

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

Read only

Former Member
0 Likes
736

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.

Read only

Former Member
0 Likes
736

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

Read only

0 Likes
736

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

Read only

Former Member
0 Likes
736

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