CDS

CDS View: Association or Join Similarities

Check out this blog for a brief introduction to Association. This is the second blog in the series.

If you mention a field while using association, it becomes a complete join. The fields are immediately available. For example:

@AbapCatalog.sqlViewName: 'Z001ASSOC'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Association Test1'

define view Z001_ASSOCIATION
as select from nsdm_v_mard as mard

association [1..1] to mara as _mara
  on $projection.Material = _mara.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.mtart

 }

Result: In eclipse

Also, if you check the children, you will not find any.

If you look at the Created SQL statement in the Eclipse, it clearly shows join.

CREATE VIEW "Z001ASSOC" AS SELECT 
  "MARD"."MANDT" AS "MANDT", 
  "MARD"."MATNR" AS "MATERIAL", 
  "MARD"."WERKS" AS "PLANT", 
  "MARD"."LGORT" AS "STORLOC", 
  "MARD"."LABST" AS "OPENQTY", 
  "MARD"."INSME" AS "QUALQTY", 
  "MARD"."SPEME" AS "BLOCKEDQTY", 
  "MARD"."LGPBE" AS "DEFAULTBIN", 
  "=A0"."MTART" 
FROM "NSDM_V_MARD" "MARD" LEFT OUTER MANY TO ONE JOIN "MARA" "=A0" ON ( 
  "MARD"."MANDT" = "=A0"."MANDT" AND 
  "MARD"."MATNR" = "=A0"."MATNR" 
)

If you want to consume the fields from the associations, in any program or another CDS view, you need to mention the fields explicitly. Just like “material type” was added here.

This brings us back to full circle and the overlap I was talking about. In this example, you can use both Join or Association. So, which one you will choose. The answer is you can use either. But, my personal philosophy is to follow what SAP does. And SAP uses Associations more often and this is what I do more often.

Hope your question is answered but please read on.

There is a small difference between Join and Association. Knowing the difference will help you understand better when you use Join and when to use Association. More on this in the next blog. Follow us on our LinkedIn page for updates.

Leave a Reply

Your email address will not be published. Required fields are marked *

error

Enjoy this blog? Please spread the word :)

Follow by Email
Twitter
LinkedIn
LinkedIn
Share