Skip to Content

The Challenge

With the availability of the SAP HANA platform there has been a paradigm shift in the way business applications are developed at SAP. The rule-of-thumb is simple: Do as much as you can in the database to get the best performance. This is also true for the underlying data models of the business applications.

Until now, data modeling in ABAP typically involved organizing your data in database tables/views and often providing some additional high-level services for the applications using suitable ABAP frameworks. It stands to reason that to enable real-time businesses some of these services should ideally also be brought closer to the data(base).

This presents several challenges. High quality data models should provide a single definition and format for the data. They should be clear and unambiguous, reusable and flexible, even extensible. So how can you capture the semantics of the data model in the database so that the model can be easily reused by different consumers, e.g. by OData clients and by OLAP tools? How can you extend the meta model to service your applications? Impossible, you say?  Maybe, if we didn’t have Core Data Services (CDS).

The Solution

CDS simplifies and harmonizes the way you define and consume your data models, regardless of the consumption technology. Technically, it is an enhancement of SQL which provides you with a data definition language (DDL) for defining semantically rich database tables/views (CDS entities) and user-defined types in the database. The enhancements include:

  • Annotations to enrich the data models with additional (domain specific) metadata
  • Associations on a conceptual level, replacing joins with simple path expressions in queries
  • Expressions used for calculations and queries in the data model

CDS entities and their metadata are extensible and optimally integrated into the ABAP Data Dictionary and the ABAP language.

CDS is supported natively in both the ABAP and the HANA Platforms! In fact, CDS is (in my opinion) the most ambitious and exciting SAP development in the area of data modeling in recent years. You can finally define and consume your data models in the same way (syntax, behaviour, etc.) regardless of the SAP technology platform (ABAP or HANA). Unwantedly the phrase: “One Data Model to rule them all” always comes to mind when I think of CDS.

CDS Support in SAP NW ABAP 7.4 SP5

With SAP NW ABAP 7.4 SP5 the first instalment of CDS support in ABAP has been delivered. This provides you with advanced viewbuilding features which you can use to optimize your data models.

Prerequisite is the ABAP Development Tools for Eclipse (ADT) 2.19 since the new CDS tooling is only available in ABAP in Eclipse.

Let’s take a look at some of these new features ABAP in Eclipse.

Create a new DDL source file

You can create a new DDL source in ABAP in Eclipse via File > New > Other … > ABAP > DDL Source

NewABAPDDLSource.png

View definition

Your new DDL source is opened in a text editor in ABAP in Eclipse. Initially the source is empty. Using the DEFINE VIEW statement you can define your CDS view entity.

SimpleSalesOrder.png

View entities are defined as selects from one or more datasources. Datasources can be other view entities, database tables or classical DDIC views (SE11 views). The select list ist defined in curly brackets after the from clause (great for code completion!). The elements in the select list are separated by a comma. The code snippet above defines a simple view entity called SalesOrder on the database table SNWD_SO. SNWD_SO contains the sales orders data.

Currently you can only define one CDS entity per DDL source.

Joining data sources

You can combine records from two or more data sources using join clauses. You can also specify aliases for the datasources.

JoinedSalesOrder.png

In addition to INNER JOIN you can also model a LEFT OUTER JOIN, RIGHT OUTER JOIN, UNION and/or UNION ALL.

The comparison operators BETWEEN, =, <>, <, >, <=, >=, NOT and LIKE can be used in the on and where clauses. In addition IS NULL and IS NOT NULL are also valid where-conditions.

Aggregations and SQL functions

CDS also provides support for aggregations (SUM, MIN, MAX, AVG, COUNT), SQL functions (LPAD, SUBSTRING, MOD, CEIL, CAST) and CASE statements in view entities.

AggregationsSQLFunctions.png

In the above example the view selects the business partners with outstanding sales orders which together (SUM) amount to more than EUR 100.000 (HAVING SUM). The outstanding amounts are reported per business partner role (GROUP BY). The codes for the business partner roles are translated to readable text in the database (CASE).

Semantically rich data models

Annotations can be used to add metadata to CDS entities. Annotations specify the properties and semantics of the entity and its behaviour when it is accessed at runtime. This metadata can also be accessed by consumption tools using special APIs. In future, consumers will be able to extend existing view definitions and add their own annotations without having to re-model the data (“One Data Model to rule them all“). Annotations always begin with the @ character.

