How To Create OData Service For ABAP CDS Views Using Annotation
How To Create OData Service For ABAP CDS Views Using Annotation
Hello
Shares everyone in this tutorial we will see on how to create SAP OData service for an ABAP CDS views using
annotation @OData.publish: true. Lets get started
We usually create OData services in SAP Gateway system using transaction SAP Gateway Service Builder(SEGW).
A new and easy way of creating OData services based on CDS views was introduced using the annotation
@OData.publish: true at view level.
Lets see how we can expose the ABAP CDS View as OData Service using an example and below is the exposure
process.
Step-by-Step Procedure
1. Create an ABAP CDS view using ABAP Development Tools in Eclipse. Copy and paste the below code in DDL editor.
1. @AbapCatalog.sqlViewName: 'ZV_ODATA_DEMO'
2. @AbapCatalog.compiler.compareFilter: true
3. @AccessControl.authorizationCheck: #NOT_REQUIRED
4. @EndUserText.label: 'OData service on ABAP CDS View'
5.
6.
7. define view ZODATA_DEMO as select from scarr
8. {
9. key carrid as AirlineCode,
10. carrname as AirlineName,
11. currcode as Currency,
12. url as AirlineURL
13. }
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.
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you
are happy with it. Accept
http://www.saplearners.com/create-odata-service-abap-cds-views-using-annotation/ 1/6
9/30/2018 How to create OData service for ABAP CDS Views using Annotation
1. @AbapCatalog.sqlViewName: 'ZV_ODATA_DEMO'
2. @AbapCatalog.compiler.compareFilter: true
3. @AccessControl.authorizationCheck: #NOT_REQUIRED
4. @EndUserText.label: 'OData service on ABAP CDS View'
5.
6.
Shares
@OData.publish: true
7. define view ZODATA_DEMO as select from scarr
8. {
9. key carrid as AirlineCode,
10. carrname as AirlineName,
11. currcode as Currency,
12. url as AirlineURL
13. }
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.
You can find all these artifacts in the transaction code – “/IWBEP/REG_SERVICE”.
5. Launch the transaction code “/IWFND/MAINT_SERVICE” to activate the OData service in hub system. Enter
System Alias, Technical Service Name and click the Get Services button. The service will be displayed for selection.
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you
are happy with it. Accept
http://www.saplearners.com/create-odata-service-abap-cds-views-using-annotation/ 2/6
9/30/2018 How to create OData service for ABAP CDS Views using Annotation
Shares
6. In the Add Service dialog box enter the package name. Technical service name and Technical model name will
already be suggested. Click on OK to continue.
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.
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you
are happy with it. Accept
http://www.saplearners.com/create-odata-service-abap-cds-views-using-annotation/ 3/6
9/30/2018 How to create OData service for ABAP CDS Views using Annotation
Shares
Above is the metadata generated for the OData service created based on the ABAP CDS view. Lets closely look at
the metadata and identify the different artifacts as part of the OData service.
1. @AbapCatalog.sqlViewName: 'ZV_ODATA_DEMO_P'
2. @AbapCatalog.compiler.compareFilter: true
3. @AccessControl.authorizationCheck: #NOT_REQUIRED
4. @EndUserText.label: 'OData service on ABAP CDS View'
5.
6. @OData.publish: true
7. define view ZODATA_DEMO_PARAMS
8. with parameters p_carrid :S_CARR_ID
9. as select from scarr
10.
11. {
12. key carrid as AirlineCode,
13. carrname as AirlineName,
14. currcode as Currency,
15. url as AirlineURL
16. }
17. where carrid = $parameters.p_carrid
NOTE: As of now there is no annotation/a way to make the input parameters OPTIONAL in ABAP CDS Views. So you
have to pass values for all input parameters in ABAP CDS view while accessing the data from it.
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
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you
are happy with it. Accept
http://www.saplearners.com/create-odata-service-abap-cds-views-using-annotation/ 4/6
9/30/2018 How to create OData service for ABAP CDS Views using Annotation
Shares
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
ZODATA_DEMO_PARAMS – Entity set which has 1 key predicate, which is input parameter. You need to pass this key
predicate to access 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.
If you like to use entity set ZODATA_DEMO_PARAMSSet following the URI to be used
/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
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you
are happy with it. Accept
http://www.saplearners.com/create-odata-service-abap-cds-views-using-annotation/ 5/6
9/30/2018 How to create OData service for ABAP CDS Views using Annotation
Shares
Congrats!! You have successfully created an OData service for an ABAP CDS view. Please stay tuned for more
tutorials.
Please feel free to comment and let us know your feedback. Subscribe for more updates.
Send us a message
Email Address
SEND MESSAGE
Powered by Sumo
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you
are happy with it. Accept
http://www.saplearners.com/create-odata-service-abap-cds-views-using-annotation/ 6/6