SAP CDS EXTEND CUSTOM ENTITY



Get Example source ABAP code based on a different SAP table
  


• EXTEND CUSTOM ENTITY ABAP_CDS_DDL_STATEMENT
• WITH ABAP_CDS_EXT_CUS_ENT

ABAP_CDS_DDL - EXTEND CUSTOM ENTITY

ABAP_SYNTAX

EXTEND CUSTOM ENTITY CustomEntity WITH
{ ElementListExtension }

What does it do?
Extends an existing CDS custom entity CustomEntity using a CDS custom entity extension in the CDS DDL. An existing CDS custom entity can have one or more CDS custom entity extensions.

ABAP_PREREQUISITE
As a prerequisite, the extended entity must allow extensions. Extensions are allowed by default or can be explicitly allowed with the annotation AbapCatalog.extensibility.extensible with the value true . If the value false is specified, extensions are not allowed.
ABAP_PREREQ_END

Components of a Custom Entity Extension
Custom entity extensions can make additions to the original entity, but they cannot modify, overwrite, or delete elements from the original entity. A custom entity extension can specify only features that are possible within custom entities, but with some limitations. The following can be specified in a custom entity extension:
New elements. These new elements are defined as described in topic DEFINE CUSTOM ENTITY, Element . Those elements can have element annotations. New key elements are not possible.
New associations _assoc1, _assoc2 can be defined in the CDS custom entity extension. The same rules apply that are described in topic DEFINE CUSTOM ENTITY, association.
New CDS compositions _compos1, _compos2 can be defined in the CDS custom entity extension under the condition that the composition target is also defined as composition child and has the required to-parent association. The composition target is the extended custom entity, not the extension itself. The same rules apply that are described in topic DEFINE CUSTOM ENTITY, Composition.
Each appended element must have a unique name.
Elements that are added to a custom entity by an extension change the custom entity signature. The ABAP class that implements the CDS custom entity can access the original and the extension fields.

ABAP_RESTRICTIONS
CDS custom entity extensions themselves cannot be extended.
It is not possible to specify new input parameters in a custom entity extension.
CDS to-parent associations must not be defined in a custom entity extension.
No addition ROOT can be specified in the statement EXTEND CUSTOM ENTITY to transform a regular entity to a root entity.
An appended element cannot be defined as a KEY element.
In a custom entity extension, header annotations are not supported. That means that no annotations are allowed in front of the statement EXTEND CUSTOM ENTITY.
ABAP_RESTR_END



Latest notes:

As stated above, a custom entity extension changes the custom entity signature of the ABAP class that implements the custom entity. To use the extension elements, the following options exist:
If the implementing ABAP class selects data from data sources, such as CDS entities or DDIC database tables, these data sources can also be extended. The custom entity extension fields can be passed to the extension fields of the data source with MOVE-CORRESPONDING.
If a customer wants to process the extension fields in the custom entity implementation, this can be enabled via BAdIs provided by the owner of the custom entity.
NON_V5_HINTS
ABAP_HINT_END
VX_EXA_ONLY

ABAP_EXAMPLE_VX
The CDS custom entity extension DEMO_CDS_EXTEND_CUSTOM
DDLS DEMO_CDS_EXTEND_CUSTOM
adds a new element and two new associations to the existing CDS custom entity.
DDLS DEMO_CDS_ORIGINAL_CUSTOM
ABAP_EXAMPLE_END