CDS Views: ASOCIATIONS

Associations:

These are mostly created to use in UI5.

1.Keep only base table/CDS view fields in the selection list.
2.Keep association as public/expose association
3.AD-Hoc Association - Showing the Association field name in first CDS view

@AbapCatalog.sqlViewName: 'ZVB_ASSOCIATION'

@AbapCatalog.compiler.compareFilter: true

@AbapCatalog.preserveKey: true

@AccessControl.authorizationCheck: #NOT_REQUIRED

@EndUserText.label: 'Associations'

define view ZAB_ASSOCIATION as select from vbak as _sohead

association [1..*] to vbap as _soitem on _sohead.vbeln = _soitem.vbeln

//Association on association not recommanded 

//association [1..*] to vbrp as _billing on _soitem.vbeln = _billing.aubel

association [1..*] to vbrp as _billing on _sohead.vbeln = _billing.aubel

{

key _sohead.vbeln as Sales_order, //Selection list

_sohead.erdat as create_date,

//make assiciations as public

_soitem.posnr as so_item, //AD HOC

_billing

}


Calling Association in SE38:

  REPORT ZVB_ASSOCIATION. SELECT    ZAB_ASSOCIATION~SALES_ORDER,    ZAB_ASSOCIATION~CREATE_DATE,    ZAB_ASSOCIATION~SO_ITEM,    \_BILLING-MANDT AS MANDT ,    \_BILLING-VBELN AS VBELN  FROM   ZAB_ASSOCIATION  INTO TABLE @DATA(LT_RESULT)  UP TO 100 ROWS . 

 

4.Path expressions

5.Change the default outer join as inner join 

By default Associations will work as Left Outer Joins. We can change it to inner joins using [INNER].

 

@AbapCatalog.sqlViewName: 'ZAB_ASSOCI_1'

define view ZAB_ASSOCIATION1  as select from vbak as _vbak

association [1..1] to vbap as _vbap on _vbak.vbeln = _vbap.vbeln

{

_vbak.vbeln as vbeln,

_vbap[INNER].posnr as posnr, //Inner join

_vbap[posnr = '10'].matnr as matnr //Path Expressions

 

}

 
6.Cardinality   
 


@AbapCatalog.sqlViewName: 'ZAB_ASSOCI_1'

define view ZAB_ASSOCIATION1  as select from vbak as _vbak

association [1..1] to vbap as _vbap on _vbak.vbeln = _vbap.vbeln

{

_vbak.vbeln as vbeln,

_vbap.posnr as posnr,

_vbap.netpr as netpr

}


@AbapCatalog.sqlViewName: 'ZAB_ASSOCI_1'

define view ZAB_ASSOCIATION1 as select from vbak as _vbak

association [1..*]to vbap as _vbap on _vbak.vbeln = _vbap.vbeln

{

_vbak.vbeln as vbeln,

_vbap.posnr as posnr,

_vbap.netpr as netpr

}

 

There is no difference in the output of above 2 CDS Views if Cardinality is [1..1] 

or [1..*].

 

 

we can able to see the difference in Database  


 

Comments

Popular posts from this blog

CDS Views: Table Functions with Example

Passing Dynamic Variables to SO10 TEXT

Adobe Form/PDF Form Introduction