In this exercise, you enable the extension of the data model, that is, the extension of the business object and its projection. First, you enable the extension of the database table for flight travel items and the related draft table. Then, you enable the extension of the data model view and the projection view for flight travel items.
Note
In this exercise, replace ## with your group number.
Solution
| Repository Object Type | Repository Object ID |
|---|
| Database Table Definition (Active Data) | /LRN/437H_TRITEM |
| Database Table Definition (Draft) | /LRN/437H_TRIT_D |
| Structure Type (Extension Include Structure) | /LRN/437H_S_EXT_TRITEM |
| CDS Data Definition (Model) | /LRN/437H_R_TRAVELITEM |
| CDS Data Definition (Projection) | /LRN/437H_C_TRAVELITEM |
| CDS Data Definition (Extension Include View) | /LRN/437H_E_TRAVELITEM |
Task 1: Enable Extension of DB Tables
Enable the extension of your database table for flight travel items Z##_TRITEM and of the corresponding draft table Z##_TRITEM_D. Follow the best practice to ensure that future extensions are consistent: Define an extension include structure (suggested name: Z##_S_EXT_TRITEM) with a dummy component and include it in both database table definitions. Then define the extension include structure and both database tables as extensible with char-like and numeric fields and define a mandatory field suffix (suggested suffix: ZIT).
Steps
Create a structure type as extension include (suggested name: Z##_S_EXT_TRITEM).
In the Project Explorer, locate your package ZS4D437_## under the Favorite Packages node.
Expand your package and right-click the Dictionary sub node. Choose New→Structure.
Enter Z##_S_EXT_TRITEM as Name and Extension Include Structure for Travel Items as Description. Then choose Next.
Confirm the transport request and choose Finish.
In the structure type, define a single component (suggested name: dummy_field). As the component type, use the built-in dictionary type CHAR with a length of 1.
In the structure type definition, replace the component_to_be_changed placeholder with dummy_field.
Replace abap.string(0) with abap.char(1).
Enable extensibility for the structure type. Allow extension with char-like and numeric fields but not with deep component types like, for example, table types.
In the AbapCatalog.enhancement.category annotation, replace the default value #NOT_EXTENSIBLE with #EXTENSIBLE_CHARACTER_NUMERIC.
Hint
Use code completion to choose from the available enhancement categories.
Define a mandatory suffix Z## for extension fields.
Adjust the code as follows:
12345678
@EndUserText.label : 'Extension Include Structure for Travel Items'
@AbapCatalog.enhancement.category : #EXTENSIBLE_CHARACTER_NUMERIC
@AbapCatalog.enhancement.fieldSuffix : 'Z##'
define structure z##_s_ext_tritem {
dummy_field : abap.char(1);
}
Activate the structure type.
Press Ctrl + F3 to activate the development object.
Edit the definition of your database table for flight travel items Z##_TRITEM and include the structure type into the field list.
Note
As you C1 released the database table in a previous exercise, you will receive a popup with the following message when you try to edit the table definition: Object is a stable API. Do not change incompatibly. Confirm this popup with OK.
At the end of the field list, add the following code:
1
include z##_s_ext_tritem;
Enable extensibility for the database table definition with the same enhancement category as in the extension include structure and activate the database table definition.
In the AbapCatalog.enhancement.category annotation, replace the default value #NOT_EXTENSIBLE with #EXTENSIBLE_CHARACTER_NUMERIC.
Press Ctrl + F3 to activate the development object.
Edit the definition of your draft table for flight travel items Z##_TRITEM_D. Include the structure as before and activate the database table definition.
Add the following code at the end of the field list:
1
include z##_s_ext_tritem;
Press Ctrl + F3 to activate the development object.
Task 2: Enable Extension of CDS Views
Enable the extension of the CDS view entities for flight travel items. Follow the best practice to ensure consistent extensions: Define an extension include view (suggested name: Z##_E_TravelItem) with only the key field of flight travel items. Then add an association to the view on data model level Z##_R_TravelItem with the extension include view as target (suggested association name: _Extension).
Allow the extension of the view on data model level Z##_R_TravelItem and the projection view Z##_C_TravelItem. In both cases, restrict the extensibility to elements from the target of the association _Extension.
Steps
Create a CDS view entity (suggested name: Z##_E_TravelItem) with your database table for active flight travel items Z##_TRITEM as data source.
Note
Specify the database table as a Referenced Object to generate the element list.
In the Project Explorer, locate the database table for active travel items Z##_TRITEM.
Right-click the database table and choose New Data Definition.
Enter Z##_E_TravelItem as Name and Extension Include for Travel Items as Description. Make sure that the Referenced Object field contains the name of the database table and choose Next.
Confirm the transport request and choose Next.
From the list of templates, select the defineViewEntity template and choose Finish.
In the definition of the view entity, remove all elements except for the key element ItemUuid.
In the element list, select all elements without the keyword KEY and press the Delete key.
Remove the comma at the end of the remaining element.
Enable extensibility for the extension view entity.
In the AbapCatalog.viewEnhancementCategory annotation, replace the default value #NONE with #PROJECTION_LIST.
Before the DEFINE VIEW ENTITY statement, insert the following code:
123
@AbapCatalog.extensibility: {
extensible: true
}
Restrict the extension to the existing data source.
Note
To achieve this, you have to define an alias name for the data source (suggested name: Item). You define this alias in the FROM clause of the SELECT statement.
Adjust the DEFINE VIEW ENTITY statement as follows:
12345
define view entity Z##_E_TravelItem
as select from z##_tritem as Item
{
key item_uuid as ItemUuid
}
Adjust the AbapCatalog.extensibility annotation as follows:
12345
@AbapCatalog.extensibility: {
extensible: true,
allowNewDatasources: false,
dataSources: ['Item']
}
Define a mandatory suffix Z## for extension elements and activate the data definition.
Adjust the AbapCatalog.extensibility annotation as follows:
123456
@AbapCatalog.extensibility: {
extensible: true,
allowNewDatasources: false,
dataSources: ['Item'],
elementSuffix: 'Z##'
}
Press Ctrl + F3 to activate the development object.
Edit the definition of your CDS view entity for travel items on data model level Z##_R_TravelItem. Define and expose an association with the extension include view as target (suggested association name: _Extension).
Adjust the code as follows:
123456789
define view entity Z##_R_TravelItem
as select from z##_tritem
association to parent Z##_R_Travel as _Travel
on $projection.AgencyId = _Travel.AgencyId
and $projection.TravelId = _Travel.TravelId
association to Z##_E_TravelItem as _Extension
on $projection.ItemUuid = _Extension.ItemUuid
{
At the end of the element list, adjust the code as follows:
123
_Travel,
_Extension
}
Enable extensibility for the CDS view entity and activate the data definition. Specify the same mandatory element suffix and restrict the extensibility with the _Extension association as the only allowed data source.
Note
Adding annotation AbapCatalog.viewEnhancementCategory is optional. If it's missing, the default value [#PROJECTION_LIST] is used.
At the beginning of the data definition, add the following code:
1234567
@AbapCatalog.viewEnhancementCategory: [#PROJECTION_LIST]
@AbapCatalog.extensibility: {
extensible: true,
allowNewDatasources: false,
dataSources: ['_Extension'],
elementSuffix: 'Z##'
}
Press Ctrl + F3 to activate the development object.
Edit the definition of your CDS view entity for travel items on projection level Z##_C_TravelItem. Enable extensibility for the CDS view entity and activate the data definition. Specify the same mandatory element suffix as before and restrict the extensibility with the primary data source Z##_R_TravelItem as the only allowed data source.
Note
To achieve this, you must define an alias name for the data source (suggested name: Item) in the AS PROJECTION ON addition.
Adjust the DEFINE VIEW ENTITY statement as follows:
123
define view entity Z##_C_TravelItem
as projection on Z##_R_TravelItem as Item
{
At the beginning of the data definition, add the following code:
1234567
@AbapCatalog.viewEnhancementCategory: [#PROJECTION_LIST]
@AbapCatalog.extensibility: {
extensible: true,
allowNewDatasources: false,
dataSources: ['Item'],
elementSuffix: 'Z##'
}
Press Ctrl + F3 to activate the development object.