You want to separate the basic definition of your data model from its specific usage (consumption). To do so, you build a new CDS view entity on top of your existing data model entity.
Prerequisites
For this exercise, you need the view entity for employee data that you created and annotated in previous exercises (suggested name was: Z##_R_Employee, where ## is your group number). If you have not finished the previous exercise, create a copy of data definition /LRN/R_EMPLOYEE_ANN.
Task 1: Define a CDS View Entity
Define a new CDS view entity that reads from your CDS view entity for employee data (suggested name: Z##_C_Employee, where ## is your group number). Use a template that adds all view elements of entity Z##_R_Employee to the element list of the new view and takes over the key definition from the base view.
Steps
In your own package, create a new data definition (suggested name: Z##_C_EMPLOYEE, where ## is your group number). Specify your existing view entity as Referenced Object and choose the Define View Entity template to generate the definition statement, some standard annotations and the element list.
In the Project Explorer view, right-click your existing data definition Z##_R_EMPLOYEE to open the context menu.
From the context menu, choose New Data Definition.
Confirm that the Package field contains the name of your package and that the Referenced Object field contains the name of your data definition.
In the Name field, enter the name for the CDS view entity (Z##_C_Employee, where ## is your group number).
Enter Employee (Consumption) in the Description field and choose Next.
Confirm the transport request and choose Next.
Caution
Make sure you don't choose Finish yet. If you do, you are not able to choose the template that you want to use.From the list of Templates, choose Define View Entity, then choose Finish.
Adjust the @ObjectModel.usageType annotations. Use the same values as in the base view.
Adjust the code as follows:
1234567
@ObjectModel.usageType:{
serviceQuality: #D,
sizeCategory: #M,
dataClass: #MASTER
}
Apply source code formatting.
From the eclipse menu, choose Source Code → Format. Alternatively, choose Shift + F1.
Task 2: Propagate Annotations
Enable the propagation of element annotations in your new view and analyze the result in the Active Annotations view. Then disable the propagation again and specify the mandatory element annotation directly.
Steps
In your new data definition, enable the propagation of element annotations.
Change the value of annotation @Metadata.ignorePropagatedAnnotations from true to false.
Activate the data definition.
Press Ctrl + F3 to activate the development object.
Open the Active Annotations View and analyze the element annotation values for view elements AnnualSalary and CurrencyCode .
Right-click anywhere in the source code of the data definition and choose Open With → Active Annotations.
The Active Annotations view appears as a new tab below the editor view.
From the toolbar on the Active Annotations view, choose Collapse All.
Expand Z##_C_EMPLOYEE → AnnualSalary → @Semantics → Amount.
In your new data definition, disable the propagation of element annotations again.
Change the value of annotation @Metadata.ignorePropagatedAnnotations back to true.
Solve the syntax error by adding the mandatory element annotation directly to the AnnualSalary view element.
Adjust the code as follows:
123456
DepartmentId,
@Semantics.amount.currencyCode: 'CurrencyCode'
AnnualSalary,
CurrencyCode,
Activate the data definition.
Press Ctrl + F3 to activate the development object.