- In this post will show you how can we add multiple entity like Header and Item combination.
- Step 1: Create Interface view for flight table (/DMO/FLIGHT)
- Step 3: Interface view created for Flight Table
- Code:
@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Flight Information'
@Metadata.ignorePropagatedAnnotations: true
define view entity ZI_FLIGHT_INFORMATION_R
as select from /dmo/flight as Flight
{
key carrier_id as CarrierId,
key connection_id as ConnectionId,
key flight_date as FlightDate,
@Semantics.amount.currencyCode: 'CurrencyCode'
price as Price,
currency_code as CurrencyCode,
plane_type_id as PlaneTypeId,
seats_max as SeatsMax,
seats_occupied as SeatsOccupied
}
- Step 4: Create Projection view on top of the Interface view
- Step 5: Add relation between Parent and child in both the Interface CDS view as below and activate both CDS view together:
- Flight Connection CDS View Code:
@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Basic Inte view for Flight Connection'
@Metadata.ignorePropagatedAnnotations: true
define root view entity ZI_CONNECTION_R
as select from /dmo/connection
composition[0..*] of ZI_FLIGHT_INFORMATION_R as _Flight
{
key carrier_id as CarrierId,
key connection_id as ConnectionId,
airport_from_id as AirportFromId,
airport_to_id as AirportToId,
departure_time as DepartureTime,
arrival_time as ArrivalTime,
@Semantics.quantity.unitOfMeasure: 'DistanceUnit'
distance as Distance,
distance_unit as DistanceUnit,
_Flight
}
- Flight Details CDS View Code:
@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Flight Information'
@Metadata.ignorePropagatedAnnotations: true
define view entity ZI_FLIGHT_INFORMATION_R
as select from /dmo/flight as Flight
association to parent ZI_CONNECTION_R as _Connection on $projection.CarrierId = _Connection.CarrierId
and $projection.ConnectionId = _Connection.ConnectionId
{
key carrier_id as CarrierId,
key connection_id as ConnectionId,
key flight_date as FlightDate,
@Semantics.amount.currencyCode: 'CurrencyCode'
price as Price,
currency_code as CurrencyCode,
plane_type_id as PlaneTypeId,
seats_max as SeatsMax,
seats_occupied as SeatsOccupied,
_Connection
}
- Step 6: Create Projection View for FLight Interface View
- Step 7: Select Projection View template and click on Finish
- Step 8: Projection View created for Flight table (Line Item )
- Step 9: Define Relation between two entity in Project View
- Root Projection (Header - Flight Connection) CDS View:
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Consuption view for Flight connection'
@Metadata.ignorePropagatedAnnotations: true
@Metadata.allowExtensions: true
define root view entity ZC_CONNECTION_R
provider contract transactional_query
as projection on ZI_CONNECTION_R
{
key CarrierId,
key ConnectionId,
AirportFromId,
AirportToId,
DepartureTime,
ArrivalTime,
@Semantics.quantity.unitOfMeasure: 'DistanceUnit'
Distance,
DistanceUnit,
_Flight : redirected to composition child ZC_FLIGHT_INFORMATION_R
}
- Flight Information Projection (Item) CDS View:
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Flight Information Projection View'
@Metadata.ignorePropagatedAnnotations: true
@Metadata.allowExtensions: true
define view entity ZC_FLIGHT_INFORMATION_R
as projection on ZI_FLIGHT_INFORMATION_R
{
key CarrierId,
key ConnectionId,
key FlightDate,
@Semantics.amount.currencyCode: 'CurrencyCode'
Price,
CurrencyCode,
PlaneTypeId,
SeatsMax,
SeatsOccupied,
/* Associations */
_Connection : redirected to parent ZC_CONNECTION_R
}
- Step 10: Create Metadata Extensio for Flight Information CDS view
- Step 11: Select Annotate Entity
- Step 12: See the belowMeta data extension:
- Step 13: Add Facet UI annotation in both Metadata extension so that we can navigate from Flight Connection(Header) and Flight Information(Item)
- Flight Connection (Header)
@Metadata.layer: #CORE
@UI.headerInfo: { typeName: 'Flight Detail',
typeNamePlural: 'Flight Detail'}
annotate entity ZC_CONNECTION_R with
{
@UI.facet: [{ id: 'FlightConnection',
purpose: #STANDARD,
position: 10,
label: 'Flight Connection',
type: #IDENTIFICATION_REFERENCE
},
{ id: 'FlightInfo',
purpose: #STANDARD,
position: 20,
label: 'Flight Information',
type: #LINEITEM_REFERENCE,
targetElement: '_Flight' }
]
@UI.selectionField: [{position: 10 }]
@UI.lineItem: [{ position: 10, label: 'Flight ID' }]
@UI.identification: [{ position: 10 }]
CarrierId;
@UI.selectionField: [{position: 20 }]
@UI.lineItem: [{ position: 20, label: 'Airline ID' }]
@UI.identification: [{ position: 20 }]
ConnectionId;
@UI.selectionField: [{position: 30 }]
@UI.lineItem: [{ position: 30, label: 'Departure From' }]
@UI.identification: [{ position: 30 }]
AirportFromId;
@UI.selectionField: [{position: 40 }]
@UI.lineItem: [{ position: 40, label: 'Destination To' }]
@UI.identification: [{ position: 40 }]
AirportToId;
@UI.lineItem: [{ position: 50, label: 'Departure Time' }]
@UI.identification: [{ position: 50 }]
DepartureTime;
@UI.lineItem: [{ position: 60, label: 'Arrival Time' }]
@UI.identification: [{ position: 60 }]
ArrivalTime;
@UI.lineItem: [{ position: 70, label: 'Distance' }]
@UI.identification: [{ position: 70 }]
Distance;
@UI.hidden: true
DistanceUnit;
}
- Flight Infomration (Item)
@Metadata.layer: #CORE
@UI.headerInfo: { typeName: 'FlightInfo',
typeNamePlural: 'Flight Information'}
annotate entity ZC_FLIGHT_INFORMATION_R with
{
@UI.facet: [{ id: 'FlightInfo',
position: 10,
label: 'Flight Information',
type: #PRESENTATIONVARIANT_REFERENCE }]
@UI.lineItem: [{ position: 10, label: 'Flight ID' }]
@UI.identification: [{ position: 10 }]
CarrierId;
@UI.lineItem: [{ position: 20, label: 'Airline ID' }]
@UI.identification: [{ position: 20 }]
ConnectionId;
@UI.lineItem: [{ position: 30, label: 'Flight Date' }]
@UI.identification: [{ position: 30 }]
FlightDate;
@UI.lineItem: [{ position: 40, label: 'Fare Price' }]
@UI.identification: [{ position: 40 }]
Price;
@UI.hidden: true
CurrencyCode;
@UI.lineItem: [{ position: 50, label: 'Plane Type' }]
@UI.identification: [{ position: 50 }]
PlaneTypeId;
@UI.hidden: true
SeatsMax;
}
- Step 14: Add Flight Information Projection CDS view to Servce Definitions, Double click on Service definition which we have created in RAP 1 tutorial.
- Step 15: Add Flight Informaiton Projection View added into Service Definitions show in below:
- Step16: Output: