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

ZARS/wp-content/uploads/2015/04/se11_dp_687586.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.

/wp-content/uploads/2015/04/service_impl_map_1_687969.jpg

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

/wp-content/uploads/2015/04/service_impl_map_2_688088.jpg

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


/wp-content/uploads/2015/04/service_impl_map_3_688115.jpg

Generate the model and do the service registration


4 Testing

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

/wp-content/uploads/2015/04/testing_1_688116.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


/wp-content/uploads/2015/04/testing_2_688136.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


To report this post you need to login first.

25 Comments

You must be Logged on to comment or reply to a post.

  1. Atanu Mallik

    Hello Arshad,

    good that you have shared this information. May be you can also share the component details/ prerequisites for this feature as this is will not be available by default.

    Atanu

    (0) 
      1. Yueqiang Zhu

        hi Arshad,

        i do not have the Business Entity in the list of map to data source.

        i am using netweaver 740 with sp08

        /wp-content/uploads/2015/12/2015_12_25_9_51_29_858010.jpg

        Do you have any idea?

        regards,

        Yueqiang

        (0) 
          1. Yueqiang Zhu

            Hi Arshad,

            thank you very mush. i found this under the context menu of the Entityset.

            and also noted that you have already pointed that out in your blog 🙂

            regards,

            Yueqiang

            (0) 
  2. Shakul Jugran

    Hello Arshad,

    I liked the way you explained it all in layman’s terms. Also, the last paragraph made for some fun reading as well 🙂

    Regards,

    Shakul.

    (0) 
  3. Indra Liana Lascu

    Hello Arshad,

    I have a strange problem, I can’t perform Map to Data Source.

    Every time I try that the system just freezes and I get no error prompt. I have tried different approaches and nothing seems to work. Do you have any idea why?

    Thank you very much,

    Indra

    (0) 
    1. Arshad Ansary Post author

      Hi Indra,

      I also faced this problem while doing it via Eclipse. Can you try logging in via R/3 Gui SEGW tranxn  and try the same?

      Regards
      Arshad

      (0) 
  4. Prashanth Prabhu

    Hi Arshad,

    you talked about the Get Entity set and Read. what about Create and Update?

    is it possible via the CDS ? can you throw some light what are the steps.

    Prashanth.

    (0) 
    1. Andre Fischer

      Hi Prashanth,

      no, this is not possible.

      You can however redefine the CREATE, UPDATE and DELETE method of the data provider extension classes and implement these methods so that your service will support all CRUD-Q methods.

      Best Regards,

      Andre

      (0) 
  5. Pieter Lemaire

    Nice blog Arshad!

    I followed the steps and my OData is created with a CDS view.

    But for testing I have some problems:

    Capture.PNG

    Does somebody has the same problem of knows the solution?

    Thanks in advance!

    Kind regards,

    Pieter

    (0) 

Leave a Reply