We need to implement the method Get Entity (Read) of an OData service.
1. Go back to SEGW and choose the service name ZSL_EPM_DEMO.
2. Expand the service. Service Implementation → GetEntity(Read) → Right Click → Go to ABAP Workbench.
3. Find the method SALESORDERSET_GET_ENTITY in DPC (Data Provider Class) ZCL_ZSL_EPM_DEMO_EXT and click on Redefine to redefine the method.
4. Let’s have a look at the signature of the method.
IT_KEY_TAB – stores the all key values and its value of the request. In our entity type the key is “SoId” .
ER_ENTITY – this is the exporting structure in which we need to pass the sales order details.
5. Write the below code in the method SALESORDERSET_GET_ENTITY
DATA: lwa_key_tab TYPE /iwbep/s_mgw_name_value_pair, lv_so_id TYPE snwd_so_id, lwa_snwd_so TYPE snwd_so. * 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. * Get the data from the table SELECT SINGLE * FROM snwd_so INTO CORRESPONDING FIELDS OF er_entity WHERE so_id = lv_so_id.
6. Save and activate the method and then DPC extension class.
7. Go to SAP Netweaver Gateway Client /IWFND/GW_CLIENT to test the service. Enter the service name with sales order number like below and the Execute.
8. The result will look like below.
You have successfully implemented a Single Read in SAP Netweaver Gateway OData service.
Stay tuned to us for more SAP Netweaver Gateway OData tutorials.Please feel free to comment and let us know your feedback.
SAPLearners.com is now on Telegram. Click here to join our channel and stay updated with the latest tutorials and updates.