Odata Service For CDS View Using Annotations
Odata Service For CDS View Using Annotations
A new and easy way of creating OData services based on CDS views was introduced
using the annotation @OData.publish: true at view level.
Let's see how we can expose the ABAP CDS View as OData Service using an example and
below is the exposure process.
1. Create an ABAP CDS view using ABAP Development Tools. Copy and paste the below
code in DDL editor.
@AbapCatalog.sqlViewName: 'ZV_ODATA_DEMO'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
carrname as AirlineName,
currcode as Currency,
url as AirlineURL
}
2. Add the annotation @OData.publish: true above the DEFINE VIEW statement.
3. After adding the annotation to CDS View save and activate the view.
@AbapCatalog.sqlViewName: 'ZV_ODATA_DEMO'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@OData.publish: true
carrname as AirlineName,
currcode as Currency,
url as AirlineURL
}
CDS view should meet following rules for successful OData service generation.
4. After activating the CDS view, following Gateway artifacts will be generated by the
SADL framework in back-end server.
8. As a
Result OData service is activated successfully in the Gateway hub system. Launch the
transaction code “/IWFND/GW_CLIENT” to test the service.
Above is the metadata generated for the OData service created based on the ABAP CDS
view. Let's closely look at the metadata and identify the different artifacts as part of the
OData service.
URL:
http://<server>:8001/sap/opu/odata/sap/ZODATA_DEMO_CDS/ZODATA_DEMO
Example #2 – ABAP CDS View with Parameters
@AbapCatalog.sqlViewName: 'ZV_ODATA_DEMO_P'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@OData.publish: true
carrname as AirlineName,
currcode as Currency,
url as AirlineURL
2. Repeat the steps explained above in the Example #1 to create the OData service for
this CDS view also.
3. On successfully OData service generation, execute the OData service and look at the
metadata generated and following are the 2 entity sets generated
ZODATA_DEMO_PARAMSSet – Entity set which has 2 key predicates, one is the input
parameter and the second one is the key of ABAP CDS View. You need to pass these 2
key predicates while accessing the data
To access the data you can use both entity sets and lets look how we can form the URI
for both of them.
/sap/opu/odata/sap/ZODATA_DEMO_PARAMS_CDS/
ZODATA_DEMO_PARAMSSet(p_carrid=’AA’,AirlineCode=’AA’)
If you like to use entity set ZODATA_DEMO_PARAMS following the URI to be used
/sap/opu/odata/sap/ZODATA_DEMO_PARAMS_CDS/
ZODATA_DEMO_PARAMS(p_carrid=’AA’)/Set