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).
Note
Recommendation: If an SAP application is enabled for extensibility we recommend that you use the
key user tool to create custom fields, even as a developer, because the key user
tool hides the technical details of the SAP application from you. On the other
side, we recommend to create custom fields directly using extend view only if...
- The SAP application is not yet enabled for extensibility
- The functionality of the key user tool is not sufficient. For example,
you want to do a calculation in a custom field.
We must remember that custom code extensibility requires the entire
development cycle to implement extensions by means of code additions. This, in
turn, requires an extension for the data model that was originally delivered in
the form of CDS views and was published as an OData service for further
consumption.
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.
Note A CDS view can be extended using multiple CDS view extensions.
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.
Remember
With an append view, fields of the original tables can be included
in the view without modifications. An append view is assigned to one database view.
However, you can create more than one append view for a database view. For each
active database view, the system looks for all the append views that are assigned
and their fields are then appended to the database view. When you create or change
an append view, the assigned database view is automatically adjusted to this change
when you activate the append view.
Figure 1:
CDS extension model for field extensibility – design time view
Architecture Overview
Figure 2:
Architecture with CDS extension model – runtime view