CDS View Association – Part-1

light111CDS View  with Association [1..1] and use of path expression 


This post shows how to create a association between two data sources and its cardinality and how to expose the association data source and consuming the CDS view from ABAP program requesting fields of the main data source/association data source.

An association  in a CDS view associates source data source with a target data source. The cardinality [min . . max]  defines the cardinality of the target data source. 

min – can be omitted then assumed as 0 , min can not be * .

max- cannot be 0, max can be * means any no of rows.

When SQL SELECT  query is performed on a CDS view  that uses a path expression to access an association or simply the path expression  is used, then the association is transformed into a join expression. 


Let’s create a CDS view with association with source data source as – SPFLI and target data source as – SCARR and these source & target source have cardinality as [1. . 1].

The select attributes include 4 fields from the source data source and also 1 fields from the association i.e carrname. Save and activate the cds view.

1

In SE11 , the corresponding SQL view also includes the CARRNAME from association table-SCARR.

2

And the SQL view contains a join condition like CDS view with JOIN. This is because though it is a CDS view with association but one of the element CARRNAME is included in the selection list.3

Here we have the graphical editor.

4

The underlying SPFLI table records.

6

Make Data preview. 

5

As there is no association is exposed, we don’t find any list of associations.

7

Here we can have a select query on the CDS view with association.

89


Let’s make the association field CARRNAME not a part of the selection list. 

10

The SQL view.

11

There is no join and the selection list don’t include any field of the association.

12

Data preview.

13


Let’s make thing little more good, now in the CDS view let’s expose the entire association but don’t include any association field in the select list. 

14

No join condition in the SQl view if only the association is exposed but no field is of the association is included in the selection list.

1516

Graphical editor view.

17

Make data preview. Here no join condition is evaluated.

18

Now as we have exposed the association [ _SCARR] , select any record and we can navigate to the association.

19

Now the ON condition is evaluated and we can see the details of the association data source.

20

This is how the SQL query is made on the CDS view to request the details of the association data source. It uses the path expression [ \ ] backslash and [ – ] operator.

21


Now make a select query on the CDS view and we get all the source fields of the view. No association field requested , so no join condition evalauted.

2223

As the complete association is exposed, we can make request for specific fields as shown below. This time the ON condition is evaluated.  The result contains 5 fields, 4 from the source and 1 from the association.

2425


Here we can request for multiple association fields and also in WHERE condition the path expression can be maintained for the association fields.

262728


We can also request only the fields of the association data source  with different values in WHERE condition.

293031

Last but not least also DISTINCT gives now duplicate records. 

3233


 

6 comments

  1. When i use association fields in my ABAP select query e.g. \_mbew-strpr, I get an error message during activation saying that “Association “_MBEW” cannot be used here, since a replacement object was defined for its target table MBEW”

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s