Anda di halaman 1dari 27

SAP NetWeaver How-To Guide

How To... Create CRUD Operations in Gateway Based on BOR Objects

Applicable Releases: Gateway 2.0

Version 1.0 April 2010

Copyright 2011 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, 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, Informix, i5/OS, POWER, POWER5, OpenPower and PowerPC are trademarks or registered trademarks of IBM Corporation. Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of Adobe Systems Incorporated in the United States and/or other countries. Oracle is a registered trademark of Oracle Corporation. 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. SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP NetWeaver, 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.

These materials are subject to change without notice. These 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. These materials are provided as is without a warranty of any kind, either express or implied, including but not limited to, the implied warranties of merchantability, fitness for a particular purpose, or non-infringement. SAP shall not be liable for damages of any kind including without limitation direct, special, indirect, or consequential damages that may result from the use of these materials. SAP does not warrant the accuracy or completeness of the information, text, graphics, links or other items contained within these materials. SAP has no control over the information that you may access through the use of hot links contained in these materials and does not endorse your use of third party web pages nor provide any warranty whatsoever relating to third party web pages. SAP NetWeaver How-to Guides are intended to simplify the product implementation. While specific product features and procedures typically are explained in a practical business context, it is not implied that those features and procedures are the only approach in solving a specific business problem using SAP NetWeaver. Should you wish to receive additional information, clarification or support, please refer to SAP Consulting. 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. Disclaimer 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. 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.

Document History
Document Version 0.5 1.0 Description First beta release of this guide only available internally and Gateway 1.0 pilot customers. Upgraded to Gateway 2.0

Typographic Conventions
Type Style Example Text Description 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 Example text Emphasized words or phrases in body text, graphic titles, and table titles File and directory names and their paths, messages, names of variables and parameters, source text, and names of installation, upgrade and database tools. User entry texts. 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 Description Caution Note or Important Example Recommendation or Tip

Example text

Example text

<Example text>

EXAMPLE TEXT

Table of Contents
1. 2. 3. 4. Business Scenario.............................................................................................................. 1 Background Information..................................................................................................... 1 Prerequisites....................................................................................................................... 1 Step-by-Step Procedure ..................................................................................................... 2 4.1 4.2 4.3 4.4 4.5 4.6 4.7 Create the BOR based Gateway Object. ................................................................... 2 Create the QUERY Operation. .................................................................................. 4 Create the READ Operation. ..................................................................................... 5 Create the CREATE Operation. ................................................................................ 7 Create the UPDATE Operation. ................................................................................ 8 Create the Gateway Consumption Model ................................................................ 11 Test the REST Operations. ..................................................................................... 13

How To... Create CRUD Operations in Gateway Based on BOR Objects

1. 2.

Business Scenario Background Information

This How to Guide goes over how to create and test all CRUD (minus Delete since the BOR Bank object doesnt have a delete method) operations for the Bank BOR object.

You will need a Gateway 2.0 system to go over thru this How to Guide.

3.

Prerequisites
WFetch HTTP client or Fire Fox Browser which has a REST client similar to WFetch. This How to Guide will use WFetch. It can be downloaded from here: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=B134A806-D50E-4664-8348DA5C17129210&displaylang=en You will need access to a configured Gateway 2.0 system. To familiarize yourself with Gateway I suggest the Project Gateway Wiki and the Project Gateway Community websites.

You will need the following tools to test your services:

May 2011

How To... Create CRUD Operations in Gateway Based on BOR Objects

4.

Step-by-Step Procedure

The following steps will guide you thru creating and testing a Gateway service based on the BOR Bank object.

4.1
...

Create the BOR based Gateway Object.

1. Logon to the Gateway 2.0 system and go to the ABAP Development Workbench transaction SE80. 2. Create a GW Data Object set the object type drop down to GW Data Object:

3. In the object name input field enter the name Z_BANK_<Your Last Name>:

Note: I am adding the number 2 to my name as not to conflict with a pre-existing Gateway Object I created. 4. Click on the eye glasses button to create the object. 5. Click the Yes button in the popup window:

6. In the Create Data Model popup window set the type to PS Public Solution Model:

May 2011

How To... Create CRUD Operations in Gateway Based on BOR Objects

7. Except the rest of the defaults (make sure Generate from Data Source Object radio button is selected), and click the Enter button. 8. In the popup window enter a Description, Data Source Type (BOR), and the System Alias (this is the alias that is connected to the back end system). Click Continue.

