In the context of RAP, we are using "define root view entity" for main projection CDS View as well as Main Interface CDS View, as that is the main entity of the business object.
For the remaining composition views, we are using "define view entity" without root keyword, as that is not the top most entity of the business object.. This much I have understood.
But In our company, we are using remaining all dependent cds views which are used for value helps, for getting texts...etc, using "define view" with out even entity....
I read few blogs and got basic differences between "define view entity" and "define view", as one got ddic view, for other no need.
But when exactly we need to use define view / define view entity ?
Can we use for all cds views.... define view entity , except root view ?
Kindly share your knowledge on this.
Thanks in advance.
Hi SAI VARMA,
CDS View Entity can be defined using both DEFINE VIEW and DEFINE VIEW ENTITY, here DEFINE VIEW ENTITY is the latest version of DEFINE VIEW. It provides a lot of improvement than DEFINE VIEW such as stricter check, no annotation for Client Handling, Only one name and artifact, and no longer time for activation of complex view hierarchies.
As for the questions:
1. When exactly we need to use define view / define view entity?
It all depends on the feature and functionality you want to use, DEFINE VIEW ENTITY being the latest one will provide a much greater set of addition and continue to improve and will continue to improve.
2. Can we use for all cds views.... define view entity , except root view ?
Yes, you can use DEFINE VIEW ENTITY for all CDS views, but you cannot create CDS View Entity with the same name as an existing CDS DDIC-based View at the same time. You may also get some issue while migrating you older view to the new one as DEFINE VIEW ENTITY is continuing to improve and may have some compatibility issue.
Please refer to this blog for more understanding - https://blogs.sap.com/2020/09/04/cds-view-entities-the-new-cds-views/