ABAP/4 OLE Automation Controller

Release 4.6C

HELP.BCFESDE6

ABAP/4 OLE Automation Controller

SAP AG

Copyright
© Copyright 2001 SAP AG. All rights reserved. No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice. Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors. Microsoft , WINDOWS , NT , EXCEL , Word , PowerPoint and SQL Server are registered trademarks of Microsoft Corporation. IBM , DB2 , OS/2 , DB2/6000 , Parallel Sysplex , MVS/ESA , RS/6000 , AIX , S/390 , ® ® ® AS/400 , OS/390 , and OS/400 are registered trademarks of IBM Corporation. ORACLE is a registered trademark of ORACLE Corporation. INFORMIX -OnLine for SAP and Informix Dynamic Server Informix Software Incorporated.
® ® ® ® ® ® TM ® ® ® ® ® ® ® ® ® ® ® ® ® ® ® ® ®

are registered trademarks of

UNIX , X/Open , OSF/1 , and Motif are registered trademarks of the Open Group. HTML, DHTML, XML, XHTML are trademarks or registered trademarks of W3C , World Wide Web Consortium, Massachusetts Institute of Technology. JAVA is a registered trademark of Sun Microsystems, Inc. JAVASCRIPT is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape. SAP, SAP Logo, R/2, RIVA, R/3, ABAP, SAP ArchiveLink, SAP Business Workflow, WebFlow, SAP EarlyWatch, BAPI, SAPPHIRE, Management Cockpit, mySAP.com Logo and mySAP.com are trademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. All other products mentioned are trademarks or registered trademarks of their respective companies.
® ® ®

2

April 2001

SAP AG ABAP/4 OLE Automation Controller Icons Icon Meaning Caution Example Note Recommendation Syntax April 2001 3 .

........................................................................................................................................................................................................................................................................................................................................... 11 Using The OLE Object Browser ....... 7 Registering External Applications in R/3. 19 GET PROPERTY ...................................................................................ABAP/4 OLE Automation Controller SAP AG Contents ABAP OLE Automation Controller ........................................................................................................................................................................................................................................... 15 Related ABAP Keywords ....5 ABAP As OLE Automation Controller.................................................................................................................................. 10 Conversion Rules........................................ 13 Examples............................................................................ 18 SET PROPERTY....................... 6 Introduction............................................................................................................................... 23 FREE OBJECT ................................................................................................................................. 17 CREATE OBJECT .............. 12 Implementation ................................... 8 Loading OLE Type Information into R/3 For Conversion...................................... 14 R/3 As OLE Automation Server..................................................................... 21 CALL METHOD ..................................... 25 4 April 2001 .............................................................................................................................................................................................................................................................................................................................................................................................................................. 16 Introduction..............................................................

SAP AG ABAP/4 OLE Automation Controller ABAP OLE Automation Controller ABAP OLE Automation Controller April 2001 5 .

see the example in the corresponding unit of the Tutorial: Communication Interfaces [Ext.ABAP/4 OLE Automation Controller ABAP As OLE Automation Controller SAP AG ABAP As OLE Automation Controller The ABAP programming language supports the OLE2 Automation technique. Desktop applications supporting OLE2 can be thus be called from R/3. Overview of Topics Introduction [Page 7] Registering External Applications in R/3 [Page 8] Loading OLE Type Information into R/3 For Conversion [Page 10] Conversion Rules [Page 11] Using The OLE Object Browser [Page 12] Implementation [Page 13] Examples [Page 14] R/3 As OLE Automation Server [Page 15] Related ABAP Keywords [Page 16] For an introduction to this technique. 6 April 2001 .].

the SAPGUI acts as OLE client. ABAP supports the OLE2 Automation technique. All applications controlled by ABAP must be registered in R/3. and the desktop application as the OLE server.SAP AG ABAP/4 OLE Automation Controller Introduction Introduction Through its Open Object Interface. Application Server Frontend SAP GUI ABAP Program RFC OLE Client OLE2 Automation OLE-specific keywords in ABAP Application OLE Server April 2001 7 . Desktop applications that provide their functionality in the form of an OLE2 Automation Server (such as Excel or WinWord) can be thus be integrated into R/3. The following ABAP key words control the applications: · · · · · CREATE OBJECT SET PROPERTY GET PROPERTY CALL METHOD FREE OBJECT When called from an ABAP program.

