You are on page 1of 32

SAP NetWeaver How-To Guide

How To... Create Services Using the OData Channel

Applicable Releases: SAP NetWeaver Gateway 2.0 SP3+

Version 1.1 July 2012

© Copyright 2012 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 1.00 1.10 Description First official release of this guide Upgraded to support SP3+ changes

and menu options.Typographic Conventions Type Style Example Text Description Words or characters quoted from the screen. Cross-references to other documentation Example text Emphasized words or phrases in body text. messages. and names of installation. User entry texts. F2 or ENTER. menu paths. Angle brackets indicate that you replace these words and characters with appropriate entries to make entries in the system. menu names. and table titles File and directory names and their paths. for example. graphic titles. Icons Icon Description Caution Note or Important Example Recommendation or Tip Example text Example text <Example text> EXAMPLE TEXT . These include field names. source text. screen titles. pushbuttons labels. names of variables and parameters. These are words or characters that you enter in the system exactly as they appear in the documentation. upgrade and database tools. Keys on the keyboard. Variable user entry.

......................4 4..................................... 10 Redefine and Implement the CREATE_ENTITY Method .................................... 1 Step-by-Step Procedure ..... 3.................................................................................................................................................... 4............. 2 Implement Your Metadata Class‟s DEFINE and GET_LAST_MODIFIED Methods .........................5 4.................1 4..................................................... Business Scenario ...................6 4...........................7 4........................................................................... 4 Create Your Service‟s Runtime Class ..................2 4..... 13 Activate the Service on the Gateway System ............................................................................. 1 Background Information ........................ 2 4.........................8 4............ 9 Redefine and Implement the UPDATE_ENTITY Method .................................................10 Test Your Service .......................................... 12 Maintain OData Channel Table Configuration ........................... 6 Redefine and Implement the GET_ENTITYSET Method .......... 21 . 2.................................................9 Create Your Service‟s Model Class ................................. 1 Prerequisites .................Table of Contents 1................................................................................3 4. 17 4............................................................. 6 Redefine and Activate the GET_ENTITY Service ...................

Background Information SAP NetWeaver Gateway offers an easy way to expose data via the REST based Open Data (OData) format. July 2012 1 . Knowledge of ABAP Object Oriented programming is required.. This guide will focus on creating a simple service with OData Channel. That said. Backend SAP System is connected to the SAP NetWeaver Gateway system.0 SP3 (or higher) installed and configured. it allows you to create simple services or complex ones. Create Services Using the OData Channel 1. You develop classes using this API on the backend system where the SAP data resides.How To. Backend SAP System with the BEP (SP3 or higher) gateway add-on installed. With Gateway you can generate services based on BOR objects. or Screen Scraping. not on the actual Gateway system. There is also another way using the OData Channel API. RFCs. which is an ABAP Object API. It is the hope of the author that once you learn how to create this very simple service you will move on to developing more complex and interesting services with OData Channel. this is a very detailed step by step guide which you could probably complete without ABAP OO experience…but you most likely wouldn‟t be able to fully understand it. The OData Channel is very flexible and powerful. 3.     Prerequisites SAP NetWeaver Gateway 2. 2.. Business Scenario Your backend SAP system contains Banking business data that you want to expose via a REST based API so that it will be easily consumable by the outside world.

9. This section will show you how to create this class and which super class it needs to inherit from. Logon to the backend SAP system that you wish to expose business data from with OData Channel based services. 6. Step-by-Step Procedure The following steps will guide you thru creating an OData Channel service based on Bank business data. July 2012 2 . 4. Go to transaction SE80 – ABAP Development Workbench 3. Enter in a Description. On the backend system you will develop and configure the Bank service using the OData Channel API and configuration tables. 2.. Click the Yes button. Since the object does not yet exist you will be asked if you want to create it: 7. Enter in the class name Z_CL_BANK_MODEL_<Your Last Name>: 5. 8.. accept the default selections and click the Save button. Create Your Service’s Model Class The Model class defines the interface of your OData Channel service.1 .. Click the Display icon (the eye glasses icon). Change the object type drop down to be Class / Interface: 4. Create Services Using the OData Channel 4..How To. 1. Once that is done you will activate the service on the Gateway system and test it. Except the default type Class radio button and click the Enter button.

