UPDATE data in Back-end using OData Service


All these SAP Netweaver Gateway tutorials you have read till now, is only to read the data from the back-end systems.

  1. Activate or Deactivate SAP Netweaver Gateway
  2. How to Connect SAP Gateway to Back-end Systems
  3. Structure of OData Service
  4. Model your first OData Service
  5. Implement your first OData Service
  6. Register your first OData Service
  7. Test your first OData Service
  8. Single record read of a OData Service
  9. Header and item data in OData Service
  10. Association and Navigation in OData Service

In contrast to the READ access, CREATE, UPDATE and DELETE methods are also available in the OData service to create,update and delete the data in back-end systems.

Lets see how we can do that.

In this tutorial we UPDATE the existing data in back-end systems. Lets look what data we are going to update.

We have sales order#500000002 in table SNWD_SO with Currency Code = EUR, we are going to modify the Currency Code to INR.

SAP OData UPDATE Entity Step1

1. Go back to service builder SEGW and Service Implementation → SalesOrderSet → Update → Right click → Go To ABAP Workbench.

SAP OData UPDATE Entity Step2

2. Put the Data Provider Class(DPC) extension class in change mode and redefine the method SALESORDERSET_UPDATE_ENTITY(  ) by clicking on redefine button.

SAP OData UPDATE Entity Step3

3. Before jumping in to code lets look at the signature of the method and understand what parameters we can use.

In the signature two parameters are important, one is IT_KEY_TAB which contains the key field value to which we need to update the data like sales order number and other one is IO_DATA_PROVIDER which contains what data we need to update.

In our case IT_KEY_TAB will have sales order number and IO_DATA_PROVIDER contains new currency code.

SAP OData UPDATE Entity Step4
DATA: lwa_key_tab           TYPE /iwbep/s_mgw_name_value_pair,
      lv_so_id              TYPE bapi_epm_so_id,
      ls_salesorder         LIKE er_entity,
      ls_headerdata         TYPE bapi_epm_so_header,
      ls_headerdatax        TYPE bapi_epm_so_headerx,
      lt_return             TYPE STANDARD TABLE OF bapiret2.

* Step-1 : To get the Sales Order#
READ TABLE it_key_tab INTO lwa_key_tab WITH KEY name = 'SoId'.
IF sy-subrc = 0.
lv_so_id = lwa_key_tab-value.

* Alpha Conversion
input        = lv_so_id
output        = lv_so_id.

* Step-2 : Read the new data from the service that needs to be updated
io_data_provider->read_entry_data( IMPORTING es_data = ls_salesorder ).

so_id           = lv_so_id
headerdata       = ls_headerdata.

* Step-3 : Update the data
ls_headerdata-currency_code  = ls_salesorder-currency_code.

ls_headerdatax-so_id      = lv_so_id.
ls_headerdatax-currency_code = 'X'.

so_id              = lv_so_id
soheaderdata        = ls_headerdata
soheaderdatax       = ls_headerdatax
return              = lt_return.

5. Activate the Data Provider Class extension class(DPC_EXT). To test the service go to SAP Netweaver Gateway Client /IWFND/GW_CLIENT.

First we need to perform the single read to get the HTTP response body and we will be using the same HTTP body to push back the request to server with new Currency Code.

Execute the below URI with GET HTTP method


SAP OData UPDATE Entity Step5

6. After getting the response click on Use As Request button to copy the HTTP body to the left panel.

SAP OData UPDATE Entity Step6

7. Change the currency code to ‘INR” and switch the HTTP method to PUT and execute it.

SAP OData UPDATE Entity Step7

8. After successful execution, you will receive a HTTP response as HTTP 204.

SAP OData UPDATE Entity Step8

9. Go back to the table and check the data is updated with new currency code.

SAP OData UPDATE Entity Step9

Congrats! You have successfully used the UPDATE operation in SAP Netweaver Gateway OData service. Please stay tuned for SAP OData tutorials.

Leave a comment in the below comment section and let us know your feedback. Thank you.

Comments are closed.