Você está na página 1de 6

Connecting OLE-compatible Office Applications to the R/3 System

http://www.erpgenie.com/sap/abap/ole.htm

Enterprise Resource Planning Portal

THE ultimate ERP website


Forums | SAP Top Sites |

Advertise | Founder BLOG

-1808
Web ERPGenie.COM WorkflowGenie.COM Other Search Options

ERPGenie Menu

Consultant Corner

Client Corner

ERP Related Websites

SAP Related Menu

ERPGenie.COM -> SAP Technical -> ABAP -> Tips and Tricks -> Connecting OLE-compatible Office Applications to the R/3 System

See our ABAP Tips and Tricks Database


Quicklinks
File Processing TextEdit Control

SAP Exchange Connector WAS - Web Application Server

Aim: To connect any OLE-compatible application, running under Windows 95/NT to the R/3 System,

Who needs ABAPers??? The functional person's tool for stress testing and data conversions.. Siamease is an easy to use tool that allows you to migrate data, upload data, stress test, and much more and you don't need4.0. to know any Release ABAP

This will be implemented as a SAPgui control, using the SAPgui Control Framework and the SAP Data Provider. The primary objective is the optimal connection of Microsoft Office 97 to the R/3 System, by taking advantage of the many benefits of the OLE architecture. It will also be possible to use Microsoft Office 95 with only a few restrictions, as well as OLE2-compatible office applications from other suppliers.

Introduction to OLE
OLE Automation
When we talk about OLE-compatible programs, we often really mean OLE automation. However, automation actually has nothing to do with OLE, except for the fact that most OLE-compatible programs use it. Microsoft developed automation in their Visual Basic and macro languages for Office applications. In this paper, OLE compatibility means Object Linking and Embedding. This does not mean, however, that this concept does not use automation. Indeed, using automation makes the concept easier and more transparent, using OLE as its basis.

OLE: Object Embedding


OLE is an interface, developed by Microsoft, which allows you to insert external objects (Microsoft calls them embedded documents) into your documents. The classic example of this is an Excel table, which you include in a Word document. When you double-click on the table, the system starts Excel. You can then edit the table. When you subsequently close Excel, the data is saved directly in the Word document. To make it possible to save external data within a document, Microsoft developed a new file format and several COM interfaces, which together are known as OLE Compound Documents. These are a kind of file system within a file, allowing different applications to save their own data independently in a single file. Object embedding does not only define how data is stored within a file, but also the way in which external objects are linked

1 of 6

14-Dec-13 1:00 PM

Connecting OLE-compatible Office Applications to the R/3 System

http://www.erpgenie.com/sap/abap/ole.htm

into a document and how the external applications open and process them. The latter is particularly useful to us. The document- and object-centered approach is at the center of the concept that we are presenting here.

OLE: Object Linking


Object linking is an extension of Microsofts own DDE interface. Object linking differs from object embedding in that only the links to other objects are stored in the file. For example, we could insert a link to the Excel table from our above example. In this case, the table itself would be stored in a different file. This concept takes on a new dimension if we use links not to files, but to server programs. For example, we could use an OLE link to a stock price program which would allow us to see the up-to-date SAP stock price as an Excel chart. Object linking has many strengths. It supports a wide range of file formats (text, RTF, bitmaps, metafiles) and can easily be extended using its own format. Last but not least, it is significantly quicker than automation when processing large quantities of data.

OLE: In-place Activation


In the above, we have assumed that OLE applications run in their own window. Our concept makes it possible to activate OLE applications in-place . This will require only minimal changes to ABAP programs. You will have to make room for the document window on the screen, and set the position and dimensions of the SAP OLE control accordingly.

