How to Extend ABAP CDS View Entity (Core Data Services)
In this blog post we are going to see how we can Extend CDS View Entity, for demo purpose a custom View Entity is created (SAP Standard View Entity is not used):
Extension to ABAP CDS View Entity is needed when there are some changes needed which are part of custom requirements… In this case we make changes to standard Entity View by adding new fields or etc…
- DDIC View can be extended using EXTEND VIEW option.
- New CDS View Entity can be extended using EXTEND VIEW ENTITY option.
So we can say that statement EXTEND VIEW ENTITY is a replacement of EXTEND VIEW
Some of the benefit and limitations of using new extension with CDS Entity View:
1.A view entity extension does not have a DDIC append view (Since there is no SQL View generated)
2.CDS view extends with EXTEND VIEW require at least one field to be extended
3.CDS view entity extensions also work without any new field. You can, define only a new association.
4.In view entity extensions, no header annotations are allowed.
5.An existing CDS view can have one or more CDS view entity extensions. A CDS entity extension cannot be further extended.
6.Both kind of View Extension EXTEND VIEW and EXTEND VIEW ENTITY can be used to extend Entity View or DDIC based Views. But this is not suggested by SAP. It has been kept just for Migration and Compatibility purposes.
7.New Field and Associations can be added while Extending Entity View
8.New Input Parameters cannot be added while Extending Entity View.
Creating Entity View and Extending
For demo purpose we will be creating new custom Entity View and then we will be extending it as we do a standard Entity View.
Below functionalities are covered:
1- Extend Core Data Services (CDS) View Entity with new Association
2- Extend Core Data Services (CDS) View Entity with new Fields
Create new Entity View. We are using SPFLI table.
Lets see the output
First change annotation value. This is needed because we will be extending this CDS Entity View which is using Select statement to display data… we are going to extend this Projection List.
Now add one Association to SCARR table to new created Entity View.
New to extend Entity View. we need to follow same path we used to create CDS Entity View.
This time we are going to select EXTEND VIEW ENTITY option from listing because we are extending new CDS Entity View.
If you are extending DDIC based CDS views then we need to select EXTEND VIEW option.
For this demo we will be adding an Association to existing Entity View using Extension.
New extend entity View
Currently there is not Association available in Entity View.
The Entity View Z_ENTITY_VIEW after extension looks like below, where we have added new association.
Now when execute the original Entity View and check the Association, we will be seeing new association which we have added in Extension Entity View.
When we click on new association we get the data as below
Now we are going to see how we can extend Fields
Now once new fields are added, lets run the original Entity View again.
We are now getting two new fields added CURRCODE and URL.
So this is how we can Extend CDS Entity View.