We have already discussed the Query, Read and create operations in our previous parts. Let’s explore Update Operations in OData service, as the name suggests update is to modify the entity which is already present in the system.

In our previous part, we have already created a sales order by using the post method. Let’s update the same.

Update Operations in Odata
Find out the update_entity method for the corresponding entity type and redefine the same

Update_entity method will have the following parameters

update_entity method
as we know in the previous part to get the payload details can be obtained from IO_DATA_PROVIDER and key information can either get from IT_KEY_TAB or using the object IO_TECH_REQUEST_CONTEXT

Let’s discuss the payload and URI part before we implement the actual logic inside the update_entity method.

We need to pass the key field in the URI and the payload in the HTTP request for the update entity. As we know the payload can be prepared either from the GET request or you can create manually. (Already covered in Part 7)

update entity URI
  METHOD orderrheaderset_update_entity.
    "Data declaration
    DATA:ls_payload    TYPE zcl_zxyz_sample_odata_mpc=>ts_orderrheader,
         ls_key_value  LIKE er_entity,
         lt_return     TYPE TABLE OF bapiret2,
         ls_header_in  TYPE bapisdh1,
         ls_header_inx TYPE bapisdh1x.

    "Get the payload information
        es_data = ls_payload ).

    "Get the key value i.e the order number
        es_key_values = ls_key_value ).

    "Call the BAPI to change the order
    ls_header_in-sales_off = ls_payload-vkbur.
    ls_header_inx-updateflag = 'U'.
    ls_header_inx-sales_off = abap_true.

        salesdocument    = ls_key_value-vbeln
        order_header_in  = ls_header_in
        order_header_inx = ls_header_inx
        return           = lt_return.
    IF NOT line_exists( lt_return[ type = 'E' ] ). "For success
    "Note: Error Handling part will be covered in the upcoming part


If you notice here we have not passed any response (er_entity exporting parameter) unlikely to create_entity method. It is not necessary to pass a response in case of update operation.

Let’s check out the result

PUT method
As we have not filled the ER_ENTITY (exporting parameter in the update_entity method) hence, the response is empty.
Sales order update
Sales office is being updated in the sales order

Note: It is not mandatory that you need to give all the attributes in the payload while performing PUT operation.

You can give even a single attribute in the payload. Like below

payload for update entity
debugging payload for update entity
During debugging inside the update_entity method

Are you curious to know about the Merge and Patch method in HTTP. Stay tuned for the next part 😉

Previous Part: Create(Create_entity) Method in OData SAP-Part 7-ABAP Skill

Next Part:

Check out our ABAP Blogs ABAP – ABAP Skill

Update entity details: https://help.sap.com/doc/d9c75eebcfa840c8a4aa4b0e6a8136de/3.0.14/en-US/7c04ddd1700610149b65d10d9609d8b0.html


What is the difference between Put,Patch,Merge OData-Part 9 · July 30, 2021 at 5:30 pm

[…] as input and the same payload will be received in the Updata_entity method as we have seen in the previous part. e.g – If you pass sales office i.e { “Vbkur” : “170” } then only […]

How to send messages as a response in OData – Part 10 · August 7, 2021 at 10:37 am

[…] of OData and implement the messaging logic inside that. Similar to update operation as covered in Part 8, Delete Operation has a method associated with it called […]

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *