Sie sind auf Seite 1von 23

Create an External Service from RFC

SAP Composite Application Framework

Document Version 1.00 November 2005

SAP AG Neurottstrae 16 69190 Walldorf Germany T +49/18 05/34 34 24 F +49/18 05/34 34 20 www.sap.com SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP NetWeaver, Copyright 2005 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. These materials are subject to change without notice. These Microsoft, Windows, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation. IBM, DB2, DB2 Universal Database, OS/2, Parallel Sysplex, MVS/ESA, AIX, S/390, AS/400, OS/390, OS/400, iSeries, pSeries, xSeries, zSeries, z/OS, AFP, Intelligent Miner, WebSphere, Netfinity, Tivoli, and Informix are trademarks or registered trademarks of IBM Corporation in the United States and/or other countries. Oracle is a registered trademark of Oracle Corporation. Disclaimer UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group. Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems, Inc. HTML, XML, XHTML and W3C 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. MaxDB is a trademark of MySQL AB, Sweden. Any Java Source Code delivered with this product is only to be used by SAPs Support Services and may not be modified or altered in any way. Some components of this product are based on Java. Any code change in these components may cause unpredictable and severe malfunctions and is therefore expressively prohibited, as is any decompilation of these components. materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty. and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary.

Typographic Conventions
Type Style Example Text Represents Words or characters quoted from the screen. These include field names, screen titles, pushbuttons labels, menu names, menu paths, and menu options. Cross-references to other documentation. Emphasized words or phrases in body text, graphic titles, and table titles. Technical names of system objects. These include report names, program names, transaction codes, table names, and key concepts of a programming language when they are surrounded by body text, for example, SELECT and INCLUDE. Output on the screen. This includes file and directory names and their paths, messages, names of variables and parameters, source text, and names of installation, upgrade and database tools. Exact user entry. These are words or characters that you enter in the system exactly as they appear in the documentation. Variable user entry. Angle brackets indicate that you replace these words and characters with appropriate entries to make entries in the system. Keys on the keyboard, for example, F2 or ENTER.

Icons
Icon Meaning Caution Example Note Recommendation Syntax

Example text
EXAMPLE TEXT

Example text

Example text

<Example text>

EXAMPLE TEXT

Contents
Introduction......................................................................................................................... 2 About This Document................................................................................................ 2 Prerequisites ............................................................................................................. 2 Disclaimer.................................................................................................................. 2 Create the Development Component Project .................................................................... 2 Import an RFC as an External Service............................................................................... 5 Encapsulate the RFC in an Entity Service ......................................................................... 8 Runtime External Service Configuration .......................................................................... 14 Test external service ........................................................................................................ 18

Introduction
About This Document
This tutorial is a part of a series that describes how to implement a composite application using SAP Composite Application Framework (CAF) capabilities. The tutorial describes how to integrate a remote-enabled (RFC) function module as an external service in your composite application using the capabilities of the CAF Service and UI layer.

Prerequisites
The following table describes the prerequisites for running this tutorial. Software The tutorial is compliant with: Sneak Preview SAP NetWeaver 04 Web Application Server 6.40 Java. You can download the sneak preview at http://sdn.sap.com

Documents

SAP NetWeaver 2004s SPS04 Before you start with this tutorial, see: Creating a Local Entity with Maintenance UI

Disclaimer
Any software coding and/or code lines / strings ("Code") included in this documentation are only examples and are not intended to be used in a productive system environment. The Code is only intended better explain and visualize the syntax and phrasing rules of certain coding. SAP does not warrant the correctness and completeness of the Code given herein, and SAP shall not be liable for errors or damages caused by the usage of the Code, except if such damages were caused by SAP intentionally or grossly negligent.

Create the Development Component Project


...

1. Launch the SAP NetWeaver Developer Studio. 2. Chose Window Open Perspective Other... Composite Application Services. 3. Navigate to File New Project and choose to create a new development component project. Choose Next.

4. Select Local Development MyComponents and choose Next.

This tutorial does not describe development using the SAP NetWeaver Development Infrastructure (NWDI). For more information about NWDI, see the relevant documentation available in the SAP NetWeaver Developers Guide at http://sdn.sap.com/irj/sdn/developersguide. 5. In the next screen, enter the following data, and then choose Next. Field Name Caption Domain Type Value user_example (use only small letters) User Example Application SAP xApps Composite Application Services

