CDS View Annotations “Scope” and “Propagation”
Target Audience & Links
This blog is for those who has a basic level of understanding in ABAP Programming model for Fiori or the CDS View annotations. If not there are a lot blogs out there and most importantly the SAP help.
Note: This blog is based of my experience and shouldn't be considered as the standard.
Scope/Propagation of Annotations
If we are creating the CDS views with annotations, you might have observed that sometimes we will have to write the same annotations multiple times in the different CDS views(parent & child) and sometimes we will write them at only the child view(transactional or basic) and not at the consumption view (or vice versa).
The Object model annotations like “CreateEnabled”, “DraftEnabled” will be written at the Transactional View(BOPF) and the consumption view(OData) as well. It is because the scope of those annotation are restricted to the View level.
But the annotations like value help, label, foreign key, lineitem, selectionfield etc.., will only be maintained at only one CDS view and will be propagated to parent CDS views.
This is because every annotation will have a scope. So how will we know the scope of the annotations? Simple, just go to the help where it gives the scope description for the annotations.
Element annotations will be propagated from child to the parent. We usually maintain these annotations at the columns level
View/Association annotations are specific to the view and will not be propagated to the parent CDS view. These usually be maintained at the header level.
Or we can simple say that the annotations that are maintained at the elements level(columns) will be propagated and the annotations that are maintained at the header will not be propagated (correct me if I am wrong 🙂 )
It reduces a lot of rewriting head ache right? Now there will be an another scenario where we don’t need the annotations to be propagated and you might want to rewrite those annotations in case of reusing the CDS views. To do that we need to use the below annotation
If we use it in the parent CDS view, the annotations from the child view will not be propagated to the parent.
Note: BTW there are more than 2 scopes that I’ve discussed and please check in the below comments for more information.