SAP Home Learn Build Integrate Model Operate Extend with AI ConnectTutorial navigator Knowledge Graph API Devtoberfest Developer Advocates App Space

Manage my Account SAP Devs YouTube ↗ Learnings ↗ Community ↗ Provide Feedback ↗
Logout
โคข Open full site

Enhance an ABAP Core Data Services (CDS) View in ABAP On-Premise

Add features like value help, aggregations, and calculated fields to an existing CDS view

Overview

🎓 beginner 60 min. ABAP DevelopmentBeginnerSAP Netweaver 7.5

You will learn

  • โœ”How to add value help using a filter
  • โœ”How to add textual information using associations
  • โœ”How to concatenate two elements, using a built-in function for CDS
  • โœ”How to convert currencies using a built-in function for CDS
  • โœ”How to use grouping and aggregation
  • โœ”How to create an object page
  • โœ”How to create a parent-child hierarchy in your business object
  • โœ”How to add a CASE statement
Unknown U Unknown March 21, 2023
Created by March 9, 2023
Contributors

Prerequisites

Steps

Intro

You can then use some of these features in productive development to make your applications more powerful and more user-friendly. By the end of this tutorial, your application should look like this.

fep-final-enhance
fep-final-enhance
step13c-fep-CASE
step13c-fep-CASE

You can see the code at the end of this tutorial. Throughout the tutorial, objects name include a suffix, such as XXX. Always replace this with your group number or initials.


Step 1 Add value help
โ€”