Annotations.png

Above the SAP buffering behaviour is specified using the @AbapCatalog.buffering annotation. Here single record buffering is enabled (prerequisite is that the underlying datasource allows buffering). In addition the element currency_code is defined as a currency key. The element gross_amount is defined as a currency field and the currency key currency_code is assigned to the field.

In every view definition the compulsory annotation @AbapCatalog.sqlViewName must be specified. This annotation specifies the name of the corresponding view in the ABAP Dictionary. CDS entities are integrated into the ABAP Dictionary and ABAP language using the same infrastructure which exists for classical Dictionary views. The CDS entity name (here SalesOrder) can be thought of as an alias for the Dictionary View. The metadata which is specified for the CDS entity, however, can only be accessed via the entity name.

Further information about the supported predefined annotations can be found in our CDS keyword documentation.

Extensibility

The ABAP Dictionary enhancement concept is also supported in ABAP CDS entites. By using $EXTENSION.* in the select list, all fields that are added as enhancements to the underlying database table or classical DDIC view are automatically added to the CDS entity.

Extension.png

Here any fields which are added to the database table SNWD_SO via enhancements, will automatically be added to the view entity. Currently it is only possible to use $EXTENSION.* in view definitions with exactly one datasource (no joins, unions, etc.).


In future, CDS will also provide additional features for extending existing CDS entities themselves (not via the underlying datasource). These features will be available on both the ABAP and HANA platforms.

Consuming your CDS entities in ABAP

Once you have saved and activated your DDL source, the DDIC artifacts are created. Consuming your CDS entity is simple: CDS entities can be used in OPEN SQL! You should always use the entity name in your OPEN SQL statements.

SELECT * FROM SalesOrder INTO TABLE @itab. “Use entity name

Note that when selecting from CDS entities in OPEN SQL, the new OPEN SQL syntax must be used. This means that the ABAP variables (in this case itab) must be escaped using the @ character. The @ character in OPEN SQL has nothing to do with CDS annotations. For more information about the new OPEN SQL syntax, see the ABAP keyword documentation


Lifecycle and database support


The best part about DDL sources and CDS entities is that they are managed by ABAP. This means that the entire lifecyle of the CDS entities are controlled by the ABAP Change and Transport System (CTS).

In addition, the SP5 CDS features are “open”. This means that your CDS view definitions can be deployed on any database which is supported by SAP.

Summary

Well, that was an attempt to give you a condensed overview of Core Data Services (CDS) in SAP NW ABAP 7.4 SP5. Not easy when you are introducing the next game changer in SAP application development.

To sum it up: CDS provides enhanced view building capabilities to enable you to easily define semantically rich and re-useable data models in the database. The new view building features include new join types, new clauses as well as support for aggregate functions and SQL functions. All these features are “open”. The features are provided in a new text editor for DDL sources in ADT 2.19.

But the journey doesn’t end here. There will continue to be future CDS feature deliveries in ABAP and even in 7.4 SP5 there is still a lot to tell. We haven’t even touched on associations or the cast functionality, not to mention the cool editor features. But that will have to wait for another time (otherwise nobody will read this lengthly blog).

If you can’t wait you can get more information by watching Carine’s video tutorial (“Building Core Data Services Views in ABAP on SAP HANA“). Or you can check out our CDS keyword documentation. For more information about the CDS support in the HANA Platform, see the SAP HANA Developer Guide.




To report this post you need to login first.

