SAP Database - The Unofficial SAP Knowledge Base

Free Business and Tech Magazines and eBooks

ABAP Program: Sample program for OLE Automation

Print This Post Email This Post Written by admin on Feb 6th, 2008 | Filed under: ABAP Programs

REPORT ZSOURCE2801.
* Including OLE types
INCLUDE OLE2INCL.
* Tables and variables for later use
TABLES: CUSTOMERS.
DATA: APPLICATION TYPE OLE2_OBJECT,
WORKBOOK TYPE OLE2_OBJECT,
SHEET TYPE OLE2_OBJECT,
CELLS TYPE OLE2_OBJECT.

* Creating an object
CREATE OBJECT APPLICATION 'excel.application'.
IF SY-SUBRC NE 0.
WRITE: / 'Error when opening excel.application', SY-MSGLI.
ENDIF.
* Setting properties
SET PROPERTY OF APPLICATION 'Visible' = 1.
* Calling methods
CALL METHOD OF APPLICATION 'Workbooks' = WORKBOOK.
PERFORM ERRORS.
CALL METHOD OF WORKBOOK 'Add'.
PERFORM ERRORS.
CALL METHOD OF APPLICATION 'Worksheets' = SHEET EXPORTING #1 = 1.
PERFORM ERRORS.
CALL METHOD OF SHEET 'Activate'.
PERFORM ERRORS.
PERFORM FILL_SHEET.

* Subroutine for filling the spread sheet
FORM FILL_SHEET.
DATA: ROW_MAX TYPE I VALUE 256,
INDEX TYPE I.
FIELD-SYMBOLS: <NAME>.
SELECT * FROM CUSTOMERS.
INDEX = ROW_MAX * ( SY-DBCNT - 1 ) + 1.
DO 4 TIMES.
ASSIGN COMPONENT SY-INDEX OF STRUCTURE CUSTOMERS TO <NAME>.
CALL METHOD OF SHEET 'Cells' = CELLS
EXPORTING #1 = INDEX.
SET PROPERTY OF CELLS 'Value' = <NAME>.
ADD 1 TO INDEX.
ENDDO.
ENDSELECT.
ENDFORM.
* Subroutine for error handling
FORM ERRORS.
IF SY-SUBRC NE 0.
WRITE: / 'Error in OLE call', SY-MSGLI.
EXIT.
ENDIF.
ENDFORM.

If you like this post, you may as well like these too:

  1. ABAP Programs:Sample dialog program (flight reservation) * This program source contains all modules and subroutines of the * flight reservation program, but screen and GUI status definitions * are not included. *&———————————————————————* *&———————————————————————* *& Include MSABBTOP...
  2. ABAP Sample Codes Download a huge collection of  on: ABAP Code Sample Business Scenario For PerFormance Issues Of HR Positions Holders ABAP Code Sample CAPTCHA For BSP Application s ABAP Code Sample Data...
  3. ABAP Programs: Sample report with selection criteria REPORT ZSOURCE1801. TABLES: CUSTOMERS, BOOKINGS. PARAMETERS P_DATE TYPE D. SELECT-OPTIONS S_NAME FOR CUSTOMERS-NAME. SELECT * FROM CUSTOMERS WHERE NAME IN S_NAME. WRITE / CUSTOMERS-NAME. SELECT * FROM BOOKINGS WHERE ORDER_DATE...
  4. SAP Automation Tools SAP Automation Tools are set of tools, components and class libraries for developers to integrate non-SAP systems with SAP systems. There are two tool sets available for SAP Automation. SAP...
  5. Call an ABAP program from a BSP Call an ABAP program from a BSP is somehow impossible due to memory context handling for a web transaction like a BSP. If you try, it would lead to an...



This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

Leave a Reply

  • Subscribe to RSS

  • Free Ebooks