Netweaver Gateway Development

Delete 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 Delete operation is used when we want to delete data on the backend server.The related HTTP method is DELETE. If the Delete operation is successful, you receive the HTTP 204 (no content) response code. Via the metadata, you can specify whether an entity set is deletable or not.In delete operation you check the key and delete the related resource.
                 In this tutorial we will use our flight service which was created in earlier tutorials.We will delete 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 Deletable checkbox .Meaning is Deletion of entries of the related entity type are supported.Dont forget to hit Generate Button. 
  2. Expand Service Implementation node.Right click on Delete 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_DELETE_ENTITY and click Redefine.  
  5. Paste the code to access the flight key fieldss provided and delete the record in SCARR table inside method(FLIGHTSET_DELETE_ENTITY) and activate it.Using the GET_KEYS method of the import object reference io_tech_request_context, you can retrieve the key value pairs.Now you can delete related record in SCARR table based on the obtained key value(here carrid).



  6. Delete 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 DELETE http method then click execute button. You will get 204 (No content) response. 
how to do OData delete operation from SAPUI5 Application?
If you enjoyed this post, I’d be grateful if you’d help it spread by sharing.Thank you! See you soon

0 comments :

Post a Comment

Powered by Blogger.