The key of TOLE (OLE application) is used as object class name in the CREATE-statement. The Typeinfo describes all the objects that a particular application can handle. The Type Library of an OLE application partly has its own CLSID. ® OLE2 ® Configuration (transaction SOLE). the typeinfo is stored in the database. · Include program Include program with constants definitions. · CLSID LibType OLE class-ID in character format. · OLE object name The name of the first OLE object that is created. Version number If several versions of an OLE application exist. · Language The language of the following text. · Typeinfo key Key for Typeinfo of an OLE application. Under this key. · CLSID OLE class identification in character format as specified in the registration database on the presentation host. The CLSID number is sent to the frontend. This entry is currently used for documentation and reference purposes only. NO_TYPELIB indicates that you do not want to use typeinfo for this application. select Details and the view “Maintenance view for OLE applications: Details” with the following fields is displayed: · · OLE application The application name determines the object class when an object is generated. Include program has to be maintained manually. Table TOLE also indicates whether type information (Typeinfo) exists for an application. Each entry contains all information needed to generate an OLE object. In order to maintain table TOLE select Development ® Programming environ. the version numbers of the OLE applications and class-IDs in character format.ABAP/4 OLE Automation Controller Registering External Applications in R/3 SAP AG Registering External Applications in R/3 All applications controlled by ABAP must be entered in the table TOLE in the ABAP Development Workbench. This field is used in the Object Browser only. 8 April 2001 . The view “Maintenance view for OLE applications: Overview” displays information on the OLE application names. including all its methods. If you want to see more specific information. use the version number from the registration database on the presentation server to distinguish between the various versions. properties and parameters.

April 2001 9 .SAP AG ABAP/4 OLE Automation Controller Registering External Applications in R/3 · Text Description of an OLE application.

10 April 2001 . an ABAP program can use methods and property names in any language for which type information has been loaded. the English version is delivered in the table OLELOAD. The ABAP processor can thus perform the necessary type conversions and is not dependent on the language of the OLE application. i. The view “TypeInfo Loaded” is displayed with the following information: · · · · Application Version CLSID of application CLSID of object library With “Load Typeinfo” a part of the typelib is loaded into SAP’s database. If an OLE server has no Typeinfo. ® OLE2 ® Load Typeinfo (transaction SOLI).ABAP/4 OLE Automation Controller Loading OLE Type Information into R/3 For Conversion SAP AG Loading OLE Type Information into R/3 For Conversion You can load the type information from the presentation server into table OLELOAD of the R/3 System (in the ABAP Development Workbench). To do this select Development ® Programming environ. For all OLE applications used by SAP standard applications. it can still be processed by ABAP. and can still process applications that have been installed in another language.e. This is only possible if the application in question is loaded on your PC. but the names of the methods and properties have to be in the same language as the language in which the frontendapplication is installed.

conversion is always via character type: The ABAP-type is converted into CHAR according to ABAP-conventions. Afterwards. April 2001 11 .SAP AG ABAP/4 OLE Automation Controller Conversion Rules Conversion Rules When passing parameters. it is set according to the ABAP type as follows: ABAP types I P. the maximum length of character variables is restricted to 255. With some objects the semantics of the parameters depends on the OLE type (see the documentation of the server application). or if the OLE type is undefined. the CHAR is converted into OLE by using the corresponding OLE types: ABAP-Type ® CHAR ® OLE type Without Typeinfo.F D T otherwise OLE types Int Double Date Time Character At present.

There are no initial entries delivered by SAP.ABAP/4 OLE Automation Controller Using The OLE Object Browser SAP AG Using The OLE Object Browser The Object Browser provides a list of OLE applications with loaded Typeinfo in English. Then you can invoke its methods or read and write its properties. You can also create an OLE application interactively within the Object Browser. This information has to be loaded by the customer. 12 April 2001 . The results of each call are displayed directly. ® OLE2 ® Object Browser (transaction SOLO). Select Development ® Programming environ. This information is stored in table INDX.

The commands CALL METHOD [Page 23]. The implementation is realized by means of the ABAP keywords CREATE OBJECT and FREE OBJECT (which call the function modules CREATE_OBJECT and FREE_OBJECT) and C functions which are written as RFC Server programs. GET PROPERTY [Page 21] and SET PROPERTY [Page 19] are bundled on the application server and passed to the SAPGUI function OLE_FLUSH_CALL in the form of an internal table. April 2001 13 . The SAPGUI contains special OLE functions which you can address from ABAP programs with normal RFC calls (destination ‘SAPGUI’).SAP AG ABAP/4 OLE Automation Controller Implementation Implementation Communication between the applications server and the frontend is via the RFC interface. From an OLE point of view. In CREATE OBJECT [Page 18]. the ABAP processor reads the relevant entry in the table TOLE and uses the found OLE class-ID to call the function OLE_CREATE_OBJECT at the frontend via RFC. the SAPGUI represents the actual OLE client. besides the OLE call. also releases all resources retrieved for this object at the frontend. Then the functions that are necessary for generating an OLE object are called from the Windows OLE library and an object handle is returned to the ABAP processor. FREE OBJECT [Page 25] calls the SAPGUI function OLE_RELEASE_OBJECT which. Reading the Typeinfo is also implemented via an RFC call to the SAPGUI.

