Skip to Content
avatar image
Former Member

Relationship in CDS Association

Hi,

Could you help me understand the relationship defined in association in CDS views is same as cardinality?

For Example, what does [0..1] and [1..1] mean? How is this different from cardniality in a join in HANA view?

association [0..1] to Z_I_Material as _Material on $projection.Material = _Material.Material association [1..1] to Z_I_Sales_Hdr as _SalesHeader on $projection.SalesDocument = _SalesHeader.SalesDocument

Thanks,

Remya

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Jun 23, 2017 at 11:26 AM

    Hi

    if you're consuming the association in a higher level view, then [0..1] and [1..1] for association will be interpreted as LEFT OUTER MANY TO ONE JOIN in the sql statement, then it would be similar to the HANA column view's LOJ to one.

    in HANA, such kind LOJ will be optimized in the runtime, e.g. if the fields is not selected, then the join will be by passed.

    you could get the sql statement for your CDS by right click your CDS content->show SQL create statement in AIE.

    you could also check a similar question and the comments in the bottom.

    https://answers.sap.com/questions/225779/cardinality-in-cds-assocation.html?childToView=234259#answer-234259

    Best Regards,

    Sean

    Add comment
    10|10000 characters needed characters exceeded

    • [0..1] here exactly means the target could have minimum 0 entry, and maximum 1 entry.

      actually, if you could always ensure that there will be and only be one entry, then [1..1] shall be used.

      however, you have to think about some rare case, e.g. is it possible that company code be blank in the C_NonManagedPurchasingSpend1? or would there be any data(in C_NonManagedPurchasingSpend1) which doesn't have an entry in the I_CompanyCode?

      if the answer is YES, then [0..1] would be better.


      if the answer if NO, then [1..1] shall be used, which will explain the model more clearly.

      this explains the I_SalesOrderItem, which have the following.

      association [1..1] to I_SalesOrder

      And, all in all, the association cardinality is mainly explaining the modeling, in run time, there is no difference between [1..1] and [0..1], because both of them are interpreted as LEFT out JOIN in SQL View.(at least, it's the case right now), so you don't have to very specific in this case, since it will not introduce any runtime difference.

      Yes, you could be more strict to do the modeling, since it will definitely introduce benefit to you in the future to understand the modeling.

      Hope my comments help you.

      Best Regards,

      Sean

  • May 29, 2017 at 12:33 PM
    -2

    You already answered your question for yourself: it is the cardinality.

    [0..1] there may be one or none entries

    [1..1] there's exactly one entry

    Add comment
    10|10000 characters needed characters exceeded

    • "Does the cardinality have any influence at all - thus providing the wrong cardinality gives different results."

      Yep, on HANA there are optimizations (from 7.50 on) that can influence results. Unfortunately, especially the documented default settings can produce unexpected results. Therefore, the cardinality should reflect the real data.