Update an Entity using SAP OData

Many times, we come across a scenario where we want to update the data records, for example, we want to update the phone number or address.

This article describes the step-by-step procedure to implement and test update operations in SAP OData.

Context

Update entity can be implemented by the redefining UPDATE_ENTITY method.

  1. Using PUT HTTP method.
  2. Using PATCH HTTP method.

Difference between PUT and PATCH HTTP method

  • PUT: The request body is considered as the updated version of the original data stored in the database. When using PUT, we need to send the full payload in our request.
  • PATCH: It is used for the partial modification of the resource. When using PATCH, we only send the data to be modified in the request body.

Procedure

  1. Open *DPC_EXT class artifact of OData and redefine *UPDATE_ENTITY method.
  2. Reimplement the method for the update.
    UPDATE_ENTITY method
  3. Activate the class and register the service.
  4. Execute and test the OData.
    1. Select Entity set
    2. Get the data to be updated using the GET request
    3. Click on Use as Request to copy the HTTP response to HTTP request which works as input.
      Execute and test the OData
    4. Change the field value Carname and URL in HTTP Request
    5. Select PUT option
    6. Add the key value to be updated in the request URL
    7. Execute the request
      Execute and test the OData PUT Request
    8. Status code 204 represents success
      PUT Request response
    9. Verify-in the table data is successfully updated.
      verify the updated data

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.