9. Your Model should now be displayed along with the BOR (Business Object Repository) of the System Aliass associated backend system:

May 2011

How To... Create CRUD Operations in Gateway Based on BOR Objects

4.2

Create the QUERY Operation.

1. In the BOR find the Bank object and in the Bank object highlight the GetList method:

2. Click the Create Mapping button found on the right hand side of the screen.

3. In the Map Operation set the Operation Type to Query:

May 2011

How To... Create CRUD Operations in Gateway Based on BOR Objects

4. We need to make the BankCtry attribute available as an input parameter to our service. Right click on the BankCtry attribute and then click the Change Mapping Route button.

5. In the popup window select BANKCTRY and click the Enter button:

6. Your mapping should now look like the following:

7. Click the Enter button to complete the operation mapping.

4.3

Create the READ Operation.

May 2011

How To... Create CRUD Operations in Gateway Based on BOR Objects

1. In the BOR Bank object highlight the GetDetail operation.

2. Click the Create Mapping button. 3. Set the Operation Type to Read. 4. Uncheck the Return and BankDetails structures, your mapping should now look like this:

5. Notice in the above image that BANK_NAME and CITY attributes of the BankAddress structure are mapped to the previously created attributes from the QUERY operation. Lets do the same with the rest of the attributes of the BankAddress structure. 6. Right click on the REGION attribute and click the Change Mapping Route button. 7. Select the root node of your object:

8. Click the Enter button. Now do these steps for each attribute in the BankAddress structure. 9. Your mapping should now look like the following:

May 2011

How To... Create CRUD Operations in Gateway Based on BOR Objects

10. Click the Enter button to complete the operation mapping.

4.4

Create the CREATE Operation.

1. In the BOR Bank object highlight the Create operation.

2. Click the Create Mapping button. 3. Select the Create operation type radio button. 4. Uncheck the BankAddress1 structure, and the BankFormatting, BankMethod, I_XUPDATE attributes. Your mapping should now look like the following:

May 2011

How To... Create CRUD Operations in Gateway Based on BOR Objects

5. Click the Enter button to complete your operation mapping.

4.5

Create the UPDATE Operation.

1. In the BOR Bank object highlight the Change operation. 2. Click the Create Mapping button. 3. Set the Operation Type to Update. 4. Uncheck the BankAddress1, BankAddress1x, BankDetail, and BankDetailx structures. 5. Your mapping should now look like the following:

May 2011

How To... Create CRUD Operations in Gateway Based on BOR Objects

6. Click the Enter button to complete the operation mapping. 7. Your Gateway Object should now look like the following:

May 2011

How To... Create CRUD Operations in Gateway Based on BOR Objects

8. Click the Generate button. This will generate all the classes and other configuration files needed for the service.

9. When generation is complete you will see the following popup window displayed:

May 2011

10

How To... Create CRUD Operations in Gateway Based on BOR Objects

4.6

Create the Gateway Consumption Model

1. Now you need to expose the service via the Internet Communication Framework (ICF). Navigate to transaction SE80. 2. In the drop-down select object type GW Consumption Model:

3. In the input field enter in the service document name in the following format: zbank<your last name>

4. Click the Display button and then click the Yes button, the following popup window will be displayed:

5. Enter in the service name zbank<your last name>, and description and click the Enter button.

May 2011

11

How To... Create CRUD Operations in Gateway Based on BOR Objects

6. The created service document will be displayed. Right click on it and in the context menu select Add Gateway Object.

7. In the popup window enter in Z_BANK* and click the F4 help button.

8. Find and select your Gateway Object you created earlierit should look similar to the following:

9. Your Gateway Object Model should now look similar to the following:

May 2011

12

How To... Create CRUD Operations in Gateway Based on BOR Objects

10. You have successfully created your Gateway servicenow you get to test it. 11. You can see the Gateway service exposed in the ICF transaction SICF:

4.7

Test the REST Operations.

1. Go back to transaction SE80 and display your Gateway Consumption Model you created in the last step:

May 2011

13

How To... Create CRUD Operations in Gateway Based on BOR Objects

2. Double click on the top level node of your Gateway Consumption Model, this will display its properties:

3. Click the Metadata button. This will launch a browser which will display the metadata of your service:

May 2011

14

How To... Create CRUD Operations in Gateway Based on BOR Objects

4. To execute the QUERY operation replace in the URL $metadata with z_bank_<Your Last Name>Collection, you should see the following page:

