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
Check out our ABAP Blogs ABAP – ABAP Skill