Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  ABAP RESTful Programming Model →  Behavior Definitions →  ABAP BDL - Example 

Child entity example

Other versions: 7.31 | 7.40 | 7.54


Example

In the business object's structure, the CDS view /DMO/I_Booking represents a child entity of the root entity Travel that can be used to create and edit flight bookings. The child entity Booking is used to manage the following flight booking data: trip ID, booking ID and date, customer number, airline, connection, and price of the flight. The booking data can only be created for a specific Travel instance.

The booking data is saved in the database table /DMO/BOOKING.

@AbapCatalog.sqlViewName: 'ZDEMO_BOOKING_DB'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@AbapCatalog.preserveKey: true
@EndUserText.label: 'Booking'
@Search.searchable: true

define view /DMO/I_Booking
  as select from /dmo/booking as Booking

  association to parent /DMO/I_Travel as _Travel              on
    $projection.Travel_ID = _Travel.Travel_ID
  association [1..1] to /DMO/I_Customer     as _Customer      on
    $projection.Customer_ID = _Customer.CustomerID
  association [1..1] to /DMO/I_Carrier      as _Carrier       on
    $projection.Carrier_ID = _Carrier.CarrierID
  association [1..1] to /DMO/I_Connection   as _Connection    on
    $projection.Carrier_ID    = _Connection.CarrierID         and
    $projection.Connection_ID = _Connection.ConnectionID
  association [0..*] to I_CurrencyText      as _CurrencyText  on
    $projection.Currency_Code = _CurrencyText.Currency
{
  @ObjectModel.readOnly: true
  @Search.defaultSearchElement: true
  key travel_id                 as Travel_ID,

  @ObjectModel.readOnly: true
  @Search.defaultSearchElement: true
  key booking_id                as Booking_ID,

  booking_date                  as Booking_Date,

  @Consumption.valueHelpDefinition: [{
    entity: {name: '/DMO/I_Customer', element: 'CustomerID' }}]
  @ObjectModel.text.association: '_Customer'
  @Search.defaultSearchElement: true
  customer_id                   as Customer_ID,

  @Consumption.valueHelpDefinition: [{
    entity: {name: '/DMO/I_Carrier', element: 'CarrierID' }}]
  @ObjectModel.text.association: '_Carrier'
  @Search.defaultSearchElement: true
  carrier_id                    as Carrier_ID,

  @Consumption.valueHelpDefinition: [{
    entity: {name: '/DMO/I_Connection', element: 'ConnectionID' },
    additionalBinding: [
      { localElement: 'Flight_Date',   element: 'FlightDate'},
      { localElement: 'Carrier_ID',    element: 'CarrierID'},
      { localElement: 'Flight_Price',  element: 'Price' },
      { localElement: 'Currency_Code', element: 'CurrencyCode' }]}]
  @ObjectModel.text.association: '_Connection'
  connection_id                 as Connection_ID,

  @Consumption.valueHelpDefinition: [{
    entity: {name: '/DMO/I_Connection', element: 'FlightDate' },
    additionalBinding: [
      { localElement: 'Connection_ID', element: 'ConnectionID'},
      { localElement: 'Carrier_ID',    element: 'CarrierID'},
      { localElement: 'Flight_Price',  element: 'Price' },
      { localElement: 'Currency_Code', element: 'CurrencyCode' }]}]
  flight_date                   as Flight_Date,

  @Semantics.amount.currencyCode: 'Currency_Code'
  flight_price                  as Flight_Price,

  @Semantics.currencyCode: true
  @Consumption.valueHelpDefinition: [{
    entity: {name: 'I_CurrencyText', element: 'Currency' }}]
  @ObjectModel.text.association: '_CurrencyText'
  currency_code                 as Currency_Code,

  /* Associations */
  _Travel,
  _Customer,
  _Carrier,
  _Connection,
  _CurrencyText
}