This is a test message to test the length of the message box.
Login
ABAP CDS Extension
Created by Software-Heroes

CDS - Extension of Views

1485

This article is about the extension of views to include customer-specific fields or to provide missing information.

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.


Included topics:
CDSCore Data ServiceExtensionExtend
Comments (0)



And further ...

Are you satisfied with the content of the article? We post new content in the ABAP area every Friday and irregularly in all other areas. Take a look at our tools and apps, we provide them free of charge.


ABAP Tools - Work with Eclipse (CDS Analysis)

Category - ABAP

In the complex world of CDS views, it is important to have the right tool at hand to ensure an analysis of the structures and data sources.

08/25/2023

CDS - View Entity

Category - ABAP

In this article you will learn more about the new Core Data Service entities, what they bring and what makes them different from the old views.

07/29/2022

CDS - Learnings

Category - ABAP

In this article we summarize the learned content and show you the way for what you will need the CDS Views in the future.

06/10/2022

CDS - Virtual fields

Category - ABAP

This article is about virtual fields in Core Data Services and how you can subsequently deliver such complex data.

06/03/2022

CDS - Authority check

Category - ABAP

How and where are the permissions for a Core Data Service delimited? Check out this article for the details.

05/20/2022