ABAP/4 OLE Automation Controller Examples SAP AG Examples Examples and OLE demonstrations are available in WinWord. Select Development ® Programming environ. 14 April 2001 . Excel and Visio. ® OLE2 ® Demo (transaction OLE) in the ABAP Development Workbench. Three OLE servers can be activated using transaction OLE and numerous methods and properties tested by selecting the appropriate pushbuttons: For a simple program example. see the Tutorial: Communication Interfaces [Ext.].

the server program RFCSRV. This means that all function modules which can be called remotely can be called by any OLE Automation Controller.].SAP AG ABAP/4 OLE Automation Controller R/3 As OLE Automation Server R/3 As OLE Automation Server In contrast to ABAP as an OLE Automation Controller. To do this. R/3 also offers some of its functionality as an Automation Server. see the example in the corresponding unit of the Tutorial: Communication Interfaces [Ext. April 2001 15 . For an introduction to this technique.EXE must be installed on the frontend.

ABAP/4 OLE Automation Controller Related ABAP Keywords SAP AG Related ABAP Keywords Introduction [Page 17] CREATE OBJECT [Page 18] SET PROPERTY [Page 19] GET PROPERTY [Page 21] CALL METHOD [Page 23] FREE OBJECT [Page 25] 16 April 2001 .

the command set of the ABAP interpreter has been enhanced to include key words that allow the application programmer to process external objects. ABAP keywords allow you to control all applications with functionality in the form of an OLE2 Automation Server from an ABAP program: Examples of such applications are the Microsoft products EXCEL or WinWord. OLE2 was supported as the first object model. For further information about OLE2. April 2001 17 .SAP AG ABAP/4 OLE Automation Controller Introduction Introduction From R/3 Release 3.0. refer to OLE2 in the online help (ABAP Editor).

CREATE OBJECT belongs to a group of key words that allows you to process external objects with ABAP. The frontend ports of SAP’s OLE implementation modules are implemented only under Windows and Apple Macintosh. At present. The transaction SOLE (see Registering External Applications in R/3 [Ext. Basic form: Addition: CREATE OBJECT obj class. i. Related topics are SET PROPERTY [Page 19]. If no specification is made. English is the default. The CREATE statement generates the initial object of this class and this can be processed further with the related key words. GET PROPERTY [Page 21]. SY-SUBRC = 4: The object is not registered with SAP. The return code value can be as follows: · · · SY-SUBRC = 0: Object successfully generated. only the object model OLE2 is supported. the server must be registered with SAP.Application'. EXCEL) from ABAP. DATA EXCEL TYPE OLE2_OBJECT. 18 April 2001 .possibly a storage space problem. all objects must be of type OLE2_OBJECT. LANGUAGE langu To address an OLE Automation Server (e. The addition LANGUAGE determines the language chosen for method and attribute names of the object class.]) allows you to assign an automation server to a class. The return code value of SY-SUBRC indicates the result of the generation.g. Generate an EXCEL object.ABAP/4 OLE Automation Controller CREATE OBJECT SAP AG CREATE OBJECT The ABAP key word CREATE OBJECT generates an object of the class “class”.e. · · SY-SUBRC = 3: The OLE-API call resulted in an error . CALL METHOD [Page 23] and FREE OBJECT [Page 25]. INCLUDE OLE2INCL. SY-SUBRC = 1: SAPGUI communication error. SY-SUBRC = 2: SAPGUI function call error. CREATE OBJECT EXCEL 'Excel. This type and other necessary data are defined in the INCLUDE module OLE2INCL.

however. The addition NO FLUSH continues the collection process. · · · SY-SUBRC = 2: A method call resulted in an error. i. Also. SY-SUBRC = 1: When communicating with the presentation server. all consecutive OLE statements are buffered by the ABAP processor and sent to the presentation server in bundled form. programmers must ensure that they do not rely on the contenst of return parameters that are not yet filled. you should remember that the values of the return parameters cannot be displayed until directly before execution of the first ABAP non-OLE statement. for example. This means.e. But it is still possible for a statement to refer to the results of preceding statements.SAP AG ABAP/4 OLE Automation Controller SET PROPERTY SET PROPERTY The ABAP key word SET PROPERTY sets the property p of the object obj according to the contents of the field f. SY-SUBRC = 4: Reading a property resulted in an error. In debugging. The field SY-MSGLI contains a short description of the error. all objects must be initialized in a bundle. all objects must be of type OLE2_OBJECT. NO FLUSH Normally. i. Basic form: Addition: SET PROPERTY OF obj p = f. The return code value of SY-SUBRC indicates whether all the bundled commands have been successfully executed. In the last 3 cases. The object obj must be of type OLE2_OBJECT. Every FREE statement always causes an exchange of the buffer. April 2001 19 .e. a dialog box containing an error note is displayed on the presentation server. At present. that a series of properties can be set in a loop and downloaded to the presentation server in a single transport operation. only the object model OLE2 is supported. The return code value can be as follows: · · SY-SUBRC = 0: All commands were successfully executed. they must be generated by an OLE call that has already been executed. a system error occurred. SET PROPERTY belongs to a group of key words that allows you to process external objects with ABAP. SY-SUBRC = 3: Setting a property resulted in an error. This type and other necessary data are defined in the INCLUDE module OLE2INCL. even if the next command is not an OLE statement. If NO FLUSH is used. A command that refers to an object not yet generated by any OLE statement terminates the automatic bundling.

20 April 2001 . CREATE OBJECT EXCEL 'Excel. DATA EXCEL TYPE OLE2_OBJECT. CALL METHOD [Page 23] and FREE OBJECT [Page 25].ABAP/4 OLE Automation Controller SET PROPERTY SAP AG Sets the property 'Visible' of an EXCEL worksheet. Related topics are: CREATE OBJECT [Page 18].Application'. GET PROPERTY [Page 21]. SET PROPERTY OF EXCEL 'Visible' = 1. INCLUDE OLE2INCL.

for example. i.SAP AG ABAP/4 OLE Automation Controller GET PROPERTY GET PROPERTY The ABAP key word GET PROPERTY copies the property p of the object obj to the field f. Normally. programmers must ensure that they do not rely on the contenst of return parameters that are not yet filled. Also. all consecutive OLE statements are buffered by the ABAP processor and sent to the presentation server in bundled form. SY-SUBRC = 4: Reading a property resulted in an error. This means. At present. The return code value can be as follows: · · SY-SUBRC = 0: All commands were successfully executed. If NO FLUSH is used. Basic form: GET PROPERTY OF obj p = f.e. even if the next command is not an OLE statement. Read the property 'Visible' of an EXCEL worksheet: April 2001 21 . SY-SUBRC = 1: When communicating with the presentation server. that a series of properties can be set in a loop and downloaded to the presentation server in a single transport operation. all objects must be initialized in a bundle. only the object model OLE2 is supported. SY-SUBRC = 3: Setting a property resulted in an error. A command that refers to an object not yet generated by any OLE statement terminates the automatic bundling. The return code value of SY-SUBRC indicates whether all the bundled commands have been successfully executed. GET PROPERTY belongs to a group of key words that allows you to process external objects with ABAP. The object obj must be of type OLE2_OBJECT. The addition NO FLUSH continues the collection process. In debugging. you should remember that the values of the return parameters cannot be displayed until directly before execution of the first ABAP non-OLE statement. But it is still possible for a statement to refer to the results of preceding statements. Every FREE statement always causes an exchange of the buffer.e. In the last 3 cases. all objects must be of type OLE2_OBJECT. a system error occurred. This type and other necessary data are defined in the INCLUDE module OLE2INCL. The field SY-MSGLI contains a short description of the error. i. · · · SY-SUBRC = 2: A method call resulted in an error. they must be generated by an OLE call that has already been executed. a dialog box containing an error note is displayed on the presentation server. however.

CALL METHOD [Page 23] and FREE OBJECT [Page 25]. CREATE OBJECT [Page 18].ABAP/4 OLE Automation Controller GET PROPERTY INCLUDE OLE2INCL. GET PROPERTY OF EXCEL 'Visible' = VISIBLE. CREATE OBJECT EXCEL 'Excel.Application'. 22 April 2001 . VISIBLE TYPE I. DATA: EXCEL TYPE OLE2_OBJECT. Related topics are: SAP AG SET PROPERTY [Page 19].

SY-SUBRC = 3: Setting a property resulted in an error. only the object model OLE2 is supported. you should remember that the values of the return parameters cannot be displayed until directly before execution of the first ABAP statement external to OLE.. This type and other necessary data are defined in the INCLUDE module OLE2INCL.. = f April 2001 23 . The return code value of SY-SUBRC indicates whether all the bundled commands have been successfully executed. all objects must be of type OLE2_OBJECT. Additions · Addition 1 . m can be a literal or a variable.. all consecutive OLE statements are buffered by the ABAP processor and sent to the presentation server in bundled form.. In the last 3 cases.e. = f 2. CALL METHOD belongs to a group of key words that allows you to process external objects with ABAP... The return code value can be as follows: · · SY-SUBRC = 0: All commands were successfully executed. At present. In debugging. . · · · SY-SUBRC = 2: A method call resulted in an error. a system error occurred.. The field SY-MSGLI contains a short description of the error. Basic form: Additions: 1. pn = fn 3. EXPORTING p1 = f1. a dialog box containing an error note is displayed on the presentation server. SY-SUBRC = 1: When communicating with the presentation server. Normally.SAP AG ABAP/4 OLE Automation Controller CALL METHOD CALL METHOD The ABAP key word CALL METHOD calls the method m of the object obj. i.. CALL METHOD OF obj m. This means that it is possible for a statement to refer to the results of preceding statements. Even a command that refers to an object not yet generated by any OLE statement terminates the bundling. NO FLUSH. however. SY-SUBRC = 4: Reading a property resulted in an error. .

.Application'.. programmers must ensure that they do not rely on the contenst of return parameters that are not yet filled. Related topics are: SET PROPERTY [Page 19].. GET PROPERTY [Page 21]. p1. This means. CALL METHOD OF WORKBOOK 'Open' EXPORTING #1 = 'C:\EX1. At present. If assignment of parameters is by sequence. i. are either key word parameters or position parameters. · Addition 3 . EXPORTING p1 = f1. even if the next command is not an OLE statement... followed by the position number of the parameter. must begin with "#"... Also. CALL METHOD OF EXCEL 'WORKBOOKS' = WORKBOOK..e. 24 April 2001 .. Open an EXCEL file with the method 'Open': INCLUDE OLE2INCL. p2. p2. that a series of properties can be set in a loop and downloaded to the presentation server in a single transport operation. p1. only position parameters are supported.. NO FLUSH. DATA WORKBOOK TYPE OLE2_OBJECT. · Addition 2 .ABAP/4 OLE Automation Controller CALL METHOD SAP AG Stores the return value of the method in the variable f. for example. CREATE OBJECT [Page 18] and FREE OBJECT [Page 25]. DATA EXCEL TYPE OLE2_OBJECT. The exporting parameters always come at the end of the statement. If NO FLUSH is used.. pn = fn EXPORTING passes values of fields to the parameters of the method.XLS'. The addition NO FLUSH continues the collection process. CREATE OBJECT EXCEL 'Excel. The return value can also be of type OLE2_OBJECT. all objects must be initialized in a bundle. Every FREE statement always causes a download of the buffer. This addition must always come before other additions.. they must be generated by an OLE call that has already been executed.

Application'. This type and other necessary data are defined in the INCLUDE module OLE2INCL. Related topics are: SET PROPERTY [Page 19]. Release an EXCEL object: INCLUDE OLE2INCL. SY-SUBRC = 1: SAP GUI communication error. GET PROPERTY [Page 21]. · · · SY-SUBRC = 0: Object successfully released.e. FREE OBJECT EXCEL.SAP AG ABAP/4 OLE Automation Controller FREE OBJECT FREE OBJECT The ABAP key word FREE OBJECT releases the storage space required for the object obj. SY-SUBRC = 2: Error when calling function in SAP GUI. April 2001 25 . all objects must be of type OLE2_OBJECT. DATA: EXCEL TYPE OLE2_OBJECT. CREATE OBJECT EXCEL 'Excel. The OLE function modules are only implemented under Windows. FREE OBJECT belongs to a group of key words that allows you to process external objects with ABAP. The object can then no longer be processed. CALL METHOD [Page 23] and CREATE OBJECT [Page 18]. only the object model OLE2 is supported. At present. The return value of SY-SUBRC specifies whether the desired object was released or not. i.

Sign up to vote on this title
UsefulNot useful