. In the class editor switch to the Properties tab: 14. 15.How To. 11. this will open the class editor.. Save your newly created class as a Local Object. Make sure you are in Change mode. Click the Superclass button. July 2012 3 . Double click on the class you just created. 13. Create Services Using the OData Channel 10. You should now see the following: 12.

Enter in the OData Channel Metadata Class . Save your class. Create Services Using the OData Channel 16../IWBEP/CL_MGW_ABS_MODEL: 17..How To. Open the Methods > Inherited Methods node of your Class in the Class browser: July 2012 4 .2 Implement Your Metadata Class’s DEFINE Method. 1. The DEFINE method of the Metadata class is where you implement the coding that defines the service‟s interface. The class should now look like this: 4.

lo_property = lo_data_object->create_property( IV_ABAP_FIELDNAME = 'BANKL' IV_PROPERTY_NAME = 'bankID' ). "Create a new data object with name Bank lo_data_object = model->create_entity_type( 'Bank' ).How To. Create Services Using the OData Channel 2.. "Define the properties of the Bank object "IV_ABAP_FIELDNAME is the ABAP dictionary name "IV_PROPRETY_NAME is the OData friendly name lo_property = lo_data_object->create_property( IV_ABAP_FIELDNAME = 'BANKS' IV_PROPERTY_NAME = 'bankCountry' ). The method editor for the redefined method will open up: 4. Enter in the following code that defines the metadata of your Bank service (or copy the contents in the attached file bind_structure. "Set as a key July 2012 5 . "Set as a key lo_property->set_is_key( abap_true ).. lo_property TYPE REF TO /IWBEP/IF_MGW_ODATA_PROPERTY.txt file): " ABAP OData Data Object DATA: lo_data_object TYPE REF TO /IWBEP/IF_MGW_ODATA_ENTITY_TYP. Right click on the DEFINE method and in the context menu select Redefine: 3.

lo_property = lo_data_object->create_property( IV_ABAP_FIELDNAME = 'ORT01' IV_PROPERTY_NAME = 'city' ). lo_property = lo_data_object->create_property( IV_ABAP_FIELDNAME = 'STRAS' IV_PROPERTY_NAME = 'street' )..3 Create Your Service’s Runtime Class The service‟s runtime class is what is called when the service is executed.. Follow the exact procedure described in section 4.. 5. and setting the super class to /IWBEP/CL_MGW_ABS_DATA.4 Redefine and Implement the GET_ENTITYSET Method The GET_ENTITYSET method is called for Query type operations.2 where you created the Metadata class. The runtime class is where you implement your business logic. lo_property = lo_data_object->create_property( IV_ABAP_FIELDNAME = 'PROVZ' IV_PROPERTY_NAME = 'region' ).How To. This section will guide you thru the initial setup of the runtime class. 1. Create Services Using the OData Channel lo_property->set_is_key( abap_true ).. . "Bind your structure that represents the above properties lo_data_object->bind_structure( 'BNKA' ).. Your class should look like the following: 4. This section will guide you thru implementing the GET_ENTITYSET method which will support filtering on the BANK_COUNTRY parameter. Open the Methods > Inherited Methods > /IWBEP/IF_MGW_APPL_SRV_RUNTIME node of your Bank runtime object: July 2012 6 . 2. lo_property = lo_data_object->create_property( IV_ABAP_FIELDNAME = 'BANKA' IV_PROPERTY_NAME = 'bankName' ). 4.. this time naming the class Z_CL_BANK_DATA_<Your Last Name>. Save and Activate your class. 1. .

.. Create Services Using the OData Channel 2.How To. The method editor should show displaying the following: July 2012 7 . Right click on the method GET_ENTITYSET and in the context menu select Redefine: 3.

TYPE /iwbep/s_cod_select_option. "banks . "Change to uppercase so we don't have to worry about case issues TRANSLATE ls_filter_select_options-property TO UPPER CASE. in our case we will "only worry about the BANK_COUTNRY field. Save and Activate your class. but often multiple fields "can be filtered on CASE ls_filter_select_options-property. append wa_bnka to lt_bank. TYPE RANGE OF banks. 5.. July 2012 8 . APPEND ls_range_bank_country TO lt_range_bank_country.How To. ENDLOOP. TYPE /iwbep/s_mgw_select_option. WHEN 'BANKCOUNTRY'. TYPE BNKA. " Select the data from the BANK table into the internal " table SELECT banks bankl banka FROM BNKA INTO CORRESPONDING FIELDS OF wa_bnka WHERE BANKS IN lt_range_bank_country. Remove the commented out portion of the method. "Loop over the selection options internal table . 6.. Create Services Using the OData Channel 4. LIKE LINE OF lt_range_bank_country.each filter option can have "more than one selection option LOOP AT ls_filter_select_options-select_options INTO ls_mgw_range_options. "Setup the range table. ENDLOOP. TYPE /iwbep/s_mgw_select_option. ENDSELECT. "Use the helper method to copy the internal table data into the "structure of the OData Service copy_data_to_ref( EXPORTING is_data = lt_bank CHANGING cr_data = er_entityset ). "Check which property is being filtered on. MOVE-CORRESPONDING ls_mgw_range_options TO ls_range_bank_country. ENDCASE. Note: please read the comments to understand what each section of code is doing: DATA: lt_bank wa_bnka ls_filter_select_options ls_mgw_select_options ls_mgw_range_options lt_range_bank_country ls_range_bank_country TYPE TABLE OF BNKA.is the bank country element "Loop at the filter options internal table that is passed to this method LOOP AT it_filter_select_options INTO ls_filter_select_options.txt. Implement the following by either typing in the below or copying the contents of the attached file named get_entityset.

