All these SAP Netweaver Gateway tutorials you have read till now, is only to read the data from the back-end systems.
- Activate or Deactivate SAP Netweaver Gateway
- How to Connect SAP Gateway to Back-end Systems
- Structure of OData Service
- Model your first OData Service
- Implement your first OData Service
- Register your first OData Service
- Test your first OData Service
- Single record read of a OData Service
- Header and item data in OData Service
- 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.
1. Go back to service builder SEGW and Service Implementation → SalesOrderSet → Update → Right click → Go To ABAP Workbench.
2. Put the Data Provider Class(DPC) extension class in change mode and redefine the method SALESORDERSET_UPDATE_ENTITY( ) by clicking on redefine button.
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.
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. ENDIF. * Alpha Conversion CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING input = lv_so_id IMPORTING 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 ). CALL FUNCTION 'BAPI_EPM_SO_GET_DETAIL' EXPORTING so_id = lv_so_id IMPORTING 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'. CALL FUNCTION 'BAPI_EPM_SO_CHANGE' EXPORTING so_id = lv_so_id soheaderdata = ls_headerdata soheaderdatax = ls_headerdatax * PERSIST_TO_DB = ABAP_TRUE TABLES 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
6. After getting the response click on Use As Request button to copy the HTTP body to the left panel.
7. Change the currency code to ‘INR” and switch the HTTP method to PUT and execute it.
8. After successful execution, you will receive a HTTP response as HTTP 204.
9. Go back to the table and check the data is updated with new currency code.
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.
Click here to join our channel and stay updated with the latest tutorials and updates.