Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
ThomasSchneider
Product and Topic Expert
Product and Topic Expert

Today, I would like to add an epilog to my “programming model” article series on the SAP HANA SPS9 update (start: A Programming Model for Business Applications (1): Assumptions, Building Blocks, and Example App). In my article, A Programming Model for Business Applications (2): Implementing the Entity Model with CDS I listed a couple of CDS restrictions that blocked me from writing down my data model in a compact format. Some of these limitations have been removed, in particular:

  1. It is now possible use CDS entities and views from other files.
  2. CDS supports “unmanaged associations” (= ability to define an association on existing elements using “on”)
  3. CDS supports “ad-hoc associations” in views
  4. CDS supports “anonymous structures” in entities

Let me now give some examples on how to use these features in the context of my example application.

1. Referencing CDS entities and views from other files

I think this is quite obvious. Here is an example:

namespace XYZ;

using XYZ::common as common; // SP9_NEW

using XYZ::address as address;

using XYZ::businesspartner as businesspartner;

@Schema: ' XYZ '

context salesorder {

<…>

}

Note: The “using” statement works like an import, in my example for the named contexts.

2.“Unmanaged Associations”

Unmanaged associations are useful to define the relation between parent and child in a business object.

Example:

entity SalesOrder {

    key ID_    : Integer64;

  Item       : association [0..*] to salesorder.Item  on Item.Parent_ID_ = ID_; // SP9_NEW

   <…>

  };

entity Item {

  key ID_     : Integer64;

Parent_ID_  : Integer64;

Parent      : association [1] to SalesOrder on Parent.ID_ = Parent_ID_; // SP9_NEW

   <…>

  };

I also use them to define time-dependent associations, for example the time-dependent elements (for example name, etc.) of a business partner:

  CurrentCommon   : association [0..1] to businesspartner.Common   on CurrentCommon.Parent_ID_= ID_

                                      and CurrentCommon.ValidityPeriod.StartDate< now() and CurrentCommon.ValidityPeriod.EndDate> now();

3. “Ad-hoc Associations” in Views

With ad-hoc associations in views I can use calculated elements from other views, for example here:

First, I calculate the net amount of an item in  a sales order as:

  view "Item$C" as select from Item {

    ID_,

    Parent_ID_,

    <...>

      (ListPriceAmount* Quantity) * (100 - DiscountPercent) / 100 as "NetAmountValue",

    <...>

  }; 

Second, I calculate the total net amount of the sales order as:

   view "SalesOrder$C" as select from SalesOrder

        mixin { // SP9_NEW

        _Item : association to "Item$C" on _Item.Parent_ID_ = ID_;

      } into

      {

     ID_,

         <...>  

         sum(_Item.NetAmountValue)  as "NetAmountValue",

    <...>  

       }

      group by ID_, <...> ;

4. Anonymous Structures

This is a “nice to have” feature, it helps me to get rid of the “type” definitions for data structures that are only used once, for example here:

  entity SalesOrder {

                <…>

    Status {

     LifeCycleStatus             : association [0..1] to salesorder.LifeCycleStatus;

     InvoiceProcessingStatus     : association [0..1] to salesorder.InvoiceProcessingStatus;

     CreditWorthinessStatus      : association [0..1] to common.CreditWorthinessStatus;

         };

As a summary: I can now get rid of my hdbview-Files that I needed in SPS8 because of the CDS limitations. This makes the data model much more readable.

If you want to get an overview on new SPS 09 developer features, you can read the following article: SAP HANA SPS 09: New Developer Features

6 Comments