6. Choose Next again. You see a list of the projects that are generated as a part of your development component (DC). 7. To complete the procedure, choose Finish.

Import an RFC as an External Service


...

1. In the Service Explorer view, select <your project name> External Services, and open the context menu using the secondary mouse button. 2. Choose Import.

3. Select the option RFC (ABAP) and choose Next.

4. As a backend system, you can select an entry maintained in the SAP Logon, or create a connection to a single server. To select an entry from the SAP Logon, choose Load Balancing and select a backend system from the System dropdown list. Enter the necessary logon information.

To define a connection to another system that does not use load balancing, switch to the Singe Server tab page, and enter the required data. 5. Search for BAPI_USER_GETDETAIL. Select it and choose Finish.

6. In the Service Explorer view, select the new external service and double click to open it.

7. Switch to the Operations tab page and select the imported function BAPI_USER_GET_DETAIL. You can enter a description of the function in the right-hand cell. A list of all input and output parameters is displayed as well.

To save the changes that you have done, choose File Save all metadata.

Encapsulate the RFC in an Entity Service


To use this external service, you must encapsulate it in an entity service. 1. Select <your project name> Entity Services, and open its context menu using the secondary mouse button. 2. Choose New.
...

3. Enter a name for the entity service, and choose Finish.

4. To create the necessary attributes for the entity service, switch to the Attributes tab, open the context menu with the secondary mouse button, and choose Create Attribute.

5. Enter firstName for the name, and First Name for the description of the new attribute, and choose Finish.

6. Repeat the above steps to add the following attributes: Field Name userId firstName lastName zip city street Data Type com.sap.caf.core.shor tText com.sap.caf.core.long Text com.sap.caf.core.long Text com.sap.caf.core.shor tText com.sap.caf.core.long Text com.sap.caf.core.long Text Description Employee number First Name Last Name ZIP Code City Street Key Yes

7. Switch to the Operations tab page and choose Add.

8. Enter the following data: Operation name: getUserDetailById Descriptio: Gets all user details by its ID

9. Switch to the Persistency tab page and disable the option Local Persistency. This is required sp that the operation can be mapped to external services.

10. Switch to the Datasource tab page and select the getUserDetailById operation. In the righthand cell, choose (Select) to map the operation to an external service.

11. Select the BAPI_USER_GET_DETAIL service and choose OK.

12. Now you can define the parameter mapping by selecting an entity service parameter and dragging the cursor to select the relevant external operation parameter. You must map the parameters as follows: Entity Service Parameter Input Id minValue Output Result pers_no Output Result firstName Output Result lastName Output Result city Output Result street Output Result zip External Operation Parameter Input parameters BAPI_USER_GET_DETAIL USERNAME Output parameters BAPI_USER_GET_DETAIL ADDRESS PERS_NO Output parameters BAPI_USER_GET_DETAIL ADDRESS FIRSTNAME Output parameters BAPI_USER_GET_DETAIL ADDRESS LASTNAME Output parameters BAPI_USER_GET_DETAIL ADDRESS CITY Output parameters BAPI_USER_GET_DETAIL ADDRESS STREET Output parameters BAPI_USER_GET_DETAIL ADDRESS POSTL_COD1

13. Switch to the Permissions tab page and disable the option Permission checks enabled.

Save the metadata, build the project and deploy it.

Runtime External Service Configuration


...

1. Open the CAF Runtime Configuration page using the following URL: http://<host>:<port>/caf

http://localhost:53000/caf

2. Then choose Administrative Tools.

3. Now choose External Service Configuration.

4. Choose Service Registry on the left. In the service registry you can define and maintain the backend connections for your external services.

5. Select the external service you have created and choose Open Definition.

6. Select the root node of the external operation.

7. If you have not defined any SAP systems in the SLD, select Self defined RFC destinations in the Mode of Remote Function Call dropdown list.

8. Enter the required logon information for logon and choose Save.

Test external service


You can test an external services using the entity service you create to encapsulate the external one. Therefore, testing an external service is similar to testing an entity.
...

1. Open the CAF Runtime Configuration page: http://<host>:<port>/caf 2. Choose Test tools.

3. Choose Service Browser.

4. Navigate to the getUserDetailById operation.

5. Enter a valid user ID and and choose Execute query. The user details are displayed in a table.