Hello,Welcome to my blog.In this post i will explain you about how to extend a CDS View.
CDS View Extensions:
- CDS View Extensions are defined in dedicated DDL Sources via DDL statement EXTEND VIEW.
- Every DDL Source with a CDS view extension defines two objects: The actual CDS view extension and an Append View. This corresponds to the two objects defined by a standard DDL. The CDS View and the SQL View.
Go to Eclipse or HANA Studio and click the below template
There is a dedicated template for creating the definition of a view extension. After creating the DDL Source, you have to specify the name of the CDS View you want to extend, the name of the new CDS entity (View extend), and the name of the SQL View append.
- In this example, CDS View S4d430_Extend_Target _A contains six elements in the element list. CDS View extension Z4d430_Extend_View_A adds fields airpfrom and airpto to this list.
- The link between the two DDL Sources is established through the CDS view name after key word EXTEND VIEW.
Note: The name of the SQL view cannot be specified here.
- literals, fields, expressions, functions
- Input parameters
- Path expressions
- Aggregates (as of 7.51, only if target already contains aggregates)
- View Extension can add associations
GROUP BY Clause (as of release 7.51)
- Only if target view contains a GROUP BY clause
- Mandatory for new elements that are not aggregates
UNION(ALL) Statements (as of release 7.51)
- Mandatory if target view contains UNION (ALL) statements
- Same number of UNION(ALL) Statements required
Like classical Append Views, CDS View Extends can add elements to the SELECT list. New is the fact that an extend view can also define additional associations. This can be used, for example, to define an association to a customer-specific database table or CDS View.
Note: A CDS View Extend may contain associations but no direct joins.
As of release 7.51, it is also possible to extend views that contain aggregations and/or UNIONS. But to do so, the target view has to actively allow this via annotation AbapCatalog.viewEnhancementCategory.
In the above example, CDS View S4d430_Extend_Target _B CDS View is extended with CDS View Extension Z4d430_Extend_View_B.
This view extension not only extends the field list. It also adds two associations to table sairport.
Note: Instead of using fields of the associated data sources directly, the view extensions could also have exposed the new associations.
- In the above example, CDS View S4d430_Extend_Target_C contains two SELECT statements linked with a UNION statement. Each SELECT statement has an aggregation expression in the element list and a corresponding GROUP BY clause.
- CDS View extension Z4d430_Extend_View_C reflects this structure. It contains the extensions for both SELECT statements, linked with key word UNION.
- In both SELECT statements, the extension adds fields city and country to the element list and expands the GROUP BY clause accordingly.
Note: Extensions with GROUP BY and UNION are only possible if explicitly allowed by the extended view via annotation @AbapCatalog.viewEnhancementCategory.
Recommendations and Restrictions for View Extensions
- (Customer) Namespace for repository objects (DDL Source and SQL Append View)
- Uncommon names for additional elements and associations (to avoid later conflicts)
CDS Views from Basis Packages
- Contact SAP before you extend CDS Views from Basis Packages.
No Renaming After Transport
- Name of CDS View Extend and SQL Append View can not be changed after first transport of DDL Source
No Additional Key Fields
- Prefix KEY is not allowed in CDS View Extends
When extending CDS Views, it is advisable to carefully choose the names of repository objects and additional entities to avoid conflicts in future upgrades.Placing the additional repository objects in an appropriate namespace is one of the recommendations. The other refers to the additional element list entries and associations. By using very common names, you increase the risk of conflicts with later additions in the standard.
Note: For append fields to transparent tables, the recommended namespace is ZZ . No such namespace exists for CDS View extends
- Like with CDS Views in general, it is advisable but not mandatory to use the same name for the DDL Source and the CDS entity.
- The most important restriction also refers to naming: After a DDL Source has been transported from the development system, the names of the SQL Append View and the CDS View Extend are fixed and cannot be changed any more.
Annotation AbapCatalog. viewEnhancementCategory
- Restricts the extensibility of a CDS View
- Comma-separated list of values in square brackets
- #GROUP BY
- #NONE cannot be combined with other values
- #GROUP BY and #UNION require #PROJECTION_LIST
As of Release 7.51, the extensibility of a CDS View may be restricted by annotation AbapCatalog.viewEnhancementCategory.
The annotation may be used with a comma-separated list of values in square brackets. The following values exist:
- No extensions are allowed. This Value cannot be combined with other values.
- Extensions of the SELECT list and additional associations are allowed; extensions of CDS views whose SELECT lists contain aggregate expressions or have a UNION clause must be permitted using further values.
- Aggregated or non-aggregated elements are allowed to be added to a SELECT list with aggregated expressions and the associated extensions of the GROUP-BY clause are also permitted.
- can only be specified together with #PROJECTION_LIST.
- Extensions of the SELECT list of a CDS view with a UNION clause are allowed. can only be specified together with #PROJECTION_LIST.
- If the annotation is used without square brackets or if the annotation is missing at all, the view’s extensibility is as if the annotation had been specified with value #PROJECTION_LIST.
Navigation from Extension Target to View Extension
- You can see it directly in the DDL Source if there are any extends for this particular CDS View.
- If one or more CDS View Extends point to this CDS View, a spiral-shaped symbol appears on the left of the DEFINE VIEW Statement. When you place the pointer over this symbol, a dialog box opens with a list of the existing extensions. Open the definition of the CDS View Extend by clicking on its name in the list.
Please write us here for any queries and concerns.