Hands-On exercise for week 1 unit 6: Creating a list report
In this unit you will add annotations to refine an object page (the 'travel details'). You will use the ABAP Development Tools in Eclipse which you installed in the hands-on exercises for week 1 unit 4 .
You will learn how to
- Add a title and a subtitle to the object page header
- Add key data to the object page header
- Add a section and use field groups to structure data
- Add a table
- Include pictures in a table
Whenever your unique suffix for creating objects is needed, the object names within this tutorial are named with suffix "######". For the screenshots the suffix "000100" was used.
Prerequisite: You have performed all previous exercises of this course.
Clicking on any item of the list report will show the object page for this item. The object page currently shows only some standard buttons and does not contain any further fields or actions. In this step you will add annotations to show a title and a subtitle in the object page header.
Remember that you can use code completion by pressing
CTRL+SPACEat the relevant positions in your coding
-
Open the metadata extensions for the Travel view
ZC_FE_TRAVEL_######. In the previous unit you already defined header information. Now you will enhance the annotation@UI.headerInfowith atitleand adescriptionproperty.... @UI: { headerInfo: { typeName: 'Travel', typeNamePlural: 'Travels', title: { type: #STANDARD, value: 'Description' }, description: { value: 'TravelID' } }, ...
Click Save and Activate.
-
Refresh the browser window. You will see an object page containing a title and a subtitle in the header and an empty content section. By the time the screenshot got created the subtitle falsely showed the text as subtitle. This was corrected in the meantime, and it shows the ID now.
In this step you will add some key information to the object page header using data points.
-
As in the steps before, open the metadata extensions for the Travel view
ZC_FE_TRAVEL_######.Add the
@UI.facetannotation with two objects of type#DATAPOINT_REFERENCE.... annotate view ZC_FE_TRAVEL_###### with { @UI.facet: [ { id: 'TravelHeaderPrice', purpose: #HEADER, type: #DATAPOINT_REFERENCE, position: 10, targetQualifier: 'PriceData' }, { id: 'TravelHeaderOverallStatus', purpose: #HEADER, type: #DATAPOINT_REFERENCE, position: 20, targetQualifier: 'StatusData' } ] @UI.lineItem: [{ position: 10}] TravelID; ...
-
Annotating properties
TotalPriceandOverallStatuswith@UI.datapointusing thetargetQualifierfrom the facet definition in step 1 will assign the properties to the header facet accordingly.... @UI.lineItem: [{ position: 70}] @UI.dataPoint: { qualifier: 'PriceData', title: 'Total Price'} TotalPrice; ...
... @UI.lineItem: [{ position: 80, criticality: 'OverallStatusCriticality' }] @UI.selectionField: [{ position: 30}] @UI.textArrangement: #TEXT_ONLY @UI.dataPoint: { qualifier: 'StatusData', title: 'Status', criticality: 'OverallStatusCriticality' } OverallStatus; ...
Click Save and Activate.
-
Switch to the app preview and refresh the browser window. The two new data points show up in the object page header. The labels are taken from property
title, the color of Status from propertycriticalityof thedatapointannotations .
In this step you will add a section to the content area of the object page. The section will contain a form with three data fields.
-
Open the metadata extension file for the Travel view
ZC_FE_TRAVEL_######and enter the facet annotations that define the section General Information as a collection facet, using the typeCollection. Add a second facet as a child of General Information with facet type#IDENTIFICATION_REFERENCEto create a form with title General. Add the code from line 8 to line 21 to your existing UI facet definition.... annotate view ZC_FE_TRAVEL_###### with { @UI.facet: [ ... { label: 'General Information', id: 'GeneralInfo', type: #COLLECTION, position: 10 }, { label: 'General', id: 'Travel', type: #IDENTIFICATION_REFERENCE, purpose: #STANDARD, parentId: 'GeneralInfo', position: 10 } ] ... }
-
Add a new field
Descriptionand annotate this and the propertiesAgencyIDandCustomerIDwith@UI.Identificationto position these fields under General.annotate view ZC_FE_TRAVEL_###### with { ... @UI.lineItem: [{ position: 10}] TravelID; @UI.identification: [{ position: 10 }] Description; @UI.lineItem: [{ position: 20}] @UI.selectionField: [{ position: 10}] @UI.identification: [{ position: 30 }] AgencyID; @UI.lineItem: [{ position: 30}] @UI.selectionField: [{ position: 20}] @UI.identification: [{ position: 20 }] CustomerID; ... }
Click Save and Activate.
-
Refresh the app window. The new form General is shown in section General Information containing the three fields.
A field group contains one or more data fields inside a UI container. In this step you define two field groups in section General Information.
-
Open the metadata extension file for the Travel view
ZC_FE_TRAVEL_######.First, define a field group for the beginning and end date of a travel item and for the prices. The facet type for a field group is
#FIELDGROUP_REFERENCE. Add the code from line 8 to line 25 to the end of the@UI.facetsection.annotate view ZC_FE_TRAVEL_###### with { @UI.facet: [ { ... { id: 'Dates', purpose: #STANDARD, type: #FIELDGROUP_REFERENCE, parentId: 'GeneralInfo', label: 'Dates', position: 30, targetQualifier: 'DatesGroup' }, { id: 'Prices', purpose: #STANDARD, type: #FIELDGROUP_REFERENCE, parentId: 'GeneralInfo', label: 'Prices', position: 20, targetQualifier: 'PricesGroup' } ] ... }
-
Annotate the properties
BeginDateandEndDatewith@UI.fieldGroup. Make sure you use the same field group qualifierDatesGroupbut different positions in each annotation. Apply the same for the propertiesBookingFeeandTotalPriceusing field group annotations with qualifierPricesGroup.... @UI.lineItem: [{ position: 40}] @UI.fieldGroup: [{ qualifier: 'DatesGroup', position: 10 }] BeginDate; @UI.lineItem: [{ position: 50}] @UI.fieldGroup: [{ qualifier: 'DatesGroup', position: 20 }] EndDate; @UI.lineItem: [{ position: 60}] @UI.fieldGroup: [ { qualifier: 'PricesGroup', position: 10} ] BookingFee; @UI.lineItem: [{ position: 70}] @UI.dataPoint: { qualifier: 'PriceData', title: 'Total Price'} @UI.fieldGroup: [{ qualifier: 'PricesGroup', position: 20 }] TotalPrice; ...
Click Save and Activate.
-
Refresh the app window. There are two additional field groups showing price and date information.
In this step you will add a new section that contains a table with booking information. This requires access to another entity Booking via an association and an additional metadata extension file.
-
Open the metadata extension file for the Travel view
ZC_FE_TRAVEL_######. In the facet annotation block add a new facet Booking with type#LINEITEM_REFERENCE. Add the code from line 7 to line 14 to the end of the@UI.facetsection. Click Save and Activate.... annotate view ZC_FE_TRAVEL_###### with { ... @UI.facet: [ ... { id: 'Booking', purpose: #STANDARD, type: #LINEITEM_REFERENCE, label: 'Bookings', position: 20, targetElement: '_Booking' } ] ...
Note the property
targetElement: _Bookingwhich references the association to the booking table that will be shown in the facet Booking. You can lookup the definition of_BookinginZC_FE_TRAVEL_###### Projection View of Travelin the Data Definitions folder. -
In the
Project Exploreropen theData Definitionssection, right-click onZC_FE_BOOKING_###### Projection View for Bookingand create a new metadata extension file from the context menu. EnterZC_FE_BOOKING_######in field Name andMetadata Extension for Booking viewin field Description.Click Buttons Next and Finish.
-
In the metadata extension file
ZC_FE_BOOKING_######use@UI.lineItemannotations to add some fields from the Booking viewZC_FE_BOOKING_###### Projection View for Bookingview to the bookings table. Replace the content ofZC_FE_BOOKING_######by the following code.@Metadata.layer: #CORE annotate view ZC_FE_BOOKING_###### with { @UI.lineItem: [ { position: 10 } ] BookingID; @UI.lineItem: [ { position: 20 } ] BookingDate; @UI.lineItem: [ { position: 30 } ] CustomerID; @UI.lineItem: [ { position: 40 } ] CarrierID; @UI.lineItem: [ { position: 50 } ] ConnectionID; @UI.lineItem: [ { position: 60 } ] FlightDate; @UI.lineItem: [ { position: 70 } ] FlightPrice; }
Click Save and Activate.
-
Change to the app preview and refresh the browser window. The booking table is now displayed in the new Bookings section of the object page.
-
Instead of showing IDs for the fields Customer ID and Airline ID one would preferably show descriptions or names.
This will be made possible by using specific annotations which are implemented within the projection view
ZC_FE_BOOKING_######. Therefore open the projection view located in folderData Definitionswhich contains the root view definitions for the booking entity.Add the
@ObjectModeland@EndUserTextannotations to the fields as shown in the coding fragments below.Annotation
@EndUserText.labeldefines the column label for the related fields. Using annotation@ObjectModel.text.elementcontrols the source of the content shown for the related field. FieldsCarrierIDandCustomerIDwill get their content by accessing the related field through the corresponding association.@EndUserText.label: 'Customer' @ObjectModel.text.element: ['LastName'] CustomerID, _Customer.LastName as LastName,
@EndUserText.label: 'Airline' @ObjectModel.text.element: ['CarrierName'] CarrierID, _Carrier.Name as CarrierName,
Click Save and Activate.
-
Change to the app preview and refresh the browser window. The booking table is now displayed in the new Bookings section of the object page with descriptions for Customer and Airline.
In this step you will add a picture with the airline logo in a new column at the beginning of the booking table.
-
To achieve this, open the metadata extension file
ZC_FE_BOOKING_######and add the following code lines to the end of the annotation structure. The propertypositioncreates a new first column@UI.lineItem: [ { position: 05, label: ' ', value: '_Carrier.AirlinePicURL' } ] _Carrier; }
Click Save and Activate.
-
Change to the app preview and refresh the browser window. The booking table is now displayed with the airline pictures in the first column.
You have completed the exercise! In this unit, you have learned how to create an object page using ABAP CDS annotation.
Week 2 Unit 3: Preparing your front-end development environment







