connecting ole-compatible office applications to the r_3 system

6
Enterprise Resource Planning Portal Advertise | Founder BLOG THE ultimate ERP website Forums | SAP Top Sites | -1808 Web ERPGenie.COM WorkflowGenie.COM Other Search Options ERPGenie Menu Consultant Corner Client Corner ERP Related Websites SAPRelated 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 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 need to know any ABAP 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, Release 4.0. 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 compatibilitymeans 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 Connecting OLE-compatible Office Applications to the R/3 System http://www.erpgenie.com/sap/abap/ole.htm 1 of 6 14-Dec-13 1:00 PM

Upload: chitturi-praveen

Post on 23-Oct-2015

34 views

Category:

Documents


3 download

DESCRIPTION

SAP OLE AND DOI

TRANSCRIPT

Page 1: Connecting OLE-Compatible Office Applications to the R_3 System

Enterprise ResourcePlanning Portal

Advertise | Founder BLOG

THE ultimateERP website

Forums | SAP Top Sites |

-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 OfficeApplications to the R/3 System

See our ABAP Tips and Tricks Database

Quicklinks Who needsABAPers??? The functional

person's tool for stresstesting and data

conversions..Siamease is aneasy to use toolthat allows you tomigrate data,upload data, stresstest, and muchmore and you don'tneed to know anyABAP

File ProcessingTextEdit 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, Release 4.0.

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 manybenefits of the OLE architecture. It will also be possible to use Microsoft Office 95 with only a few restrictions, as well asOLE2-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 hasnothing to do with OLE, except for the fact that most OLE-compatible programs use it. Microsoft developed automation intheir 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 easierand 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 �embeddeddocuments�) 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 closeExcel, 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 COMinterfaces, which together are known as OLE Compound Documents. These are a kind of file system within a file, allowingdifferent 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

Connecting OLE-compatible Office Applications to the R/3 System http://www.erpgenie.com/sap/abap/ole.htm

1 of 6 14-Dec-13 1:00 PM

Page 2: Connecting OLE-Compatible Office Applications to the R_3 System

into a document and how the external applications open and process them. The latter is particularly useful to us. Thedocument- 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 Microsoft�s own DDE interface.

Object linking differs from object embedding in that only the links to other objects are stored in the file. For example, wecould 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 OLElink 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 beextended using its own format. Last but not least, it is significantly quicker than automation when processing large quantitiesof 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 activateOLE applications �in-place�. This will require only minimal changes to ABAP programs. You will have to make room forthe 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 asof 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 Frameworkand SAPgui controls.

This means that the programming model has changed completely. Previously, the ABAP program was blocked for theduration of the RFC call and the document editing. Communication between Office applications and R/3 took place usingRFC callbacks. In the new model, processing in ABAP and at the front end is parallel. The R/3 transaction will be able toaccept user input once it has opened the document. It is now even possible to use the Control Framework to pass eventstriggered in the Office application by user input or macros back to the ABAP program. These are then processed in the PAIphase.

OLE dictates that it will be necessary to implement several COM objects. The main function will be a SAPgui control, whichwe 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 largelyindependent. They can be partially implemented without OLE to produce a limited range of functions for other operatingsystems. 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 possibilityof 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 OLElinks. These are replaced with data when the document is displayed (for example, a link to a processing number in aletter).

The following sections use Microsoft Word as a sample application. However, unless explicitly stated otherwise, the examplesapply to any OLE-compatible application.

Application Control

Connecting OLE-compatible Office Applications to the R/3 System http://www.erpgenie.com/sap/abap/ole.htm

2 of 6 14-Dec-13 1:00 PM

Page 3: Connecting OLE-Compatible Office Applications to the R_3 System

The following shows the conventional way of starting applications and opening documents. The document data is written to atemporary file, then the application is started. The name of the document to be edited is passed either as a command lineparameter 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

Connecting OLE-compatible Office Applications to the R/3 System http://www.erpgenie.com/sap/abap/ole.htm

3 of 6 14-Dec-13 1:00 PM

Page 4: Connecting OLE-Compatible Office Applications to the R_3 System

OLE only defines how documents are opened, edited and saved. Further communication between the controlling programand the Office application is the job of automation or DDE. Thanks to macro languages and, more recently, VBA (VisualBasic 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 alsooccurs with other concepts which do not use OLE). You can then use this pointer to get a pointer to the document automationinterface. 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 ensuresthat a pointer to a container is passed when you open a document in an OLE application. You can then access the pointer inVBA using the container property of the opened document. The container object, implemented by the SAP OLE ContainerControl, contains methods and properties which can be used to communicate with the controlling ABAP program. Callingfrom 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/3transaction.

While OLE has a clear, standardized protocol, application control using automation or DDE is not at all standardized. EvenVBA could not achieve this. However, Microsoft has implemented a standard programming language for all Officeapplications, although the object models for the individual programs are very different. This means that you need to usedifferent code in each program to produce the same result. This is a serious problem, considering that the aim of Officeintegration is that it should be application-independent. Using OLE may not solve the problem, but it does significantlyreduce 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 toOffice applications which is independent of platform and application . There is a standard interface, proposed by the OS/2group, 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 touse documents as templates, where R/3 data is included at runtime. For example, a customer might want to use a templatewith his or her company logo and address for an order or delivery note, where the order number, name of the personresponsible 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 intothe 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 insertthe right data at the right place in the document. This then led to the problems mentioned in the previous section: you had tore-write the control for each application. Furthermore, it was only possible to replace simple text fields if you wanted yoursolution to work for all applications and platforms. The following shows the conventional method for replacing data.

Connecting OLE-compatible Office Applications to the R/3 System http://www.erpgenie.com/sap/abap/ole.htm

4 of 6 14-Dec-13 1:00 PM

Page 5: Connecting OLE-Compatible Office Applications to the R_3 System

For the sake of completeness, we should, at this point, mention another way of getting and merging data. In the OpenInformation Warehouse (OIW), you can insert R/3 data into Excel worksheets using the OCX function and automation. Thistechnique also works with documents opened using the SAP Container Control. However, its decisive disadvantage is thatyou 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 havelisted, 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

Connecting OLE-compatible Office Applications to the R/3 System http://www.erpgenie.com/sap/abap/ole.htm

5 of 6 14-Dec-13 1:00 PM

Page 6: Connecting OLE-Compatible Office Applications to the R_3 System

+ 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 ForumGenieHoldings.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 inGermany and in several other countries.

Every effort is made to ensure content integrity. Use information on this site at your own risk.

Connecting OLE-compatible Office Applications to the R/3 System http://www.erpgenie.com/sap/abap/ole.htm

6 of 6 14-Dec-13 1:00 PM