SAP NetWeaver How-To Guide How To... Create CRUD Operations in Gateway Based on Remote Function Modules 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 SAP’s Support Services and may not be modified or altered in any way. Document History Document Version Description 1.0 First release of this guide. Typographic Conventions Icons Type Style Description Icon Example Text 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 Example text File and directory names and their paths, messages, names of variables and parameters, source text, and names of installation, upgrade and database tools. Example text User entry texts. These are words or characters that you enter in the system exactly as they appear in the documentation. <Example text> Variable user entry. Angle brackets indicate that you replace these words and characters with appropriate entries to make entries in the system. EXAMPLE TEXT Keys on the keyboard, for example, F2 or ENTER. Description Caution Note or Important Example Recommendation or Tip Table of Contents 1. Business Scenario .......................................................................................................... 1 2. Background Information ................................................................................................. 1 3. Prerequisites.................................................................................................................... 1 4. Step-by-Step Procedure .................................................................................................. 2 4.1 Create the RFC based Gateway Object. ................................................................... 2 4.2 Create the QUERY Operation. .................................................................................. 4 4.3 Create the READ Operation. ..................................................................................... 7 4.4 Create the CREATE Operation. .............................................................................. 10 4.5 Create the UPDATE Operation. .............................................................................. 11 4.6 Create the Gateway Consumption Model ................................................................ 14 4.7 Test the REST Operations. ..................................................................................... 15 How To... Create CRUD Operations in Gateway Based on Remote Function Modules 1. Business Scenario This How to Guide goes over how to create and test all CRUD (minus Delete since there is no Bank delete RFM) operations based on the available Bank BAPIs. 2. Background Information You will need a Gateway 2.0 system to go over thru this How to Guide. 3. Prerequisites You will need the following tools to test your services: 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. If you are using Internet Explorer make sure it is not configured to show “friendly error messages”. To configure, follow menu path Tools > Internet Options > Advanced > Uncheck “Show friendly HTTP error messages”. This will help you analyze an errors if they occur. May 2011 1 How To... Create CRUD Operations in Gateway Based on Remote Function Modules 4. Step-by-Step Procedure The following steps will guide you thru creating and testing a Gateway service based on the Bank BAPIs. 4.1 Create the RFC based Gateway Data Model. The Gateway Data Model represents the mapping of the Gateway Service to the business data, which in this case will come from Remote Function Modules. In this step you will create the Gateway Data Model. ... 1. Logon to the Gateway 2.0 system and go to the ABAP Development Workbench – transaction SE80. 2. Create a GW Data Model – set the object type drop down to GW Data Model: 3. In the object name input field enter the name Z_BANK_RFC_<Your Last Name>: 4. Click on the eye glasses button to create the data model. 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 2 How To... Create CRUD Operations in Gateway Based on Remote Function Modules 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 (Remote Function Call), 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. As you can see no RFM‟s are displayed, you will need to search for them. May 2011 3 How To... Create CRUD Operations in Gateway Based on Remote Function Modules 4.2 Create the QUERY Operation. The QUERY operation is used to get a list of the business objects that your Gateway Service is mapped to. In this step you will map the QUERY operation against the BAPI_BANK_GETLIST remote function module. 1. Click the search icon to search for remote function modules: 2. In the popup window enter the search string BAPI_BANK*: 3. A list of all matching RFM‟s are returned: May 2011 4 How To... Create CRUD Operations in Gateway Based on Remote Function Modules 4. High light the RFM named BAPI_BANK_GETLIST – this will be used for the QUERY operation. 5. Click the Create Mapping button found on the right hand side of the screen. 6. In the Map Operation set the Operation Type to Query: 7. We need to map BANK_CTRY and BANK_KEY of the BANK_LIST table to the S_COR_IDVALUE. May 2011 5 How To... Create CRUD Operations in Gateway Based on Remote Function Modules Note: the S_COR_ID-VALUE is the primary key of generated Gateway services. Each Gateway operation must be mapped to the same primary keys. S_COR_ID-VALUE is a 72 character length string, so the combined length of all primary key fields mapped to it cannot exceed this length! 8. Right click on BANK_LIST-BANK_CTRY and click the Change Mapping button: 9. In the Mapping Route popup window select the S_COR_ID-VALUE and then click the Enter button: 10. Do the same thing for the BANK_LIST-BANK_KEY attribute (both should be mapped to S_COR_ID-VALUE). 11. Your mapping should now look like this: 12. Now let‟s set a constant value on the BANK_CTRY input attribute. 13. Right click on the BANK_CTRY attribute and click the Set Constant Value button: May 2011 6 How To... Create CRUD Operations in Gateway Based on Remote Function Modules 14. In the Set Constant Value popup window enter a value for the Bank Country, in this example „US‟ – with single quites!!!: 15. Your mapping should now look like the following: 16. Click the Enter button to complete the operation mapping. Note: You may notice that there is no save button to save your Gateway Data Model. To save your Gateway Data Model you must click the Generate button, which will not only save the Data model but will also generate all of its corresponding classes and configuration. If for some reason you became disconnected from the Gateway system your changes will not be saved if you have not generated. 4.3 Create the READ Operation. The READ operation is used to read a single business object‟s data. The OData specification mandates that an OData based service must have at the very least a QUERY operation and a READ operation. In this step you will map the READ operation to BAPI_BANK_GETDETAIL. 1. In RFM search results list, select BAPI_BANK_GETDETAIL: May 2011 7 How To... Create CRUD Operations in Gateway Based on Remote Function Modules 2. Click the Create Mapping button. 3. Set the Operation Type to Read. 4. Map BANKCOUNTRY and BANKKEY input attributes to S_COR_ID-VALUE. 5. Right click on the BANKCOUNTRY attribute and select the Change Mapping Route button: 6. In the Mapping Route popup window select the S_COR_ID-VALUE attribute and click the Enter button: 7. Do the same with the BANKKEY input attribute, your mapping for these attributes should now look like this: 8. Uncheck the Return and BankDetails structures, your mapping should now look like this: May 2011 8 How To... Create CRUD Operations in Gateway Based on Remote Function Modules 9. 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. Let‟s do the same with the rest of the attributes of the BankAddress structure. We are doing this so that the Gateway Data Model has a completely flat structure (no structure or table nodes, all attributes are directly under the root node). This is important for two reasons, one – it makes for a very clean and simple interface, and two – operations UPDATE and CREATE which we will be mapping later require a flat interface…no structures or table input are supported for these operations! 10. Right click on the REGION attribute and click the Change Mapping Route button. 11. Select the root node of your object: Note: by selecting the root node of the object you are having the attribute mapped directly under it, thus flattening out the structure. 12. Click the Enter button. Now do these steps for each attribute in the BankAddress structure. 13. Your mapping should now look like the following: May 2011 9 How To... Create CRUD Operations in Gateway Based on Remote Function Modules 14. Click the Enter button to complete the operation mapping. 4.4 Create the CREATE Operation. The CREATE operation creates a business entity. In order for OData to support the CREATE operation, structure of the business object mapping must be completely flat. No structures or tables are allowed to be passed as input in OData. In this step you will map the CREATE operation to the BAPI_BANK_CREATE remote function module. 1. In the RFM search results, select BAPI_BANK_CREATE: 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 10 How To... Create CRUD Operations in Gateway Based on Remote Function Modules 5. The output attributes BANK_CTRY and BANK_KEY need to be mapped to the S_COR_IDVALUE. Do this, once done the mapping for these attributes will look like this: 6. Click the Enter button to complete your operation mapping. 4.5 Create the UPDATE Operation. The UPDATE operation updates a business entity. Just like with the CREATE operation, in order for OData to support the UPDATE operation the structure of the business object mapping must be completely flat. No structures or tables are allowed to be passed as input in OData. In this step you will map the UPDATE operation to the BAPI_BANK_CHANGE remote function module. 1. In the RFM search results, select BAPI_BANK_CHANGE. 2. Click the Create Mapping button. 3. Set the Operation Type to Update. 4. Uncheck the BankAddress1, BankAddress1x, BankDetail, and BankDetailx structures. 5. Map the input attributes BANKCOUNTRY and BANKKEY to S_COR_ID-VALUE. 6. Your mapping should now look like the following: May 2011 11 How To... Create CRUD Operations in Gateway Based on Remote Function Modules 7. Click the Enter button to complete the operation mapping. 8. Your Gateway Object should now look like the following: May 2011 12 How To... Create CRUD Operations in Gateway Based on Remote Function Modules 9. Click the Generate button. This will generate all the classes and other configuration files needed for the service. 10. When generation is complete you will see the following popup window displayed: May 2011 13 How To... Create CRUD Operations in Gateway Based on Remote Function Modules 4.6 Create the Gateway Consumption Model The Consumption Model is what exposes the Gateway Data Models to the network. It does this by creating a service in the Internet Communication Framework. In this step you will create a Consumption Model and then map your Data Model to it. 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: zbankrfc<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 zbankrfc<your last name>, and description and click the Enter button. 6. The created service document will be displayed. Right click on it and in the context menu select Add Gateway Object. May 2011 14 How To... Create CRUD Operations in Gateway Based on Remote Function Modules 7. In the popup window enter in Z_BANK_RFC* and click the F4 help button. 8. Find and select your Gateway Object you created earlier…it should look similar to the following: 9. Your Gateway Object Model should now look similar to the following: 10. You have successfully created your Gateway service…now you get to test it. 11. You can see the Gateway service exposed in the ICF – transaction SICF – follow the ICF tree path default_host > sap > opu > sdata > sap...there you will see a list of all ICF services that represent Gateway Consumption Models. 4.7 Test the REST Operations. Now for the fun part! You get to test everything you have done up to this point. Testing the QUERY and READ operations is easy…you just need a browser. Testing the CREATE and UPDATE operations (as well as the DELETE if we had implemented that), requires the use of a simple HTTP tool, the one we use here is WFetch (the FireFox browser also has a nice REST plug-in available). May 2011 15 How To... Create CRUD Operations in Gateway Based on Remote Function Modules 1. Go back to transaction SE80 and display your Gateway Consumption Model you created in the last step: 2. Double click on the top level node of your Gateway Consumption Model, this will display it‟s properties: 3. Click the Metadata button. This will launch a browser which will display the metadata of your service: May 2011 16 How To... Create CRUD Operations in Gateway Based on Remote Function Modules 4. To execute the QUERY operation replace in the URL $metadata with z_bank_rfc_<Your Last Name>Collection, you should see the following page: http://servername:http_port/sap/opu/sdata/sap/ZBANKGEBO/z_bank_gebo2Collection?sapclient=800&$format=xml May 2011 17 How To... Create CRUD Operations in Gateway Based on Remote Function Modules 1. 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: http://servername:http_port/sap/opu/sdata/sap/ZBANKGEBO/z_bank_rfc_geboColl ection(value='0209_US021000089',scheme_id='Z_BANK_RFC_GEBO',scheme_agen cy_id='LOCAL') 2. 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: May 2011 18 How To... Create CRUD Operations in Gateway Based on Remote Function Modules 3. You will need to start WFetch to test the Create and Update operations. 4. 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. 5. Enter in the required HTTP Header and Body ( in the drop-down select Add Headers&Body): May 2011 19 How To... Create CRUD Operations in Gateway Based on Remote Function Modules 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" ?> \r\n <atom:entry xml:base="HTTP://10.66.9.130:50045/sap/opu/sdata/sap/ZBANKRFCGEBO/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:sap="http://www.sap.com/Protocols/SAPData">\r\n <atom:content type="application/xml">\r\n <m:properties>\r\n <d:value>0209_US021800089</d:value> \r\n <d:scheme_id>Z_BANK_RFC_GEBO</d:scheme_id> \r\n <d:scheme_agency_id>LOCAL</d:scheme_agency_id> \r\n <d:swift_code>CITIUSXX</d:swift_code> \r\n <d:street>123 Main St</d:street> \r\n <d:bank_ctry /> \r\n <d:bank_group /> \r\n <d:bank_name>Bank of Gebo</d:bank_name> \r\n <d:pobk_curac /> \r\n <d:city>Sacramento</d:city> \r\n <d:addr_no /> \r\n <d:bank_no/>\r\n <d:bank_branch>California</d:bank_branch> \r\n <d:region>CA</d:region> \r\n <d:post_bank /> \r\n </m:properties>\r\n </atom:content>\r\n </atom:entry>/entry>\r\n Note: the header x-requested-with is required for CREATE, UPDATE and DELETE operations! 6. Check the contents of the <d:value></d:value> tag…in 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 doesn‟t 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. May 2011 20 How To... Create CRUD Operations in Gateway Based on Remote Function Modules 7. Now click the Go! button. 8. The CREATE operation will be executed and the flowing response should be returned: Note: notice that in the response if the OData READ operation XML for this bank you just created. OData calls the READ operation after the a successful CREATE. This means that your OData Gateway services with CREATE operations will need a corresponding READ operation…without the READ operation you would get an exception even though the creation was successful. 9. Now let‟s test the UPDATE method. In WFetch change the Verb type to PUT: 10. Set the path to be the same path used when executing the READ operation, in this example it will be: /sap/opu/sdata/sap/ZBANKRFCGEBO/z_bank_rfc_geboCollection(value='0209_US021800089', scheme_id='Z_BANK_RFC_GEBO',scheme_agency_id='LOCAL')?sap-client=800&$format=xml Make sure the value is set to the correct Bank Number. Note: If copying the path above make sure to change the name “Gebo” to your name. 11. Now in the HTTP Header and Body data, change the bank_name and city attributes to something different. May 2011 21 How To... Create CRUD Operations in Gateway Based on Remote Function Modules 12. Click the Go! button. 13. If the UPDATE is successful you will receive the following response: Note: The HTTP response code of 204 is a successful update response…there is no response body returned hence the codes text “No Content”. 14. To make sure that the UPDATE was correct just change the Verb type to GET and disable the Header and Body: 15. It should return in the response the new bank details: May 2011 22 How To... Create CRUD Operations in Gateway Based on Remote Function Modules 16. Alternatively just test the read in the browser: Congratulations! You have successfully created and tested your Gateway Bank Service! h ttp://<s erve r_n am e>:<h ttp _ po rt> /sa p/op u /s da ta/sa p /z ba nk <y ou r_l as t May 2011 23 www.sdn.sap.com/irj/sdn/howtoguides
© Copyright 2024