Basics
Unlike previous connections to Office applications, this concept uses the new features offered by the Control Framework as of R/3 Release 4.0. Instead of using RFC as a protocol and the RFC server as the R/3 contact, it uses the Control Framework and SAPgui controls. This means that the programming model has changed completely. Previously, the ABAP program was blocked for the duration of the RFC call and the document editing. Communication between Office applications and R/3 took place using RFC callbacks. In the new model, processing in ABAP and at the front end is parallel. The R/3 transaction will be able to accept user input once it has opened the document. It is now even possible to use the Control Framework to pass events triggered in the Office application by user input or macros back to the ABAP program. These are then processed in the PAI phase. OLE dictates that it will be necessary to implement several COM objects. The main function will be a SAPgui control, which we suggest will be called the SAP OLE Container Control.

Basic Architecture
The infrastructure of a connection to an OLE-compatible application consists of three areas, each of them largely independent. They can be partially implemented without OLE to produce a limited range of functions for other operating systems. The implementation of these areas is transparent for ABAP programs. 1. Application control: Starts and closes an application; transports document data; opens, processes, saves, prints and closes documents. 2. Document control and communication between applications and R/3: Controls an application using automation or DDE (ex. Find and replace, attaching templates, inserting text modules, calling macros); this also includes the possibility of triggering an event in an Office application which can then be processed in the controlling ABAP program. 3. Document templates and merging R/3 data: Documents are seen as templates, and references are inserted using OLE links. These are replaced with data when the document is displayed (for example, a link to a processing number in a letter). The following sections use Microsoft Word as a sample application. However, unless explicitly stated otherwise, the examples apply to any OLE-compatible application.

Application Control

2 of 6

14-Dec-13 1:00 PM

Connecting OLE-compatible Office Applications to the R/3 System

http://www.erpgenie.com/sap/abap/ole.htm

The following shows the conventional way of starting applications and opening documents. The document data is written to a temporary file, then the application is started. The name of the document to be edited is passed either as a command line parameter or using DDE. This has the following advantages and disadvantages: + + portable: works on all platforms with almost any application can mean less main memory is required works differently for each application configuration is more difficult, since the path for the application must be known requires write authorization at the front end for writing temporary files extensive macro programming is necessary to send a message back to R/3 when the document or application is closed integration and stability are minimal if the user uses the application incorrectly

Using OLE enables us to eliminate nearly all of the above disadvantages. + + Applications are localized and started by OLE OLE opens the documents: the changes are saved directly in an internal table. This means that no temporary files are necessary (although they are possible). + All OLE-compatible applications work in the same way. There will be no need to adapt to future versions of Microsoft Office. + OLE sends a message to the SAP Container Control and on to the R/3 System when the document is closed. + A high degree of integration and stability. Restricted to OLE and Windows environment. More main memory required. Two copies of the document data are stored in main memory while you are editing the file. When you save, there may even be three copies.

Document Control and Communication Between Applications and R/3

3 of 6

14-Dec-13 1:00 PM

Connecting OLE-compatible Office Applications to the R/3 System

http://www.erpgenie.com/sap/abap/ole.htm

OLE only defines how documents are opened, edited and saved. Further communication between the controlling program and the Office application is the job of automation or DDE. Thanks to macro languages and, more recently, VBA (Visual Basic for Applications), you can control documents and call macros externally. When you use OLE to open a document, a COM interface pointer is generated which points to the open document (this also occurs with other concepts which do not use OLE). You can then use this pointer to get a pointer to the document automation interface. You can then control the document using VBA commands. The advantages of the concept can be seen when you want to send events to the ABAP program. The OLE protocol ensures that a pointer to a container is passed when you open a document in an OLE application. You can then access the pointer in VBA using the container property of the opened document. The container object, implemented by the SAP OLE Container Control, contains methods and properties which can be used to communicate with the controlling ABAP program. Calling from a VBA macro is very easy: Application.ActiveDocument.Container.SendCustomEvent(TESTEVENT) In the events, you can send up to 12 freely-definable parameters which you can then query in the PAI block of an R/3 transaction. While OLE has a clear, standardized protocol, application control using automation or DDE is not at all standardized. Even VBA could not achieve this. However, Microsoft has implemented a standard programming language for all Office applications, although the object models for the individual programs are very different. This means that you need to use different code in each program to produce the same result. This is a serious problem, considering that the aim of Office integration is that it should be application-independent. Using OLE may not solve the problem, but it does significantly reduce the amount of application-dependent code required. Since the main aim of R/3 application programming is to produce standard software, there is a real need for an interface to Office applications which is independent of platform and application . There is a standard interface, proposed by the OS/2 group, for document control, and this can easily be integrated into the concept presented in this document.

