CDS View: Association or Join Differences
Check out our previous blog for a brief intro on Association and its similarities with Join. Let’s see where these two differ.
For Association, it is necessary that you select the field which you are using to “associate” with the other entity. As we saw in the introduction blog, that we can navigate to children and linking is vital for that. A syntax error will come during activation of the CDS without selecting all the linking fields.
You can join two different tables or Views without selecting all the linked fields.
@AbapCatalog.sqlViewName: 'Z003ASSOC' @AbapCatalog.compiler.compareFilter: true @AccessControl.authorizationCheck: #CHECK @EndUserText.label: 'Association Test2' define view Z002_ASSOCIATION as select from nsdm_v_mard as mard inner join mara on mara.matnr = mard.matnr { // key mard.matnr as Material, key mard.werks as Plant, key mard.lgort as Storloc, mard.labst as OpenQty, mard.insme as QualQty, mard.speme as BlockedQty, mard.lgpbe as DefaultBin, mara.matnr // _mara.mtart }
Hopefully, now it will be easier to decide between Join or Association. To reiterate, both are just fine in most situations and SAP primarily used Association. A good rule of thumb is to always follow SAP.
If you like our content, please do follow us on our LinkedIn page.