CDS View with Association and Path Expressions


Let’s  make ourselves familiar with some important keywords before we jump in to understand Association with examples:


Association is different than join in that sense that association defines how two entities are connected to each other. It is sometimes understood as “Conceptual Thinking” also because its nature of linking entities rather than joining them directly. The join may be the next step once the association is defined.


In database design, the cardinality or fundamental principle of one data aspect with respect to another is a critical feature. The relationship of one to the other must be precise and exact between each other in order to explain how each aspect links together.

In the relational model, tables can be related as any of “one-to-many”, “many-to-many” “one-to-zero-or-one”, etc.. This is said to be the cardinality of a given table in relation to another.

In terms of SAP:

  • A [1..1] B means that for every row of A, there is a unique row in B and vice versa
  • A[0..1] B or just A [1] B means that B may have a record for which there no source information in A.
  • A [0..*] B means that B may have many records for which there no source information in A.

Path Expressions

Path expressions identify an object by describing how to navigate to it to objects via steps/route. For example, the path expression Object.Employee.Address.ZipCode can refer to Zip Code of particular Employee’s address. Of course, this relationship should be established beforehand using association/cardinality to use this kind of Path to access particular information.

To understand Association better, let’s take help of some CDS views and an ABAP program to consume CDS.

Case 1:

In Case 1, we create 3 CDS views and a report for concept demonstration. We create first CDS view to link Business Partner with ADR6 table. In Second CDS we link first CDS and ADRC table. In Third CDS, we link first and second CDS so that it can be consumed by ABAP, oData service, and other CDS. In the last step of Case 1, we create an ABAP program and consume third CDS view.

All the code for Case 1 can be found on GitHub.


@AbapCatalog.sqlViewName: ‘Zadr6_view’

@AbapCatalog.compiler.compareFilter: true

@AccessControl.authorizationCheck: #CHECK

@EndUserText.label: ‘BP + ADR6’

define view Zadr6_stob

  as select from but020 as b20

  association [1..1] to adr6 as _adr6 on  b20.addrnumber   = _adr6.addrnumber

                                      and _adr6.flgdefault = ‘X’


      // Business partner

  key b20.partner                  as partner,

      // Address #

  key b20.addrnumber               as addrnumber,







  // Address should be valid on the current date!

      b20.addr_valid_from <= tstmp_current_utctimestamp()

  and b20.addr_valid_to   >= tstmp_current_utctimestamp()

Above CDS links Business Partner with the ADR6 table.


@AbapCatalog.sqlViewName: Zadrc_view

@AbapCatalog.compiler.compareFilter: true

@AccessControl.authorizationCheck: #CHECK

@EndUserText.label: ‘BP + ADR6 + ADRC’

define view Zadrc_stob

  as select from adrc

  association [1..1] to Zadr6_stob

  as _adrc on $projection.addrnumber = _adrc.addrnumber


      // Business partner

  key _adrc.partner                  as partner,

      // Address #

  key adrc.addrnumber                as addrnumber,

      // Name

      adrc.name1                     as name,




CDS links ZADR6_STOB with ADRC.


@AbapCatalog.sqlViewName: zget_full_addr

@AbapCatalog.compiler.compareFilter: true

@AccessControl.authorizationCheck: #CHECK

@EndUserText.label: ‘Full Address’

define view zget_full_address

as select from Zadrc_stob as _address


// See how information is being fetched using Path expression

// Root Path : _address > fields




// Path : _address > _adrc > Fields




// Path : address > _adrc > _adr6 > email



CDS links ZADRC_STOB with ZADR6_STOB and hence provide full address for a Business Partner. CDS can be readily consumed in an ABAP program as below:



*& Report ZCDS_TEST




REPORT zcds_test.



  INTO TABLE @DATA(lt_data)

WHERE partner = ‘0010100001’.

IF sysubrc IS INITIAL.

  cl_demo_output=>display( lt_data ).


This program passes a business partner to the CDS ZGET_FULL_ADDRESS and in return, CDS returns full address.


Case 2

In this case, we create a CDS to demonstrate how multiple tables can be linked using association and then information can be fetched using path expression.

All the code for Case 2 can be found on GitHub.


CDS is written to join Business Partner, ADR6, and ADRC tables. This is also an example of CDS view with Parameters. We are going to cover that in next section!

@AbapCatalog.sqlViewName: Ztest_cds_view

@AbapCatalog.compiler.compareFilter: true

@AccessControl.authorizationCheck: #CHECK

@EndUserText.label: ‘ZTEST_CDS’

define view Ztest_CDS_2

  with parameters

    i_partner :bu_partner

  as select from but020 as b20

           association to adr6 as a6 on
.addrnumber = a6.addrnumber

                      and a6.flgdefault = ‘X’

           association [1..1] to adrc as _address

                      on $projection.addrnumber = _address.addrnumber


// Business partner

key b20.partner as partner,

// Address #

key b20.addrnumber as addrnumber,

a6[1: left outer].smtp_addr as email, // Email ID

// Exposed association is used to future reusability

// Association is on demand join,

// so if no field of ADRC is selected, join will never execute!




    b20.partner = :i_partner


// Address should be valid on current date

      b20.addr_valid_from <= tstmp_current_utctimestamp()

  and b20.addr_valid_to >= tstmp_current_utctimestamp() )

CDS Output:


Program consumes CDS and since CDS is an exposed association, logic fetches exposed columns.






REPORT zcds_test.


DATA : i_bp TYPE bu_partner VALUE ‘0123456789’.


ztest_cds_2( i_partner = @i_bp )


” Path expression used to get Telephone #

    \_addresstel_number AS telephone” Telephone

    email AS email ” Email

    INTO TABLE @DATA(lt_address).

IF sysubrc IS INITIAL.

    cl_demo_output=>display( lt_address ).


Notice the way Path expression is used to access Telephone number!

Program output:


You may also like Performance Comparison:  New Open SQL vs CDS vs AMDP vs CTE(Common Table Expression)



5 thoughts on “CDS View with Association and Path Expressions

  1. Greetings I am so delighted I found your blog page, I really found you by
    error, while I was searching on Bing for something else, Nonetheless I
    am here now and would just like to say thanks for a incredible post and
    a all round enjoyable blog (I also love the theme/design), I don’t have
    time to go through it all at the moment but I have bookmarked it
    and also added in your RSS feeds, so when I have
    time I will be back to read a great deal more, Please do keep
    up the superb job.

  2. Hi everybody, here every person is sharing these experience,
    thus it’s pleasant to read this webpage, and I used to visit this web site
    all the time.

Leave a Reply