78 Comments

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

  1. Abdul Hakim

    Hi Christiaan – What is the difference between creating the CDS view entity with annotation and without? This part is not clear for me..Also after defining the CDS view whether the same can be viewed through SE11?

    Thanks

    Hakim

    (0) 
    1. Christiaan Edward Swanepoel Post author

      Hi Hakim,

      In the first delivery for CDS support in ABAP, we only support “core” annotations. This means that consumers cannot yet define their own annotations and further enrich the existing data models themselves.

      Many of these core annotations have default values. If you do not, for example, specify the buffering behaviour for your view, then the default is “no buffering”. So if you don’t use the annotations, in many cases you get the default values. Some core annotations, however, don’t have default values (e.g. “currency code” annotations). If you don’t use these then the information is simply missing. You can still activate and use your view but higher-level tools, e.g. UIs, will not have any information about which field contains the currency code for an amount.

      As mentioned above, in the context of ABAP, there is one compulsory annotation: @AbapCatalog.sqlViewName. You cannot activate your view if this annotation is not specified.

      W.r.t you second question, the view entites cannot be viewed in the SE11. The corresponding DDIC view (specified in the sqlViewName annotation) can be viewed in the SE11, but the view is read-only and very often the informaton displayed is inconsistent. This is because CDS support many features which cannot be displayed in the SE11, e.g. UNIONs. The best place to browse the views is in the new DDL editor.

      Regards

      Chris

      (0) 
      1. Kris Claes

        We just got this interesting CDS and some questions occur.

        @AbapCatalog.sqlViewName: ‘sql_view_name’
        @EndUserText.label: ‘Mijn eerste probeersel met CDS’
        define view Zs_Cds_Number_One as select from hrp1000 {

        key hrp1000.otype,

                hrp1000.objid
            }

        Is there a way to ‘synchronise‘ both names, to make sure they are equal? Is a Code Inspector check possible on these views e.g.

        Regards.

        Kris

        (0) 
        1. Christiaan Edward Swanepoel Post author

          Hi Kris,

          this is not possible. The sqlViewName and the entity name (here ‘Zs_Cds_Number_One’) share the same namespace. This means that you have to specify different names otherwise you will get syntax errors.

          The sqlViewName also has the same restrictions as the view names in the SE11. The sqlViewName can be max. 16 characters long. The entity name, however, can be 30 characters long. This extension allows you to implement better names for your CDS entities. Names which better convey the semantics. Keeping the names the same (even if it was possible) would mean that you would have to apply the same restrictions to the entity name. You’d be “wasting” the additional characters.

          The entity name can, however, have the same name as the DDL source name. We don’t check this since the CDS specification allows for multiple entities to be implemented in the DDL source. This has not yet been implemented in ABAP, but when/if it is, then you probably don’t want the DDL name to be the same as one entity in your source. You would probably prefer to choose a source name which describes the semantics of all the included entities.

          Cheers

          Chris

          (0) 
  2. Vikas Singh

    Great example !

    I hope I’m not the only one tripped by omission of @ for Host variables when trying out these examples.

    select * from salesorder into table lt_salesorder. <- Error

    select * from salesorder into table @lt_salesorder. <- This works fine

    (0) 
    1. Christiaan Edward Swanepoel Post author

      Hi Vikas,

      Thanks, you are right. The host variable lt_salesorder in the OPEN SQL statement must be escaped using @. The usage of this escape character is not related to the @ in CDS annotations. This has to do with the new OPEN SQL syntax in SAP NetWeaver 7.4 SP5. In order to select from CDS entities in OPEN SQL, the new syntax must be used. This also includes separating the fields in the select list using a comma.

      See Horst’s blog (OPEN SQL, New Syntax) and the ABAP keyword documentation for more details.

      I have updated the blog with this information.

      Regards

      Chris

      (0) 
  3. Trond Stroemme

    Hi Chris,

    I was initially confused by the acronym CDS – Core Data Services – and it’s similarity to CDS – Content Delivery Services, which allows for extensive data modelling in HANA. As far as I remember, the Content Delivery Services are also stored as “DDL” sources – or at least something similar (file suffix .hddbd). SAP is not making it easy for us 🙂

    Regards,

    Trond

    (0) 
    1. Thomas Jung

      From the HANA Native Development side we don’t have a development object with the file suffix hddbd.  We do have hdbdd, but that is the same CDS – Core Data Services.  Its the same syntax used in ABAP DDL sources.  We use CDS in HANA Native to define tables, structures, associations, and views. It is also the core language within the data definition of the River syntax.

      Myself and several others in the HANA development group have never head of Content Delivery Services nor had we heard of hddbd. There is not artifact with that extension documented in the HANA Development guide nor does it open any specific editor in HANA Studio.  Are you sure that perhaps you weren’t thinking of hdbdd?

      (0) 
      1. Trond Stroemme

        Hi Thomas,

        you’re perfectly right. Got the acronyms mixed up (guess I was subconsciously thinking of CDN as in internet content delivery services… another topic altogether).

        Interesting that you make the link with RDL – I’ve been wondering about the similarities between CDS and RDL and how these fit together.

        Regards,

        Trond

        (0) 
  4. Uwe Fetzer

    Hi Christiaan,

    if I’m using the substring element on MaxDB, I’m getting an error while generating the DDL:

    ddl.PNG

    Pressing “generate” a second time, I’m getting this:

    ddl2.PNG

    If I’m commenting out this line, all is ok.

    Any idea?

    Uwe

    (0) 
    1. Jasmin Gruschke

      Hi Uwe,
      can you have a look at the activation log? Click in the DDLS editor window and find the activation log in Navigate > Open Activation Log.

      Cheers,

        Jasmin

      (0) 
      1. Uwe Fetzer

        No errors found in the log.

        The log ends with:

        Number of objects to be analyzed: 3

        Number of relevant dependencies: 2

        Level 1:1 objects assigned, 2 less dependencies

        Level 2:2 objects assigned, 0 less dependencies

        Graph_Analysis: 3 objects on 2 topological levels

        *************************************************************************

              Calculation of Dependencies:
        End phase  001 ***********************************************************

        Start phase 002 **********************************************************

              Object Activationnull*************************************************************************

        *** Activate objects at level 1

        * Synchronous execution, no parallel processing *

        (0) 
          1. Uwe Fetzer

            Hi Christiaan,

            we, or better Burkhard Diesing , found the reason for the error: the first number isn’t the offset (like in HANA?) but the starting position -> with substring( bpa.company_name, 1, 10 ) it works.

            See ABAP documentation:

            Substring of arg from the position pos in the length len. pos and len must be positive number literals.

            But in my opinion:

            • MaxDB should behave the same like HANA
            • the syntax-check must fail

            Cheers

            Uwe

            (0) 
            1. Burkhard Diesing

              Hello Uwe,

              the behaivior is the same but HANA doesn’t throw an error and set the
              startposition to 1 if 0 is given.

              But you are right the syntax check should be fail or MaxDB accept the 0 too.

              I will discuss this internally what needs to change to follow expectations.

              Burkhard

              (0) 
              1. Christiaan Edward Swanepoel Post author

                Hi Uwe and Burkhard,

                Since SP8, the syntax check now fails if the offset isn’t a positive integer value.

                I have updated the screenshot in the blog to now use substring(bpa.company_name, 1, 10).

                Cheers

                Chris

                (0) 
    1. Christiaan Edward Swanepoel Post author

      Hi Shai,

      CDS is the “core” of SAP River. CDS enables the data modeling part of SAP River as well as the role based access control. In addition SAP River provides its own programming language to implement the business logic (actions) on top of the data model. See Introducing SAP River for more information.

      To sum it up: You can use “pure” CDS to define your data models (as described in this blog) or you can use CDS in the context of  SAP River.

      Regards

      Chris

      (0) 
    1. Christiaan Edward Swanepoel Post author

      Hi Saurabh,

      Yes! Views on views are possible in CDS. In fact, this design pattern is heavily used to enable many of our SAP products which use CDS. A good example for this use-case is when you have to define a specialized “consumption view” for providing data to the UI. These consumption views are very often based on other CDS views.

      Regards

      Chris

      (0) 
      1. Saurabh Chaturvedi

        Hi Chris,

        Some more questions:-

        1) Are selects from multiple tables allowed for CDS view definition, for example something like SELECT table1.column1, table2.column2 FROM table1, table2 WHERE table1.column1 = table2.column1;

        2) Are nested joins allowed for CDS view definition; for example something like

        select from ((A join B on..) as C join (D join E on..) as F on..)

        As of now I am getting a syntax error for both 1 and 2.

        Thanks & Regards,

        Saurabh

        (0) 
        1. Christiaan Edward Swanepoel Post author

          Hi Saurabh,

          In both cases this is possible.

          1) You can model this in CDS using simple INNER JOINs. The condition in the WHERE clause can used for the join condition (ON clause). See the F1-Help for details.

          2) You have to be careful how you use the brackets when doing nested joins. In your example “as C” must be contained within the brackets, e.g.: (A as X  inner join B as Y on X.f = Y.f ) inner join ( D as Z join E on Z.f = E.f  ) on X.f = Z.f

          Kind regards

          Chris

          (0) 
          1. Saurabh Chaturvedi

            Hi Chris,

            I have to do multiple nested inner joins so I need to have aliases for the intermediate joins because some of the field names are same across tables used in the joins and also in the resultant intermediate joins. So my question is that in your example can I do something like this:-

            ((A as X  inner join B as Y on X.f = Y.f ) as AB) inner join (( D as Z join E on Z.f = E.f) as DE )

            on AB.f = DE.f

            Thanks for all the help you have already provided and in advance for thsi one 🙂

            Regards,

            Saurabh

            (0) 
            1. Andreas Gruenhagen

              Hi Saurabh,

              you cannot specifiy alias names for joins, neither in CDS nor in any SQL dialect I know.

              But since you can use the alias names of tables in the on-condition, this is not necessary:

              (A as X  inner join B as Y on X.f = Y.f ) inner join (D as Z join E on Z.f = E.f )

              on X.f = Z.f

              regards

              Andreas

              (0) 
              1. Saurabh Chaturvedi

                Hi Andreas,

                Thanks for the reply. I used aliases for joins in HANA SQL script. Basically I am trying to port a HANA SQL script based AMDP to a CDS view.

                Here is the working code that I used:-

                    METHODS hana_ld
                      IMPORTING
                        VALUE(mandt)     TYPE sy-mandt
                        VALUE(it_geo_fr) TYPE t_loc
                        VALUE(it_geo_to) TYPE t_loc
                        VALUE(it_mtr)    TYPE t_mtr
                      EXPORTING
                        VALUE(et_l2l)    TYPE t_lane…

                CLASS zsc_hana_ld IMPLEMENTATION.

                METHOD hana_ld BY DATABASE PROCEDURE
                                     FOR HDB LANGUAGE SQLSCRIPT
                                     OPTIONS READ-ONLY
                                     USING /scmb/toentity /sapapo/trm /scmtms/d_shzon.

                    et_l2l = select ‘1’ as “REQUEST_ID”, e.”GEO_FR”, f.”GEO_TO”, e.”TTYPE” as “MTR”, e.”TRMID_FR” as “TRMID”, 0 as “DIST_DET_RELEVANT”
                             from
                             (select a.”SCUGUID” as “GEO_FR”, b.”TRMID” as “TRMID_FR”, b.”TTYPE”
                             from “/SCMB/TOENTITY” as a
                             join
                             “/SAPAPO/TRM” as b
                             on a.”SCUGUID22″ = b.”LOCFR”
                             where a.”SCUGUID” in (select “SCUGUID” from :it_geo_fr)
                             and a.”MANDT” = :mandt
                             and b.”MANDT” = :mandt
                             and b.”TTYPE” in (select “MTR” as “TTYPE” from :it_mtr) ) as e
                             join
                             (select c.”SCUGUID” as “GEO_TO”, d.”TRMID” as “TRMID_TO”
                             from “/SCMB/TOENTITY” as c
                             join
                             “/SAPAPO/TRM” as d
                             on c.”SCUGUID22″ = d.”LOCTO”
                             where c.”SCUGUID” in (select “SCUGUID” from :it_geo_to)
                             and c.”MANDT” = :mandt
                             and d.”MANDT” = :mandt
                             and d.”TTYPE” in (select “MTR” as “TTYPE” from :it_mtr)) as f
                             on e.”TRMID_FR” = f.”TRMID_TO”;

                The aliasing of joins is needed because the output of such a join is needed in other joins and the field names are repeated across tables and joins within this join and outside of it.

                Any further pointers would be highly appreciated.

                Thanks & Regards,

                Saurabh

                (0) 
                1. Andreas Gruenhagen

                  Hi Saurabh,

                  In your example, you are using sub selects in the from-clause. This is something we do not support in CDS, yet. In CDS you probably have to implement this using a view on view construct.

                  By the way, in your example you do not specify an alias name for a join but for a whole sub select inside the from clause. In this case the aliasing does make sense.

                  regards

                  Andreas

                  (0) 
                  1. Saurabh Chaturvedi

                    Hi Andreas,

                    Thanks a lot for the quick reply. So with the current CDS capabilities I will have to use the view on view construct. I will try this out.

                    Also sorry for using the wrong terminology (joins vs. sub select)!!

                    Regards,

                    Saurabh

                    (0) 
                  2. Anni Pang

                    hi Andreas,

                    Will the nested select be supported in future? besides, does abap cds support while loop?

                    thanks,

                    Anni

                    (0) 
                    1. Andreas Gruenhagen

                      Hi Anni,

                      subselects are certainly on the backlog for the CDS Scrum team, unfortunately we have a long backlog.

                      Regarding Loops, since CDS like SQL is a purely declarative language I do not think we will have any procedural elements like loops in the near future.

                      If you need a loop, use SQL Script.

                      regards

                      Andreas

                      (0) 
                      1. Paul Hardy

                        Hello!

                        I just need to be sure about this – you just said in no uncertain terms that loops are possible in SQL Script.

                        Can you just confirm that once again? I had it in my head that this was not the case, maybe it was not once, but maybe now this has been added.

                        So just to be clear – when you say “if you need a loop, use SQL Script” that means SQL script supports loops?

                        An example of the syntax would be wonderful, I bet it is not like ABAP, probably more like a so called “cursor” moving through a group of database records.

                        Cheersy Cheers

                        Paul

                        (0) 
                        1. Andreas Gruenhagen

                          Hi Paul,

                          yes I can confirm loops in SQLScript, just look at the SQLScript reference here in the SCN. In the subsection Imperative SQLScript Logic-> Orchestration-Logic it says: Orchestration logic is used to implement data flow and control flow logic using imperative language constructs such as loops and conditionals.

                          regards

                          Andreas

                          (0) 
  5. Trond Stroemme

    I note the comparison CDS – RDL and the comment that CDS is a core part of River. This also seemed evident from the launch of the two products. In spite of this, there are some annoying differences in syntax between the two languages (CDS and RDL), such as the following:

    – in RDL, fields within entities have to be defined using the key word “element”; this is not needed (nor possible) in CDS

    – after the ending curly bracket for defining an entity in CDS, you need a semi-colon; this is not the case in RDL

    – no imperative logic in CDS

    Copy/pasting an RDL model into a CDS file (or vice versa) is, in other words, not possible. It looks almost like SAP created CDS and RDL in parallel, or maybe defined CDS based on a previous (and non-released) version of RDL? At the very best, these two “almost-identical” syntaxes are confusing, and gives the impression of a certain lack of coordination between various departments or development groups. Even worse, I imagine it will be more and more difficult to iron these bumps out as RDL and CDS takes hold.

    That is, if SAP doesn’t decide to scrap one in favour of the other – if so, which one?

    Regards,

    Trond

    PS: come to think of it, RDL is not released yet. Would it be possible to request someone at SAP to look into “syncing” the syntax properly?

    (0) 
    1. Steffen Weinstock

      Hi Trond,

      in short and simplified: RDL = CDS + actions.

      CDS is intended for defining data models, RDL adds imperative logic.

      When restricted to pure model definition, CDS and RDL syntax should indeed be (almost) identical.

      You are right with the assumption that different teams are working on CDS and RDL in parallel, but both are based on the same specification. Nevertheless it happens that there are (hopefully minor) misalignments concerning the syntax. They should be gone in the end.

      Best regards,

      Steffen

      (0) 
    1. Andreas Gruenhagen

      Hi Joseph,

      HANA calc views without parameters can be accessed in the ABAP / DDIC by creating an external View in the ADT (ABAP Development Tool). This view than can consumed in CDS View just like any other view or table declared in the DDIC.

      Best regards

      Andreas

      (0) 
  6. Martin Hofmann

    Hello Christian,

    is it possible to use build in varibles in the where condition of an CDS view  ? In Detail i want to use the actual Date (sy-datum) as an condition Parameter. If i could use this Parameter directly, without an inputparameter for the view, i could use the view directly in a SADL Query for displaying the results in a FPM Application.

    best regards

    (0) 
    1. Jens Boeckenhauer

      Hello Martin,

      view parameters can only be set by sub-classing the standard feeder class. In a subclass of CL_FPM_SADL_SEARCH_RESULT you can redefine method PREPARE_PBO with code like this:

      *******************************************************************************************

      *—– inherit
          super->prepare_pbo( io_event ).

      *—– test setting view parameters
          CHECK io_event->mv_event_id = ….<some condition if not desired each time>
          set_view_parameters( VALUE #( ( name = ‘HUGO’ value = ‘HALLO’ ) ) ).

      *******************************************************************************************

      An example is given in class CL_FPM_TEST_SADL_SRES_CUSTOM which is used in Test App FPM_TEST_SADL_SBOOK_CUSTOM (here only on DDIC, nit CDS, but the code is the same).

      Best regards

      Jens

      (0) 
    1. Christiaan Edward Swanepoel Post author

      Hi Amiya,

      this is currently not possible for ABAP developers but it is in the pipeline. Since most of SAP’s software solutions already have/had their persistencies, the main focus has been on view building to enable code pushdown. Although there are plans to support defining database tables using CDS (with a similar integration in DDIC), I cannot give you a timeline.

      The CDS implementation on SAP HANA, however, already offers this possibility. If you are doing HANA native development, you SHOULD already be using CDS to create your database tables (entities) instead of HDBTable. But any database tables defined directly in the  HDB are not integrated into ABAP DDIC and the ABAP language.

      Cheers

      Chris

      (0) 
        1. Christiaan Edward Swanepoel Post author

          These views are  read-only. The CDS specification allows for updateable views, but they are not yet implemented. Currently there are investigations on how to used SADL and BOPF to enable “write” scenarios, including transactional handling (disclaimer here!), but again this is something for the furture.

          (0) 
  7. Eric Farrar

    Hi Chris,

    You mention that “Annotations can be used to add metadata to CDS entities. Annotations specify the properties and semantics of the entity and its behaviour when it is accessed at runtime. This metadata can also be accessed by consumption tools using special APIs.”

    What are these APIs?

    Thanks.

    (0) 
    1. Eric Farrar

      I should clarify. Do you know if there is a way to access the annotation metadata outside of ABAP (i.e. directly through some HANA interface like XSJS)?

      Thanks.

      (0) 
    2. Christiaan Edward Swanepoel Post author

      Hi Eric,

      here again we have to differentiate between the CDS implementation in ABAP (with DDIC support and running in the ABAP Application Server) and the implementation in HDB (with its own repository and independent of ABAP/DDIC).

      You are referring to the possibility to define your own annotations in HANA CDS to annotate your entities which you defined in HANA (.hdbdd files). This is possible since HANA SPS9. Currently these annotations (the metadata) can only be accessed by SAP consumption tools. In other words, to date only internal APIs exist. There are plans to deliver public APIs with SPS10 (disclaimer here!). Then “external” consumers (in the context of HANA development) will also be able to access this information, e.g. via XSJS. It is important to note that these entities and their metadata are managed by the HANA DBMS, independent of the ABAP DDIC and ABAP runtime. This information is not found in the database tables mentioned by Uwe (since DDIC is not involved here).

      In ABAP the situation is somewhat different. In ABAP CDS entities are defined and managed in/by the ABAP Repository, independent of the HANA catalog. In fact, ABAP CDS is “open”. You can use these CDS features regardless of the underlying database. Currently you cannot define your own annotations in ABAP CDS (like in HANA CDS), but you can simply write the annotation in the DDL source. During activation these annotations are not validated (like in HANA) but simply stored in the ABAP Repository as metadata (in the database tables mentioned by Uwe). Here again there are currently also no official ABAP APIs to access this data. In the future official APIs will be delivered.

      To sum it up. Depending on where you define your CDS entities (ABAP or HANA), the metadata is stored in different repositories. Currently there are no official APIs for these repositories (neither in ABAP nor HANA). But they are on their way …

      Regards

      Chris

      (0) 
  8. Paul Hardy

    Coming bcak to the @semantics again, in your example you link the currency field to the amont field, just like in ABAP DDIC tables where amount fields must point to a curency field like WAERS, and quantity fields must point to a unit of measure field like MEINS.

    Since this is enforced in the ABAP DDIC the underlyin tables already have this information inside SAP – therefore is this semantic information intended for non-SAP based consumers e.g. EXCEL or a third party software system?

    Is this like in the SEGW gateway transaction where I can add semantic information to say a field is a geo-co-ordinate so when something like Google Maps can access the data model it knows for sure what the co-ordinate fields are?

    I may have this all wrong, but to keep ploughing ahead does this extra semantic information have any purpose within the ABAP environment?

    Cheersy Cheers

    Paul

    (0) 
  9. Anita Dixit

    Hi experts,

    I created a simple CDS view with one input parameter and use it for 2 places in the “where” condition, But I am getting the errors as shown :

    ABAPCDs_2datesparameter.PNG

    can anyone please help here?

    Thanks

    (0) 
  10. Anita Dixit

    Hi,

    I tried using “having ” in one of ABAP CDS views but it is not working.

    Here, I need to retrieve top 5 employee with max total revenue, how to do that?

    Can anyone help here please ?

    ************************************

    define view Zsoemp as select from snwd_so as so1

    association [1] to snwd_employees as emp

       on so1.created_by = emp.node_key

    {

        

         key emp.employee_id as emp_id,

        key so1.so_id as so_id,

        emp.node_key,

        emp.first_name,

      @Semantics.currencyCode: true

        emp.currency,

       @DefaultAggregation: #SUM 

       sum(so1.gross_amount) as Total_Revenue,

       @DefaultAggregation: #SUM

       sum(so1.net_amount) as Total_Net,

       @DefaultAggregation: #SUM

       sum(so1.tax_amount) as Total_Tax

    }group by emp.employee_id,so1.so_id,emp.node_key,emp.first_name,emp.currency

    having count(distinct emp.employee_id) = 5

    **************************************

    thanks

    (0) 
    1. Anita Dixit

      I am working on BW on HANA . SAP_BW – Release 750

      and using Eclipse IDE for Java Developers

      Version: Kepler Service Release 2

      Build id: 20140224-0627

      Thanks

      (0) 
        1. Anita Dixit

          There is such no error, I need to know how to select the top 5 (which has the highest number of sales).

          We can’t put “select top 5 …” in ABAP CDS views, so what is the alternative one?

          Regards,

          Anita

          (0) 
          1. Andreas Gruenhagen

            Hi Anita,

            currently the ABAP CDS does not support an ORDER BY clause yet. Since a “select top 5 …” only make sense with a defined order, this feature is postponed as well.

            As soon as the ORDER BY is available, the LIMITS-clause will probably be supported as well.

            What is the alternative ? For the ordering you have to rely on the query language on top of CDS, say, ABAP Open SQL.

            best regards

            Andreas

            (0) 
  11. Shailesh Velaparambil

    Hi Christiaan,

    Great blog! Thanks for keeping it updated. I am currently creating CDS views for client handling (MANDT). You have mentioned in the blog : “Currently you can only define one CDS entity per DDL source.”

    Does this still hold true ? I tried to create multiple views in one DDL source but failed. Wondering if some new syntax has come in to achieve this?

    (0) 
  12. Zaza Wang

    Hi Christiaan,

    Thanks for this fabulous survey of cds-view .

    I found that there were many annotations can be used in DDL building , but i wonder if there is a list of all annotations ? Cause currently I don`t have any idea about the relationship between annotations and the view definition(define view as select……).

    Regards,

    Zaza

    (0) 
  13. Sunil Sankar

    Hi All,

    I have built an CDS view with 3 tables – T1, T2, T3. T1 and T2 have 1-1 mapping while T3 has multiple entries. I tried all options to get last(one) row from T3 but couldn’t able to achieve it. Getting multiple rows from the query.

    Is there any possible way to exclude duplicates from table 3?

    Appreciate if you help me on this.

    (0) 
  14. Naresh Setty

    Hi Christiaan,

    Is this the future direction to build all views in ABAP itself and not use Hana Calculation views? Can you pl. provide some more insigts if SAP continue to suggest do calc views and cds views?

    (0) 
  15. Zaza Wang

    Hi all ,

    Anybody know how to hide this navback button thought annotations ?

    I cannot find any annotation working on it .

    Ca11111.PNG

    Thanks&BestRegards

    (0) 

Leave a Reply