Quantcast
Channel: SCN : All Content - SAP Gateway
Viewing all articles
Browse latest Browse all 2823

Creating Odata services out of CDS views

$
0
0

Introduction

The purpose of this blog is to show how HANA Artifact CDS view can exposed as Odata service to consumer.


1 CDS (Core Data Services) Views

CDS(Core Data Service) views  is the newest kid in the block in HANA . It allows you to do much more compared to classical view

 

  • Push Code to Data  Base layer by allowing queries ,calculations and imperative statements at the DB layer(instead of application service layer)
  • Allows you to add associations with other business entities/tables
  • Annotations to semantically describe your data model

 

I am not going to get vociferous about CDS because there is enough documentation already available .

 

Please refer this ABAP on HANA open sap course for more details.

https://open.sap.com/courses/a4h1

 

For creating CDS views there are some prerequisites

 

  • Eclipse should be installed
  • ADT(Abap Development Tools) add on should be installed
  • SAP NetWeaver AS ABAP 7.4 SP05 or higher running on a SAP HANA database SPS6 should be available

 

The ABAP system in which I am trying is NW7.4 SP8 system

 

Once we are done with prerequisites , we will create a CDS view .

 

This CDS view will join tables SNWD_SO(Sales Order) and SNWD_BPA (Business Partner) and find out sum of invoices whose gross amount is greater than 10000000.

 

@AbapCatalog.sqlViewName: 'ZDDLS_CDS_AGGR'
@EndUserText.label: 'CDS view for aggregation'
define view Zars_Cds_Aggr as select from snwd_so as so
inner join snwd_bpa as bpa
on so.buyer_guid = bpa.node_key
{ key bpa.bp_id as BusinessPartner,  bpa.company_name,  sum( so.gross_amount ) as  Total_Gross_Amount,  so.currency_code
}
group by
bpa.bp_id,    bpa.company_name,    so.currency_code    having sum(so.gross_amount) > 100000000

Here you can see there are two views - The View ZDDLS_CDS_AGGR is DDLS(DDL source view) name which can be viewed in SE11 and this object is integrated with the CTS (Change and transportation system) .The other view ZARS_CDS_AGGR is the CDS view name

 

Now we will check the results of the CDS Views. We can do it in two ways

 

a Open Data preview of CDS view in Eclipse


Eclipse_dp.jpg

 

 

Now the results

Eclipse_dp_1.jpg

b You can see the result in classical se11 transaction also. But this time we should give the DDL SQL view name ZDDLS_CDS_AGGR

 

 

 

ZARSse11_dp.jpg

2 Data Modelling in Gateway Builder


As we are done with CDS view building , we will move to Gateway data modeling part . The good thing here is we don't need to switch to GUI for Gateway builder transaction. We can run the SEGW transaction from eclipse itself as an embedded GUI. Just press CTRL+SHIFT+A and give SEGW.

 

We Create  data model based on DDLS view ZDDLS_CDS_AGGR

 

GW_builder_Data_modeling_1.jpg

GW_builder_Data_modeling_2.jpg

Click on Next button

 

GW_builder_Data_modeling_3.jpg

select the properties we want in the entity( ignore the MANDT field)

 

GW_builder_Data_modeling_4.jpg

Here we can see the property names of the entity has been automatically adjusted (Camel case) and we need to mark the Business Partner as the key property of the entity

 

Press finish to complete the data model part

 

3 Service implementation

Now we are done with Data model , we look into the data provisioning part.

Here we give the data source name as CDS view name ZARS_CDS_AGGR

Right click on the entity set SalesAggregationSet under service implementation and select Map to Data source . The important point here is we are not mapping the GetEntitySet operation of the entityset but the entityset itself.

service_impl_map_1.jpg

We have to select type as Business Entity and use F4 help to select CDS view  ZARS_CDS_AGGR.

service_impl_map_2.jpg

We then do the mapping of Entity properties with the CDS view fields. Strangely propose mapping button seems to be not there


service_impl_map_3.jpg

Generate the model and do the service registration


4 Testing

Now we head to GW client for testing . We test the SalesAggregationSet.

testing_1.jpg



In the above case we have not implemented the query operation but we use the URL of the query operation to get the CDS view results .

One more thing that comes free is the read operation .No separate implementation of READ (GET_ENTITY) required.


So if We put the below URL

/sap/opu/odata/SAP/ZARS_CDS_SIMPLE_SRV/SalesAggregationSet('100000014') also, we get the results


testing_2.jpg



Conclusion

ABAP is not only 'ABAP' right now . For a complete End to End scenario , now we need to proficient across three layers (ABAP,Gateway,UI) which seems to be close to impossible .  But as  grey haired 'Abaper' , it is required that we at least keep up to date with  how ABAP is evolving itself for HANA DB and how its pushing the changes  in Gateway layer. The easiest solution will be to ignore all the changes happening around us and stick to the old classical style. But that will be a gap too big to bridge



Viewing all articles
Browse latest Browse all 2823

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>