Create and Expose Core Data Services Based on a Database Table
- How to create a database table
- How to create Core Data Services
Prerequisites
- SAP BTP, ABAP Environment user
- Business Catalog
SAP_CORE_BC_EXT_TST
assigned to your business user - Initial development setup
In this tutorial, wherever XXX
appears, use a number (e.g. 000
).
- Step 1
Select to your ABAP package created in tutorial Create Simple Database Table for ABAP Environment and create a Core Data Services (CDS) data definition.
Therefore right-click on your packageZ_BOOKING_XXX
and select New > Other Repository Object. - Step 2
Search for data definition, select it and click Next.
Enter a name and a description for your data definition
ZI_BOOKING_XXX
.Select a new transport request and click Next.
Select Define View template and press Finish.
- Step 3
Specify the
sql view name
in the view definition asZV_BOOKING_XXX
.Specify your data source after the select from statement as
ztbooking_xxx
.Specify your data definition as shown below. The keyword key is used to specific a key element and the keyword as is used to define alias names. The two associations
I_Country
andI_Currency
are defined and exposed in the projection. The elementCurrencyCode
is specified as currency key for the element Cost which is an amount field. The view entity is specified as searchable using the view annotation@Search.searchable: true
and the elementCustomerName
is specified as default search element using the element annotation@Search.defaultSearchElement: true
.ABAPCopy@AbapCatalog.sqlViewName: 'ZV_BOOKING_XXX' @AbapCatalog.compiler.compareFilter : true @AbapCatalog.preserveKey: true @AccessControl.authorizationCheck: #CHECK @EndUserText.label : 'Data Definition Booking' @Search.searchable : true define view ZI_BOOKING_XXX as select from ztbooking_xxx as Booking association [0..1] to I_Country as _Country on $projection.country = _Country.country association [0..1] to I_Currency as _Currency on $projection.CurrencyCode = _Currency.Currency { key booking as Booking, @Search.defaultSearchElement: true customername as CustomerName, numberofpassengers as NumberOfPassengers, emailaddress as EmailAddress, country, dateofbooking as DateOfBooking, dateoftravel as DateOfTravel, @Semantics.amount.currencyCode: 'CurrencyCode' cost, @Semantics.currencyCode: true currencycode as CurrencyCode, lastchangedat as LastChangedAt, _Country, _Currency }
- Save and activate.
- Step 4
Go back to the data definition and used the
@UI
annotations to add the UI-specific semantics. Add following UI annotation in front of your data definition.ABAPCopy@UI: { headerInfo: { typeName: 'Booking', typeNamePlural: 'Bookings', title: { type: #STANDARD, value: 'Booking' } } }
Replace your code with following:
ABAPCopy@AbapCatalog.sqlViewName: 'ZV_BOOKING_XXX' @AbapCatalog.compiler.compareFilter : true @AbapCatalog.preserveKey: true @AccessControl.authorizationCheck: #CHECK @EndUserText.label : 'Data Definition Booking' @Search.searchable : true @UI: { headerInfo: { typeName: 'Booking', typeNamePlural: 'Bookings', title: { type: #STANDARD, value: 'Booking' } } } define view ZI_Booking_XXX as select from ztbooking_xxx as Booking association [0..1] to I_Country as _Country on $projection.country = _Country.Country association [0..1] to I_Currency as _Currency on $projection.CurrencyCode = _Currency.Currency { @UI.facet: [ { id: 'Booking', purpose: #STANDARD, type: #IDENTIFICATION_REFERENCE, label: 'Booking', position: 10 } ] @UI: { lineItem: [ { position: 10, importance: #HIGH, label: 'Booking ID' } ], identification:[ { position: 10, label: 'Booking ID' } ] } key booking as Booking, @UI: { lineItem: [ { position: 20, label: 'Customer', importance: #HIGH } ], identification:[ { position: 10, label: 'Customer' } ] } @Search.defaultSearchElement: true customername as CustomerName, @UI: { lineItem: [ { position: 30, label: 'No of Passengers', importance: #HIGH } ], identification:[ { position: 30, label: 'No of Passengers' } ] } numberofpassengers as NumberOfPassengers, @UI: { identification:[ { position: 40, label: 'Email' } ] } emailaddress as EmailAddress, @UI: { identification:[ { position: 50, label: 'Country' } ] } country, @UI: { identification:[ { position: 60, label: 'Booked On' } ] } dateofbooking as DateOfBooking, @UI: { identification:[ { position: 70, label: 'Traveling on' } ] } dateoftravel as DateOfTravel, @UI: { lineItem: [ { position: 40, label: 'Cost', importance: #HIGH } ], identification:[ { position: 80, label: 'Cost' } ] } @Semantics.amount.currencyCode: 'CurrencyCode' cost, @UI: { identification:[ { position: 90, label: 'Currency' } ] } @Semantics.currencyCode: true currencycode as CurrencyCode, @UI: { identification:[ { position: 100, label: 'Last Changed At' } ] } lastchangedat as LastChangedAt, //public associations _Country, _Currency }
Save and activate your data definition.
- Step 5
Right-click on your data definition
ZI_BOOKING_XXX
and select New Service DefinitionCreate a service definition and call it
ZI_BOOKING_XXX
.Click Finish to complete your transport request.
- Step 6
Expose the
ZI_Booking_XXX
and theI_Country
view entities.ABAPCopy@EndUserText.label: 'Service Definition for Booking' define service ZI_Booking_XXX { expose ZI_Booking_XXX as Booking; expose I_Country as Country; }
Save and activate your service definition.
- Step 7
Right-click on your service definition
Z_I_BOOKING_XXX
and select New Service Binding.Create a service binding and name it
Z_I_BOOKING_XXX
.
Make sure thatOData V2 - UI
is selected as binding type.
Click Next >.Click Finish to complete your transport request.
- Step 8
Activate your service binding.
Click Publish.
- Step 9
In your service binding, check your result. Select
to_Country
and click Preview.Login with your username and password.
Click on GO.
Check your result.
- Step 10
Write following UI annotation as a header Information:
typeName
:Test
typeNamePlural
:Tests
title
:type
:#STANDARD
value
:testyourself