Extending Apps with Custom Fields

As an SAP customer you may want - in some cases - to extend the user interfaces (UI) of the On-Premise applications delivered by SAP or SAP partners.

Using a concrete example, this documentation section demonstrates how you, as an SAP customer, can implement field extensions with your own custom code in the context of the ABAP CDS extension model.

Field Extensibility

Field extensibility means that you would like to provide additional fields in a given business application context that is represented by the UI actually used. These are fields that were not foreseen by the application when delivered by SAP. In such a case, you have the option to use the extensibility infrastructure of the ABAP platform in order to add custom fields to the original application. This infrastructure needs to ensure first of all that new data elements are added to the persistency (database tables) and to all the involved layers in between (ABAP Dictionary, CDS, SAP Gateway service). The infrastructure also needs to be exposed again to the service metadata of the application’s UI for consumption

You can use this infrastructure in different scenarios:

  • Key user extensibility – You are solely interested in configurable extensions as they are used in the context of business power user (key user) adaption.
  • Custom code extensibility – You want maximize leverage of this infrastructure for field extensibility with custom code by implementing your own extensions.

Custom Code Versus Key User Extensibility

Key user extensibility allows key user to create custom fields, if the SAP application is enabled for extensibility. The key user has a business perspective and does not need to take care of technical details. So, in the end, the key user is able to create and change custom fields and their properties (name, label, type, or the position on the screen).

For each CDS view to be extended, the developer needs to create a data definition as development object and implement the corresponding CDS view extension using EXTEND VIEW syntax:
				
  AbapCatalog.sqlViewAppendName: 'CDS_APPEND_VIEW' 
  [@extension_annot1] 
  [@extension_annot2] 
   ... 
  EXTEND VIEW cds_view_original WITH cds_view_extension 
			[association1 association2 ...] 
			{ select_list_extension } [;] 
			
Using the syntax above, you can extend a delivered CDS view cds_view_original using a CDS view extension cds_view_extension. The CDS view extension adds the following elements to the SELECT list of the available view without making modifications:
  • The elements of the specified extension list select_list_extension, as known from view fields
  • Optional associations association1, association2, ... for the SELECT statement of the extended CDS view
  • Further annotations extension_annot1, extension_annot2... can also be specified.

Typical Use Cases for Custom Code Adaption

  • Adding calculated fields
  • Defining new associations in the extension code
  • Adding fields resulting from new associations

CDS Extension Model and Append Views

The CDS extension is based on the proven append technique that you probably already know from the ABAP Dictionary. Special views, known as append views, are the type of views that you as an SAP customer can use to add new fields to existing database views. They are intended for enhancements of database views of the SAP standard.

CDS extension model for field extensibility – design time view
Figure 62: CDS extension model for field extensibility – design time view

Architecture Overview

Architecture with CDS extension model – runtime view
Figure 63: Architecture with CDS extension model – runtime view