This blog post provides an overview of all available types of CDS extensions.
Statement Can be used for Available since
EXTEND VIEW ENTITY |
| 7.87 | 1911 | 7.55 |
EXTEND CUSTOM ENTITY | CDS custom entity | 7.89 | 2208 | 7.57 |
EXTEND ABSTRACT ENTITY | CDS abstract entity | 7.84 | 2105 | 7.56 |
EXTEND VIEW | CDS DDIC-based view | 7.40, SP08 |
The statement EXTEND VIEW ENTITY is a replacement of EXTEND VIEW, designed for the extension of CDS view entities and CDS projection views.
An existing CDS view can have one or more CDS view entity extensions. A CDS entity extension can not be further extended.
Both kinds of view extensions, EXTEND VIEW and EXTEND VIEW ENTITY, can be used for all three kinds of CDS views (CDS view entities, CDS projection views, CDS DDIC-based views). This is supported for migration and compatibility reasons, but it is not recommended.
The header annotation @AbapCatalog.viewEnhancementCategory[ ] specifies how a CDS view entity can be extended. The possible values are:
The following CDS view entity allows extensions of the SELECT list.
@AccessControl.authorizationCheck: #NOT_REQUIRED
@AbapCatalog.viewEnhancementCategory: [#PROJECTION_LIST]
@EndUserText.label: 'Further information about the CDS entity'
define view entity DEMO_CDS_ORIGINAL_VIEW_VE
as select from
spfli
join scarr on
scarr.carrid = spfli.carrid
{
key scarr.carrname as carrier,
key spfli.carrid as carrierId,
key spfli.connid as flight,
spfli.cityfrom as departure,
spfli.cityto as destination
};
The following CDS view entity extension defines and exposes a new association:
extend view entity DEMO_CDS_ORIGINAL_VIEW_VE with
association [1..*] to sflight as _sflight
on $projection.carrierId = _sflight.carrid
{
_sflight
}
CDS custom entity extensions can be used to add elements to a custom entity without making any modifications to the original entity.
The following CDS custom entity extension
extend custom entity DEMO_CDS_ORIGINAL_CUSTOM with
{
col4 : abap.char(1);
_assoc : association to DEMO_CDS_CUSTOM_ENTITY
on $projection.col2 = _assoc.id;
_compos : composition [0..1] of DEMO_CDS_CUSTOM_CHILD;
}
extends the existing CDS custom entity
@EndUserText.label: 'CDS custom entity, extended entity'
@AbapCatalog.extensibility.extensible: true
define root custom entity DEMO_CDS_ORIGINAL_CUSTOM
with parameters
param1 : abap.int4
{
key col1 : abap.char( 5 );
col2 : abap.int4;
col3 : abap.int4;
}
CDS abstract entity extensions were designed specifically to extend CDS abstract entities. Here’s a short overview of the rules:
The following CDS abstract entity allows extensions:
@EndUserText.label: 'CDS abstract entity with extension'
@AbapCatalog.extensibility.extensible: true
define abstract entity DEMO_CDS_ORIGINAL_ABSTRACT
with parameters
param1 : abap.int4
{
col1 : abap.char( 5 );
col2 : abap.int4;
col3 : abap.int4;
}
A new field and a new association are added by the following CDS abstract entity extension:
extend abstract entity DEMO_CDS_ORIGINAL_ABSTRACT with
{
col4 : abap.char( 1 );
_assoc : association to demo_cds_abstract_entity
on $projection.col1 = _assoc.col1;
}
The following program evaluates the structure of the enhanced CDS abstract entity using RTTI methods:
CLASS demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
ENDCLASS.
CLASS demo IMPLEMENTATION.
METHOD main.
DATA(out) = cl_demo_output=>new( ).
DATA(components) =
CAST cl_abap_structdescr( cl_abap_typedescr=>describe_by_name(
'DEMO_CDS_ORIGINAL_ABSTRACT' )
)->components.
out->write( components ).
cl_dd_ddl_annotation_service=>get_direct_annos_4_entity(
EXPORTING
entityname = 'DEMO_CDS_ORIGINAL_ABSTRACT'
IMPORTING
annos = DATA(annos) ).
out->write( annos ).
*
DATA(struct) = VALUE demo_cds_original_abstract(
col1 = 'hallo'
col2 = 333
col3 = 2
col4 = 'A' ).
out->write( struct ).
out->display( ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
demo=>main( ).
The result set contains the column added via the extension:
Further information on CDS entity extensions is available in the ABAP Keyword Documentation, secion about CDS entity extensions.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
4 | |
3 | |
3 | |
2 | |
2 | |
2 | |
2 | |
1 |