Read Operation with GET_ENTITY .
The post describes how to implement the data provider extension class for the READ operation. [ Check the link oData- Part1 to create the entity type, entity set and runtime artifatcs.]
The SCARR table entries.
We have the project. In the entity data model ‘Carrid’ is the only key.
Go to the data provider extension class- ZCL_ZSCARR_DEMO_DPC_EXT. Right click on it and choose Go to ABAP workbench.
Select change mode. Select the method: SCARRS_GET_ENTITY and click on the redefine button.
Now when we request with the URL
https://server address/sap/opu/odata/sap/ZSCARR_DEMO_SRV/Scarrs(‘AA’), the IT_KEY_TAB is filed with the key value pair and return as a structure ER_ENTITY.
Put the below code:
DATA: lv_carrid TYPE scarr–carrid.
CHECK it_key_tab IS NOT INITIAL.
DATA(ls_key) = it_key_tab[ 1 ].
lv_carrid = ls_key–value.
SELECT SINGLE * FROM scarr INTO CORRESPONDING FIELDS OF er_entity
WHERE carrid = lv_carrid.
Activate the code and go back.
Go Back.
From the Service Implementation , choose Maintain.
Choose Call Browser.
Well, here we have the XML format.
Now we have to form the url to read details with the key ‘Carrid’.
https://server address/sap/opu/odata/sap/ZSCARR_DEMO_SRV/Scarrs(‘AA’)
https://server address/sap/opu/odata/sap/ZSCARR_DEMO_SRV/Scarrs(‘LH’)
To check the html format we can use the below url as
https://server address/sap/opu/odata/sap/ZSCARR_DEMO_SRV/Scarrs(‘LH’)?sap-ds-debug=true
One comment