CDS - Extension of Views
This article is about the extension of views to include customer-specific fields or to provide missing information.
Table of contents
Article update: Since release 7.57 (S/4 HANA 2022), DEFINE VIEW is marked as obsolete, you should use DEFINE VIEW ENTITY instead. These may differ from the examples in some places. You can find more information about the new views in this article.
In this article, we look at extending Core Data Services and how we can make additional fields available to apps. In doing so, we will roughly describe the two extension methodologies that are currently used.
Preperation
In the first step we look at the extension of CDS Views and how we can add additional information. First of all, let's define a view that we want to extend. This is based on the Basic View for discounts:
@AbapCatalog.sqlViewName: 'ZBSCDMODISEXT'
@EndUserText.label: 'CDS Extension'
define view ZBS_C_DmoDiscountExtension
as select from ZBS_I_DmoDiscount
{
key PartnerNumber,
key MaterialNumber,
DiscountValue,
_Material.MaterialName,
_Material.MaterialDescription
}
As you can see, it's a simple view, we'll take over the keys and add some additional information to the texts for the material.
EXTEND VIEW
In the second step, we now want to expand the "ZBS_C_DmoDiscountExtension" view because we need additional information that is currently missing in the app that is above this view. Let's assume that since it's a standard view, we can't extend the view. For this we create a new Core Data Services, but with the pattern "Extend View" and we adopt the new field:
@AbapCatalog.sqlViewAppendName: 'ZBSEDMODISEXT'
@EndUserText.label: 'Extension for ZBS_C_DmoDiscountExtension'
extend view ZBS_C_DmoDiscountExtension with ZBS_E_DmoDiscountExtension
{
_Partner.PartnerName
}
The annotation "@AbapCatalog.sqlViewAppendName" differs from the previously created views. Here we define an extension of the Core Data Service and add the partner name. In the SE11 this would look like this:
The new field is created as an append and the view is thus cleanly expanded. In Eclipse you would now get a corresponding mark on the original view:
The corresponding entry also appears in the CDS Navigator of the view and refers to the extension:
If we now look at the "Data Preview" for the Core Data Service, the new field is automatically adopted and is available to us. The view has been extended accordingly without having to change the original view:
Hint: The extension also has its own naming convention with E for extension, so that the extension view can still be distinguished from the data model.
Association
The second extension option is to integrate an extension into the various entities of the data model via association, especially if the database table also requires the new field. In this extension scenario, additional data should be stored in the application, but at the same time the app should display the data in the UI.
In most cases, the extensions are installed and made available as "_Extension". As a separate view, it directly integrates the database table and is implemented in the corresponding views via association:
The fields can then be attached to the extension view again with an extend. These views usually have the corresponding annotation "@VDM.viewType: #EXTENSION". This expansion option is mainly used in the SAP standard when working with the key user apps.
Conclusion
The extension of CDS views is now also possible without modification and the resources remain cleanly separated in the system. If you need more content in a view, you should think about expanding before copying.