ABAP Program: Sample program for OLE Automation
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:
- 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...
- 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...
- 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...
- 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...
- Generate Temporary ABAP Program Ever had a need to create a temporary program during the run time. Here is a simple program which will allow you to learn that. REPORT ZSOURCE2501. * Internal table...
- SAP ABAP Program Types Each ABAP program has a type, which is defined in the program attributes. What is the purpose of all the different program types? The program type determines which processing blocks...
- Create a Program in SAP ABAP You can navigate to the ABAP Editor through the Menu. You can also create favorites for certain transactions and put it into your custom menu. You can type SE38 from...
- 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...
- ABAP Program:Reading data from a file REPORT ZSOURCE2602. * Data declarations for later use TABLES CUSTOMERS. PARAMETERS FILENAME(128) DEFAULT '/usr/tmp/testfile.dat' LOWER CASE. DATA: MSG_TEXT(50), ALL_CUSTOMER_NAMES LIKE CUSTOMERS-NAME OCCURS 100 WITH HEADER LINE. * Opening the File...
- ABAP Program : Working with Temporary Programs Ever had a need to create a temporary program during the run time. Here is a simple program which will allow you to learn that. REPORT ZSOURCE2501. * Internal table...
- ABAP Program to Send Mail with Attachment This ABAP program use the function module ‘SO_NEW_DOCUMENT_ATT_SEND_API1′ to send the email with attachment. There are five steps involved in sending the email with attachment. Add Recipients Put in the...
- ABAP Program to Send External Mail from SAP Here is a ABAP program which would allow you to send mail to any external system from SAP. Ensure that you have all the required configurations done by the basis...
- ABAP Program:Transferring data to a file (presentation server) REPORT ZSOURCE2603. * Data declarations for later use PARAMETERS FILENAME(128) DEFAULT 'c:usersdefaulttestfile.dat' LOWER CASE. TABLES CUSTOMERS. DATA ALL_CUSTOMERS LIKE CUSTOMERS OCCURS 100 WITH HEADER LINE. * Get data for file...
- Sample SAP Exam Questions Want to check out sample SAP Exam questions? Follow the link on SAP Education: Exam Preparation. This contains the sample exam questions on lots of areas....
- ABAP Program: Dynamic external perform (call back form) Here the two programs which are calling dynamically. REPORT ZSOURCE2309. PERFORM EXTFORM IN PROGRAM ZSOURCE2310 USING 'CALL_BACK_FORM' SY-CPROG. FORM CALL_BACK_FORM. WRITE / 'I am the call back form in ZSOURCE2309.'....



















Leave a Reply