Sie sind auf Seite 1von 2

6/6/2020 CDS Part 3.

Expose CDS Views as OData Service through Annotation |

CDS Part 3. Expose CDS Views as OData


Service through Annotation
By Saswata - May 23, 2017

1
Shares

If you are following our series on SAP ABAP on HANA then you would be familiar with
CDS Views. If not, then please check our HANA ABAP Part IV where we introduced
Core Data Services and Part V where we took a Deep Dive into CDS Views. Also, if you
have been taking the advantage of our SAP Netweaver Gateway and OData Services
Tutorial series, you would know that SEGW is the t-code to create OData Projects and
eventually publish an OData Service.

But would you not be surprised if we say, you can create your OData Projects without
going to SEGW transaction? Today, we would show you how you can expose CDS View
as OData Services with just some Annotations (i.e SQL code).

Introduction
We have substantially explored the CDS views with major functionalities. CDS provides
another magical strength to the users to expose the views as OData services. There is a
conventional way to create a service in SEGW importing the view you created.

This article presents a technique to expose a view as a gateway service just by


maintaining a cool annotation. No need to create service through SEGW. Sounds
amazing? Let’s see how we can achieve that.

Technical Environment
For CDS views we have used Eclipse Luna.
OData version 2 has been used for gateway application.

Step – I :
Create a view with a left outer join between tables VBAP and MARA. We have considered
VBAP as ‘soitem’ and MARA as ‘prod’. A left outer join between two will allow you to
select any fields from these two tables. For simplicity, we took only the fields mentioned
in the key.

https://sapyard.com/abap-on-sap-hana-part-xv-expose-cds-views-as-odata-service-through-annotation/ 1/8
6/6/2020 CDS Part 3. Expose CDS Views as OData Service through Annotation |

1
Shares

Fig.1-Create First View

Step – II :
Create a second view with Association. Associations in CDS views are more like
associations in Gateways. You create an association to conceptually join or associate
one data source to a target data source on a condition provided. If data sources
can be envisaged as Entities of OData service then associations are joining two entities
conceptually.

Fig.2- Create view with Association and OData Annotation

Take special note of the Annotation at the 6th line: @OData.publish: true. This is the
magic spell for our article today. 🙂

Step – III :
Now our view is ready. With the DDL view we should be able to see data from Header
table VBAK, Item table VBAP and Product table MARA.

https://sapyard.com/abap-on-sap-hana-part-xv-expose-cds-views-as-odata-service-through-annotation/ 2/8

Das könnte Ihnen auch gefallen