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_entity method will have the following parameters
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)
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
io_data_provider->read_entry_data(
IMPORTING
es_data = ls_payload ).
"Get the key value i.e the order number
io_tech_request_context->get_converted_keys(
IMPORTING
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.
CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
EXPORTING
salesdocument = ls_key_value-vbeln
order_header_in = ls_header_in
order_header_inx = ls_header_inx
TABLES
return = lt_return.
IF NOT line_exists( lt_return[ type = 'E' ] ). "For success
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
ENDIF.
"Note: Error Handling part will be covered in the upcoming part
ENDMETHOD.
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
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
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
2 Comments
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 […]