Netweaver Gateway Development

Update data in SAP Backend using OData Service

Pre-requisites

1.SAP user id with developer access
2.abap skill 
3.Odata service created using SEGW.(If you dont know how to Please refer  my previous post step-by-step-gateway-odata-service)
4.GET_ENTITYSET implemented already.(If you dont know how to Please refer  my previous post http://www.techippo.com/2015/10/odata-service-implementation-for.html)
5.GET_ENTITY method implemented already(Refer OData Service Implementation for GET_ENTITY)

                 The Update operation is used when we want to update data on the backend server.The related HTTP method is PUT. If the Update operation is successful, you receive the HTTP 204 (no content) response code. Via the metadata, you can specify whether an entity set is updatable or not.In update operation you check the key and update the related resource.
                 In this tutorial we will use our flight service which was created in earlier tutorials.We will update a record in our SCARR table via OData service.We have seen how to create data in SAP Backend using OData Service in our previous tutorial.


Steps

  1. Open the service and click on edit button.Expand Data Model->Entity Sets and select our FlightSet.Then tick mark Updatable checkbox .Meaning is Updates of entries of the related entity type are supported.Dont forget to hit Generate Button.
  2. Expand Service Implementation node.Right click on Update and click on Go to Abap Workbench.
  3.  You will get an information message that method is not implemented. Click OK.
  4. You will now land on class builder with ****_DPC_EXT opened.We write our code in this class.Expand Methods node.expand Inherited Methods node.Right click on FLIGHTSET_UPDATE_ENTITY and click Redefine.
  5. Paste the code to access the flight details provided and update record in SCARR table inside method(FLIGHTSET_UPDATE_ENTITY) and activate it.Using the read_entry_data method of the import object reference io_data_provider, you can retrieve the data that was passed along the PUT request in the HTTP body. The entry is retrieved in the format of the entity type definition.Now you can update related record in SCARR table. 
  6.     data: ls_flight like er_entity.
        io_data_provider->read_entry_data( IMPORTING es_data = ls_flight ).
    
        UPDATE SCARR FROM LS_FLIGHT.
    
    

  7. Update operation implemented.Now you can test it.For testing open tcode /IWFND/GW_CLIENT.Paste url(/sap/opu/odata/sap/ZTEST_ODATA_SRV_01/FlightSet('AI')) and select GET http method then click execute button. You will get details of flight with carrid AI. 
  8. Now Click on Use as Request button in the right side.This is for copying the format of our entry data.Edit the data Select PUT http method.Do not change the url and press execute button.You will get a 204(No Content)  response. 
how to do OData update operation from sapui5 application?
 
If you enjoyed this post, Please Share!!

0 comments :

Post a Comment

Powered by Blogger.