we won‟t be using that. DATA: lv_string lv_and(4). 2. Create Services Using the OData Channel 4. ENDIF. ELSEIF ( ls_key_tab-name = 'BANKID' ).. ls_key_tab-name = 'BANKL'.How To. wa_bnka TYPE BNKA. Add the implementation by type in the following or copying the contents of the attached file named get_entity. July 2012 9 . Right click on the method GET_ENTITY and in the context menu select Redefine. lv_value TYPE string. * Change OData key field names to the BNKA table properties name TRANSLATE ls_key_tab-name TO UPPER CASE.txt. Note: make sure to read the comments to understand what the code is doing. Delete the commented out section. VALUE ''''. IF ( ls_key_tab-name = 'BANKCOUNTRY' ).. ls_key_tab TYPE /IWBEP/S_MGW_NAME_VALUE_PAIR. * surround values with '' CONCATENATE con_filler ls_key_tab-value con_filler INTO lv_value. Open the Methods > Inherited Methods > /IWBEP/IF_MGW_APPL_SRV_RUNTIME node of your Bank runtime object. The method editor should show displaying the following: 4. CONSTANTS: con_filler(1) * Loop over the key values passed in LOOP AT it_key_tab INTO ls_key_tab. 5. This section will guide you thru how to implement the GET_ENTITY method to support reading in the information of a bank based on the bank key field values that are passed to the method. 1. TYPE string. 3. ls_key_tab-name = 'BANKS'.5 Redefine and Activate the GET_ENTITY Service The GET_ENTITY method is called for Read operations.

" throw exception ENDIF. 2. IF sy-subrc EQ 0.How To.6 Redefine and Implement the UPDATE_ENTITY Method The UPDATE_ENTITY method is called for the Update Operation (HTTP Put verb). Right click on the method UPDATE_ENTITY and in the context menu select Redefine. Save and Activate your changes. This section will guide you thru implementing this method for the Bank service we are creating. 4. * Get the data from table BNKA SELECT SINGLE banks bankl banka provz stras ort01 adrnr FROM BNKA INTO CORRESPONDING FIELDS OF wa_bnka WHERE (lv_string). Create Services Using the OData Channel * build where the string CONCATENATE lv_string lv_and ls_key_tab-name '=' lv_value INTO lv_string SEPARATED BY space. * fill the OData structure copy_data_to_ref( EXPORTING is_data = wa_bnka CHANGING cr_data = er_entity ). * now and is needed.. ELSE. 3. ENDLOOP. 1. The method editor should show displaying the following: July 2012 10 . lv_and = 'and'. this is where you will add code to update the given business data. Open the Methods > Inherited Methods > /IWBEP/IF_MGW_APPL_SRV_RUNTIME node of your Bank runtime object. 6..

Implement the update method calling the BAPI for Bank update by either typing in the following code. * Get the updated bank data io_data_provider->read_entry_data( IMPORTING es_data = ls_bnka ). or copying the contents of the attached file named update_entity. ls_bank_address_x-street = 'X'. CALL FUNCTION 'BAPI_BANK_CHANGE' EXPORTING BANKCOUNTRY BANKKEY BANK_ADDRESS BANK_ADDRESSX * * * * BANK_DETAIL BANK_DETAILX BANK_ADDRESS1 BANK_ADDRESS1X IMPORTING = ls_bnka-banks = ls_bnka-bankl = ls_bank_address = ls_bank_address_x = = = = July 2012 11 . ls_bank_address-street = ls_bnka-stras. ls_bank_address_x-city = 'X'. ls_bank_address_x TYPE BAPI1011_ADDRESSX. return TYPE BAPIRET2. ls_bank_address-city = ls_bnka-ort01. Delete the commented out section. ls_bank_address_x-region = 'X'..txt: DATA: ls_bnka TYPE BNKA. we won‟t be using that. Create Services Using the OData Channel 4. * Set X on fields that can be updated ls_bank_address_x-bank_name = 'X'. 5. * Move data into BAPI structure ls_bank_address-bank_name = ls_bnka-banka. ls_bank_address-region = ls_bnka-provz. ls_bank_address TYPE BAPI1011_ADDRESS.How To..

3. Create Services Using the OData Channel RETURN . Open the Methods > Inherited Methods > /IWBEP/IF_MGW_APPL_SRV_RUNTIME node of your Bank runtime object. The method editor should show displaying the following: 4. Save and Activate your changes. 6. 5. = return CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.How To. ls_bank_address TYPE BAPI1011_ADDRESS. 1. " throw exception ENDIF.. Right click on the method CREATE_ENTITY and in the context menu select Redefine. Implement the create_entity method calling the BAPI for Bank create by either typing in the below or copying the contents from the attached file name create_entity. copy_data_to_ref( EXPORTING is_data = ls_bnka CHANGING cr_data = er_entity ). Delete the commented out section.. IF ( return-type = 'E'). 2. 4.7 Redefine and Implement the CREATE_ENTITY Method The CREATE_ENTITY method is called for the Create operation (HTTP POST verb).txt: DATA: ls_bnka TYPE BNKA. This section will guide you thru implementing the CREATE_ENTITY method for the Bank service we are creating. we won‟t be using that. July 2012 12 .

8 Maintain OData Channel Configuration For Gateway to access the OData Channel service some configuration tables need to be configured. These tables define the metadata class. io_data_provider->read_entry_data( IMPORTING es_data = ls_bnka ).How To. ls_bank_address-city = ls_bnka-ort01. " throw exception ENDIF. This section will guide you thru configuring these tables for the Bank service.. 1. ls_bank_address-region = ls_bnka-provz. and then relates the metadata configuration to the runtime configuration for the service. Save and Activate your changes. IF ( return-type = 'E').. CALL FUNCTION 'BAPI_BANK_CREATE' EXPORTING BANK_CTRY BANK_KEY BANK_ADDRESS * * * * BANK_METHOD BANK_FORMATTING BANK_ADDRESS1 I_XUPDATE IMPORTING RETURN * BANKCOUNTRY BANKKEY . * Move data into BAPI structure ls_bank_address-bank_name = ls_bnka-banka. copy_data_to_ref( EXPORTING is_data = ls_bnka CHANGING cr_data = er_entity ). 4. Create Services Using the OData Channel return TYPE BAPIRET2. external service name (service to be defined in the ICF of the Gateway system). This configuration is done on the backend system where you created your Bank service classes. = return = ls_bnka= ls_bnka-bankl = ls_bnka-banks = ls_bnka-bankl = ls_bank_address = = = = 'X' 6. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'. runtime class. ls_bank_address-street = ls_bnka-stras. Go to transaction SPRO and click button title “SAP Reference IMG”: July 2012 13 .

Navigate the folder structure as shown below: SAP Customizing Implementation Guide > SAP NetWeaver > Gateway Service Enablement > Backend OData Channel > Service Development for Backend OData Channel 3. Click the Execute button next to Maintain Serivces: 4. Z_BANK_SERVICE_<Your Last Name> and Service Version „0001‟: July 2012 14 .. Create Services Using the OData Channel 2. Doing this will bring you to the maintain service screen: 5.How To.. Enter the Technical Service Name.

Enter in the Model Provider Class (Z_CL_BANK_MODEL_<Your Last Name>) and a Description: July 2012 15 .. Click the Create button. 12. and Object Model Version „0001‟: 11. Enter in the Data Provider Class (Z_CL_BANK_DATA_<Your Last Name>) and a Description: 8. 9. Click the Create Model button. Enter in the Technical Model Name Z_BANK_MODEL_<Your Last Name>. 7. Click the Create button. Save the service configuration. Create Services Using the OData Channel 6.How To.. 10.

Your service configuration should now look like the following: July 2012 16 . Click the Save button. Click the back button to navigate back to the service configuration: 15. 14..How To. 16.. 18. In the popup window enter the Object Model configuration you created in the last step: 17. Create Services Using the OData Channel 13. Save the configuration. Click the Assign Model button.

How To. 3. the services will be registered in the ICF.. You must go in and manually activate it using a transaction available on the Gateway system. Go to transaction /iwfnd/maint_service. This section will guide you thru the process of activating the Bank service.9 Activate the Service on the Gateway System The OData Channel service isn‟t automatically activated on the Gateway.. Click the “Add Service” button shown below outlined in red: July 2012 17 .. Once activated. 1. You should see something similar tothe following: 4. Logon to the Gateway System.. Create Services Using the OData Channel 4. . 2.

. Enter in the System Alias. Create Services Using the OData Channel 5. You should now see the following Add Service screen: 6. also enter in the Technical Service Name you defined in the prior section – Z_BANK_SERVICE_<Your Last Name>: 7. Hit the enter button – the service you configured earlier should show up: 8.How To.. in this case we are using the local system and the alias has been defined with the name “LOCAL”. Click the Technical Service Name link shown outlined in red below: July 2012 18 .

.. Your service has now been added to the Gateway system. Click the search icon to search for your service in the list – the search icon is outlined in red below: 13. Keep the defaults for the rest of the values and click the Enter button.How To. Create Services Using the OData Channel 9. Click the back arrow to go to the main service screen shown below: 12. In the Add Service popup window that is displayed set the package to $tmp if you are working with local objects (otherwise select an appropriate package): 10. 11. In the Find popup window enter in the Technical Service Name (Z_BANK_SERVICE_<Your Last Name>) for the search term: July 2012 19 .

this will cause the Alias assignment details be displayed at the bottom of the screen: 16. Create Services Using the OData Channel 14. 17. The LOCAL alias is assigned to this service for the OData Standard Mode runtime (SData is an older runtime that exists for backwards compatibility).. July 2012 20 . Click the Technical Service Name link (highlighted below in red). Click the “Call Browser” button to launch a web browser for the service‟s service document.. Click the enter button. your service should be located in the list: 15.How To.

To test you will need a REST Client.. Test the QUERY/GET_ENTITYSET operation... July 2012 21 . . Take the URL that was launched in the last step (in my case it is): http://server_name:8000/sap/opu/odata/sap/Z_BANK_SERVICE_GEBO5/?$format=xml 2.10 Test Your Service Now for the fun part! This section will guide you thru the testing of your new service. Create Services Using the OData Channel 18. 1. The browser should display something very similar to the following: 4. In the URL Replace $metadata? with BankCollection?$filter=bankCountry eq 'DE'&sap-ds-debug=true http://server_name:8000/sap/opu/sdata/sap/BANKGEBO/BankCollection?$filter=bankCountry eq 'DE'&sap-ds-debug=true Note: sap-ds-debug is a query string parameter provided by Gateway that helps debugging and testing…one of the things is does is format the output as HTML making it easier to navigate relationships between entity sets.How To.. there are many available…the guide is based on the FireFox REST Client plugin that is available for free download. Add $metadata after the /BANKGEBO/ in the URL and remove the query string parameters: http://server_name:8000/sap/opu/odata/sap/Z_BANK_SERVICE_GEBO5/$metadata 3.

For each bank listed in the BankCollection above should be a link to the READ operation: 5. Click the link to execute the entities get_entity method…this will display the entity‟s details: July 2012 22 .How To... Test the GET_ENTITY / READ operation. Create Services Using the OData Channel 4.

To pass in a header value we need to use the REST Client…here using the FireFox RESTClient: 7. 9. Enter the name / value as shown below: Tip: Check the “Save to favorite” check box so you can easily add this header for faster testing the next time! 11.How To. Click the Okay button. Copy the URL used in the test in step 5 above and paste it into the URL input field. Create Services Using the OData Channel 6. You should now see the following: July 2012 23 ... Remove the query string attribute “sap-ds-debug=true” from the URL. Click the Headers menu item and select Custom Header: 10. 8. To test the create and update functionality we will need a CSRF token (needed to prevent Cross Site Request Forgery attacks)…to do this we need to request this token during a read by passing in an http header value requesting the token.

. shown here outlined in red (note. Change the value for header attribute x-csrf-token to be the value you copied above. Click the Headers dropdown and select Custom Header. 17. Add the content-type header to the Request Headers section.type=entry: July 2012 24 . In the Response section at the bottom of the RESTClient copy the value returned for the x-csrftoken. these token values are generated by the gateway server): The token will be passed back in when testing the create and update functionality. to do this just click on the header attribute in the RESTClient you should now see something to the following: 15. Test the UPDATE_ENTITY / UPDATE operation. 14. Click the SEND button. 13.How To. Enter the name/value – content-type/application/atom+xml. Create Services Using the OData Channel 12.. 16.

Click the Okay button to add the header request. 19... Paste the Response Body you just copied into the Request Body section. 18. Change the Method dropdown to PUT. Switch to the “Response Body (Raw)” tab and copy the contents there (we will be u pdating the data that was sent back when reading the entity): 20. To test the update functionality we need to change some of the values in the request body that we are sending to the Gateway server…change the value for street and city: July 2012 25 . Your RESTClient should now look similar to the following: 22. 21. Create Services Using the OData Channel Tip: Save this as a favorite so you can easily add it again when testing.How To.

30. Set the Method dropdown to POST.. Your Request should now look similar to the following: July 2012 26 . for German banks the key must be 8 characters. Test the CREATE_ENTITY / CREATE operation. for US banks the key is 9 characters): Note: the important part of this request data is the XML values that you are changes…the rest can be ignored in this case. 27. In the Request Body change the bankID value to be something unique in the system (also.How To.. All you need to do is remove the ending portion of the URL used for the update that starts and ends with parenthesis…the URL should look like the following example: http://server_name:8000/sap/opu/odata/sap/Z_BANK_SERVICE_GEBO5/BankCollection 28. To test the create functionality we need to change the URL to be the same URL you would use when testing the GET_ENTITYSET method. 26. 24. 29. If the update is successful you will get a status code of 204 as shown below: 25. Click the SEND button. Create Services Using the OData Channel 23. You can switch the Method back to GET and click the send button again then check the response body to see if the values you changed for the update are returned by the read.

You should receive back a response status code of 201 if successful: 32.How To.. Create Services Using the OData Channel 31. When the create is successful a call is done to the URL specified in the Location header which is the URL used to read the newly created entity…you can see the contents of this call in the Response Body: 33. Congrats! You have successfully created and tested a simple OData service! July 2012 27 .. Click the SEND button.