CDS

CDS View: Association or Join

I get asked this question a lot. It reminds me of my yesteryears when we used to mull over – Select Join or Select For All Entries OR Select single or Select Up to 1 rows. These questions were thrown a lot in the name of the Quality review. Trust me, I know. I was one of them – experienced it from both sides.

Coming back to the question – Association or Join which one is better. The answer is the same as it was then – it depends. Important thing is to understand how both work and then use them freely.

The Introduction

CDS has come with a lot of new features. Association is one of them. By now, you must have heard – Association is like a join but more (or on-demand join, ad-hoc join). Let’s check with an example, what that means –

@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

 }

 

Although we didn’t select any field from MARA, all fields are available in the result.

Try the result in Eclipse.

It will open something like this –

If you consider this an advantage. Go ahead start using association. SAP uses Association more often than Join. I think that is the as best answer you can get.

But I have more to share about the Association. More in the next blog.

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