To make the input fields more useful, you will now add input value help to the field AgencyID.

  1. Specify the source of the value help. This works a bit like a join: You need to point to an entity, and field common to both the entity and your CDS view. In this case, you will point to AgencyID in the CDS entity /DMO/I_Agency. Add the following annotation to your field AgencyID.

    CDS
    @Consumption.valueHelpDefinition: [{  entity: {name: '/DMO/I_Agency', element: 'AgencyID'}  }]
  • You also need to expose this second entity in the OData service. To do this, add the entity /DMO/I_Agency to your service definition, so the complete definition looks like this:

    CDS
    @EndUserText.label: 'Service exposes Travel Data 005'
    define service Z_EXPOSE_TRAVEL_005 {
      expose Z_C_TRAVEL_DATA_005 as Travel;
      expose /DMO/I_Agency as Agency;
    }
  • Format, save, and activate both CDS view and service definition ( Shift+F1, Ctrl+S, Ctrl+3 ).

  • Refresh your Fiori Elements preview and choose value help for the input field AgencyID.

    step13a-choose-value-help
    step13a-choose-value-help

  • Now the value help appears. Enter the country key DE and choose Go. Only German agencies appear on the list.

    step13b-german-agencies
    step13b-german-agencies

  • Repeat this step for CustomerID:

    CDS
    @Consumption.valueHelpDefinition: [{entity: {name: '/DMO/I_Customer', element: 'CustomerID' }}]
  • Also, expose this entity in the service definition:

    CDS
    expose /DMO/I_Customer as Customer;
  • Step 2 Add text associations
    +
  • Check that the association is included in the field list. (This should have been done automatically when you inserted the signature of /DMO/I_TRAVEL_U.)

    step14b-association-added
    step14b-association-added

  • Format, save, and activate ( Shift+F1, Ctrl+S, Ctrl+F3 ).

  • Make sure that the entity /DMO/I_Agency has been added to your service definition. (You should have done this in step 1.)

    step2a-sd-added
    step2a-sd-added

  • Refresh your Fiori Elements preview. The agency name should now be shown, with the ID number in parentheses.

    step14c-fep-agency-by-name
    step14c-fep-agency-by-name

  • Repeat for the fields CustomerID and Currency_Code:

    CDS
    association [1..1] to /DMO/I_Customer as _Customer    on $projection.CustomerID =   _Customer.CustomerID
    association [0..*] to I_CurrencyText as _CurrencyText on $projection.CurrencyCode = _CurrencyText.Currency
  • CDS
    @ObjectModel.text.association: '_Customer'
    @ObjectModel.text.association: '_CurrencyText'
  • Also make sure these associations are added to the list of fields:

    CDS
    //Associations
    _Customer
    _CurrencyText

    step2b-associations-added
    step2b-associations-added

  • Step 3 Merge two fields
    +

    step15a-concat
    step15a-concat

  • Also make sure this association is added to the list of fields:

    CDS
    
    //Associations
    _Customer
  • Format, save, and activate these objects using Shift+F1, Ctrl+S, Ctrl+F3 .

  • Check the result in the data preview, by clicking in the editor and choosing Open With > Data Preview from the context menu. The result should look like this. If not, make sure that you have selected the Addressee field in Settings.

    step3-settings-addressee
    step3-settings-addressee
    step15b-concat-result
    step15b-concat-result

  • Now you have the addressee, you may want to comment out the text association for CustomerID.

  • Step 4 Add currency conversion
    +
    Step 5 Add aggregation and grouping
    +
    Step 6 Test aggregation and grouping
    +
    Step 7 Check code
    +
    Step 8 Test yourself
    +
    Step 9 Create object page
    +
  • Add the following to the other elements, so that your metadata extension looks like this:

    CDS
    @UI: { lineItem:     [ {  position: 20, label: 'Agency', importance: #HIGH } ],
         identification: [ { position: 20 } ],
         selectionField: [{position: 20  }]
        }
    AgencyID;
    
    
    @UI: { lineItem:        [ {  position: 30, label: 'Customer', importance: #HIGH  } ]
           ,identification: [ { position: 30 } ]
           ,selectionField: [ { position: 30 }]
          }
    CustomerID;
    
    
    @UI: {  lineItem: [ { position: 40 } ],
            identification: [ { position: 40 } ],
            selectionField: [ { position: 40 }]
          }
    BeginDate;
    
    
    @UI: {  lineItem: [ { position: 50 } ],
            identification: [ { position: 50 } ]
           ,selectionField: [ { position: 50 }]
          }
    EndDate;
    
    
    @UI: { lineItem: [ { position: 60 } ],
            identification: [ { position: 50 } ]
    
           }
    TotalPrice;
  • Finally, add a header to your object page, just after the layer annotation (before the annotate view... statement):

    CDS
    @UI: {
      headerInfo: {
        typeName: 'Travel',
        typeNamePlural: 'Travels',
        title: {
          type: #STANDARD,
          label: 'Travel',
          value: 'TravelID'
        }
      }
    }
  • step6c-header
    step6c-header

  • Test your object page in the Fiori Elements preview. It should look roughly like this:

    step6b-fep-preview-object-page
    step6b-fep-preview-object-page

  • Step 10 Create CDS entity for booking
    +
    Step 11 Specify hierarchy
    +
  • Now, choose Activate All (Shift+Ctrl+F3).

    Link text e.g., Destination screen
    Link text e.g., Destination screen

  • Choose Deselect All, then choose your two entities Z_I_TRAVEL_R_XXX and Z_I_BOOKING_XXX, then choose Activate.

    Link text e.g., Destination screen
    Link text e.g., Destination screen

  • Change the @AccessControl.authorizationCheck: to #NOT_REQUIRED.

  • Add an alias to the define view statement, so that your code looks like this:

    CDS
    @AccessControl.authorizationCheck: #CHECK
    @EndUserText.label: 'Read-only view from /DMO/I_BOOKING_U'
    define view entity Z_I_BOOKING_XXX as select from /DMO/I_Booking_U as Booking
  • Format, save, and activate the CDS entity (Shift+F1, Ctrl+S, Ctrl+F3) Z_I_BOOKING_XXX.

  • Step 12 Add annotations
    +
    Step 13 Create metadata extension for Z_I_BOOKING_XXX
    +
    Step 14 Add association from Travel to Booking
    +
    Step 15 Add Booking information to object page
    +
  • Test your new facet in the Fiori Elements preview. It should roughly look like this:

    step9b-fep-booking-facet
    step9b-fep-booking-facet

  • Step 16 Add association from Booking to Connection
    +
  • Now add the following two elements to the CDS entity Z_I_BOOKING_XXX:

    CDS
    @Semantics.quantity.unitOfMeasure: 'DistanceUnit'
    _Connection.Distance as Distance,
    
    _Connection.DistanceUnit as DistanceUnit,
  • Add the following to your service definition, Z_EXPOSE_TRAVEL_R_XXX.

    CDS
    expose /DMO/I_Connection as Connection;
  • Optional: Test your Fiori Elements preview again. It should look like this:

    step12a-fep-plus-connection
    step12a-fep-plus-connection

    If not, make sure that you have selected the field Flight Distance from Settings.

  • Step 17 Add CASE statement
    +

    step13b-add-where-clause
    step13b-add-where-clause

  • Format, save, and activate the CDS entity.

  • Test your Fiori Elements preview again. It should look like this:

    step13c-fep-CASE
    step13c-fep-CASE

  • Step 18 More Information
    +

    Resources

    Discussion

    Share feedback on this tutorial or join the conversation in SAP Community.

    Submit detailed feedback Discuss in Community
    Steps
    Step 1 of 18
    1. Add value help 2. Add text associations 3. Merge two fields 4. Add currency conversion 5. Add aggregation and grouping 6. Test aggregation and grouping 7. Check code 8. Test yourself 9. Create object page 10. Create CDS entity for booking 11. Specify hierarchy 12. Add annotations 13. Create metadata extension for Z_I_BOOKING_XXX 14. Add association from Travel to Booking 15. Add Booking information to object page 16. Add association from Booking to Connection 17. Add CASE statement 18. More Information

    Learn more →