Document Templates and Merging R/3 Data


Since R/3 is not just a document display and management system, but contains business applications, we need to be able to use documents as templates, where R/3 data is included at runtime. For example, a customer might want to use a template with his or her company logo and address for an order or delivery note, where the order number, name of the person responsible and other data can be inserted. Until now, this was accomplished in a completely different way. The templates were stored as RTF files, data was merged into the template in R/3 using an RTF interpreter, and Word was used merely as a display program for the RTF documents. To use other binary document formats, you had to leave the task of merging the data to the Office application you were using. To make this work on a cross-platform basis, you needed a mixture of macro programming and automation or DDE to insert the right data at the right place in the document. This then led to the problems mentioned in the previous section: you had to re-write the control for each application. Furthermore, it was only possible to replace simple text fields if you wanted your solution to work for all applications and platforms. The following shows the conventional method for replacing data.

4 of 6

14-Dec-13 1:00 PM

Connecting OLE-compatible Office Applications to the R/3 System

http://www.erpgenie.com/sap/abap/ole.htm

For the sake of completeness, we should, at this point, mention another way of getting and merging data. In the Open Information Warehouse (OIW), you can insert R/3 data into Excel worksheets using the OCX function and automation. This technique also works with documents opened using the SAP Container Control. However, its decisive disadvantage is that you need a separate RFC connection, so it does not work within the current program. Using OLE links, which we mentioned earlier in the introductory section, you not only avoid the disadvantages we have listed, but you can also link complex data formats such as RTF, graphics and internal tables.

You can create document templates without any macro programming, and they are supported by a simple Paste Special dialog box. To insert a link to an order number, you would insert the following field in Microsoft Word: {LINK SAP.LinkItem.1 SAPOLELinkServer RequestNumber \t} and the following cell in Excel: =SAP.LinkItem.1|'SAPOLELinkServer'!'!RequestNumber' For a bitmap, you insert the following link in Word: {LINK SAP.LinkItem.1 SAPOLELinkServer SAPLogo \b} OLE link technology also allows you to link to data contained in an internal table. You can refer either to the whole table or, as in Excel, to individual cells or areas. A link to the data in the first order item would look like this in a Word document:
{LINK SAP.LinkItem.1 SAPOLELinkServer RequestItems!R1C1:R1C2 \t}

As the previous illustration shows, you need to send the data for the links to the Data Provider using GUI RFC. To summarize, using OLE links has the following advantages: + no need for macro programming

5 of 6

14-Dec-13 1:00 PM

Connecting OLE-compatible Office Applications to the R/3 System

http://www.erpgenie.com/sap/abap/ole.htm

+ + +

no need to adapt code to the different Office programs supports several different data formats can be used from VBA using automation
Contact Us | Polls | Add URL | Contribute | About | Privacy | Terms | Feedback | Help! Message Board | Discussion Forum | BLOG | Consultants: Post your resume | Companies: Advertise on ERPGenie.COM | Post Job Financials Consultant | Consultant Review | Gallia Consulting | Supply Chain Project | SAP Financials Forum GenieHoldings.COM, Inc. | Genie Press | WorkflowGenie | ESAGenie | ERPTopSites | ABAP Tips and Tricks Searching Survivor

2001-2007 ERPGenie.COM, Inc. All rights reserved. All product names are trademarks of their respective companies. GenieHoldings.COM, Inc. and it's websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver, and and any other SAP trademarks are registered trademarks of SAP AG in Germany and in several other countries. Every effort is made to ensure content integrity. Use information on this site at your own risk.

6 of 6

14-Dec-13 1:00 PM

Você também pode gostar