Skip to Content

Create and Expose Core Data Services Based on a Database Table

Build a list report app with the ABAP RESTful Application Programming Model (RAP) for SAP Fiori and test your UI for demo usage.
You will learn
  • 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 package Z_BOOKING_XXX and select New > Other Repository Object.

    Open Eclipse
  • Step 2
    1. Search for data definition, select it and click Next.

      Create data definition
    2. Enter a name and a description for your data definition ZI_BOOKING_XXX.

      Create data definition
    3. Select a new transport request and click Next.

      Create data definition
    4. Select Define View template and press Finish.

      Create data definition
  • Step 3
    1. Specify the sql view name in the view definition as ZV_BOOKING_XXX.

      Specify SQL view
    2. Specify your data source after the select from statement as ztbooking_xxx.

      Specify SQL view
    3. 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 and I_Currency are defined and exposed in the projection. The element CurrencyCode 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 element CustomerName is specified as default search element using the element annotation @Search.defaultSearchElement: true.

      ABAP
      Copy
      @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       
      }
      
    4. Save and activate.
      Specify SQL view
  • Step 4
    1. 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.

      Add UI annotation
      ABAP
      Copy
          @UI: {
        headerInfo: {
        typeName: 'Booking',
        typeNamePlural: 'Bookings',
        title: { type: #STANDARD, value: 'Booking' }
        }
      }
      
    2. Replace your code with following:

      ABAP
      Copy
      @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
      }
      
    3. Save and activate your data definition.

      Add UI annotation
  • Step 5
    1. Right-click on your data definition ZI_BOOKING_XXX and select New Service Definition

      Create service definition
    2. Create a service definition and call it ZI_BOOKING_XXX.

      Create service definition
    3. Click Finish to complete your transport request.

      Create service definition
  • Step 6
    1. Expose the ZI_Booking_XXX and the I_Country view entities.

      ABAP
      Copy
      @EndUserText.label: 'Service Definition for Booking'
      
      define service ZI_Booking_XXX {
      expose ZI_Booking_XXX as Booking;
      expose I_Country  as Country;
      }
      
    2. Save and activate your service definition.

      Expose entities
  • Step 7
    1. Right-click on your service definition Z_I_BOOKING_XXX and select New Service Binding.

      Create service binding
    2. Create a service binding and name it Z_I_BOOKING_XXX.
      Make sure that OData V2 - UI is selected as binding type.

      Create service binding

      Click Next >.
    3. Click Finish to complete your transport request.

      Create service binding
  • Step 8
    1. Activate your service binding.

      Publish locally
    2. Click Publish.

      Open SAP Fiori elements view
  • Step 9
    1. In your service binding, check your result. Select to_Country and click Preview.

      Open SAP Fiori elements view
    2. Login with your username and password.

      Login
    3. Click on GO.

      Settings
    4. Check your result.

      Select filter
  • Step 10

    Write following UI annotation as a header Information:

    • typeName: Test
    • typeNamePlural: Tests
    • title:
    • type: #STANDARD
    • value: testyourself

Back to top