Since we defined the bankctry input parameter to our QUERY operation we need to supply it. 5. OData supports passing input parameters via the Query String. Add the attribute $filter=bankctry EQ US to the Query String of the URL your URL should now look something like this: http://servername:http_port/sap/opu/sdata/sap/ZBANKGEBO/z_bank_gebo2Collection?$filter= bankctry EQ 'DE'&sap-client=800&$format=xml

6. For each bank in the list there is an atom:id tag with a value of the URL that can be used to call the READ operation, for example:

May 2011

15

How To... Create CRUD Operations in Gateway Based on BOR Objects

http://servername:http_port/sap/opu/sdata/sap/ZBANKGEBO/z_bank_gebo2Collect ion(value='0209_US021000089',scheme_id='Z_BANK_GEBO2',scheme_agency_id= 'LOCAL') 7. Copy one of these and paste it into the URL of the browser and navigate to it, the details of the Bank will be displayed:

8. You will need to start WFetch to test the Create and Update operations. 9. Test the CREATE operation. Enter in the Verb POST, Host, Port and Path. The path should be the same as you used to execute the QUERY operation above. You will also need to set authentication for Basic auth and enter in your user name and password.

May 2011

16

How To... Create CRUD Operations in Gateway Based on BOR Objects

10. Enter in the required HTTP Header and Body ( in the drop-down select Add Headers&Body):

Here is an example of the request that you can type in yourself or you can copy the contents of the attached file named bank_request.txt. Please note, you will have to change the values to match your service(at the very least scheme_id and scheme_agency_id):
x-requested-with: XMLHttpRequest\r\n \r\n <?xml version="1.0" encoding="utf-8" standalone="yes"?>\r\n <entry xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">\r\n <content type="application/xml">\r\n <m:properties>\r\n <d:value>0209_US021200089</d:value> \r\n <d:scheme_id>Z_BANK_GEBO2</d:scheme_id> \r\n

May 2011

17

How To... Create CRUD Operations in Gateway Based on BOR Objects

<d:scheme_agency_id>LOCAL</d:scheme_agency_id> \r\n <d:post_bank /> \r\n <d:bank_branch>Sacramento</d:bank_branch> \r\n <d:street>123 Main St.</d:street> \r\n <d:city>El Dorado Hills</d:city> \r\n <d:swift_code/>\r\n <d:region>CA</d:region> \r\n <d:bank_name>Bank of Gebo</d:bank_name> \r\n <d:pobk_curac /> \r\n <d:bankctry /> \r\n <d:bank_group /> \r\n <d:addr_no /> \r\n </m:properties>\r\n </content>\r\n </entry>\r\n </entry>\r\n

Note: the header x-requested-with is required for CREATE, UPDATE and DELETE operations! 11. Check the contents of the <d:value></d:value> tagin this case it is 0209_US021200089, this value represents the Key value of the bank to be created. The service knows it has two key values but it doesnt know how long. 02 is the length of the first attribute, and 09 is the length of the second attribute. This is how it is able to parse the key value string. Make sure to enter in a unique Bank Number which is currently set to 21200089 in the XML above. Change it to something unique. 12. Now click the Go! button.

13. The CREATE operation will be executed and the flowing response should be returned:

May 2011

18

How To... Create CRUD Operations in Gateway Based on BOR Objects

14. Now lets test the UPDATE method. In WFetch change the Verb type to PUT:

15. Set the path to be the same path used when executing the READ operation, in this case it will be: /sap/opu/sdata/sap/ZBANKGEBO/z_bank_gebo2Collection(value='0209_US021200089',schem e_id='Z_BANK_GEBO2',scheme_agency_id='LOCAL') Make sure the value is set to the correct Bank Number. If copying the path above make sure to change the name Gebo to your name. 16. Now in the HTTP Header and Body data, change the bank_name and city attributes to something different.

May 2011

19

How To... Create CRUD Operations in Gateway Based on BOR Objects

17. Click the Go! button. 18. If the UPDATE is successful you will receive the following response:

19. To make sure that the UPDATE was correct just change the Verb type to GET and disable the Header and Body:

20. It should return in the response the new bank details:

21. Alternatively just test the read in the browser: May 2011 20

How To... Create CRUD Operations in Gateway Based on BOR Objects

Congratulations! You have successfully created and tested your Gateway Bank Service!

h ttp s e r_ a e h tt _ p rt /sa p p u / d ta p / b n < o r_ a t ://< rve n m >:< p o > /o s a /sa z a k y u l s

May 2011

21

www.sdn.sap.com/irj/sdn/howtoguides

Anda mungkin juga menyukai