Working with Dimension and Text Views

Objectives

After completing this lesson, you will be able to:
  • Identify the main elements of a dimension view
  • Identify the main elements of a text view

Dimension View

Let's cover the most important aspects of the dimension view.

A dimension view needs the header annotation @Analytics.dataCategory: #DIMENSION to define the view as a dimension.

The annotation @ObjectModel.representativeKey is needed. This annotation must point to the key field which represents the dimension. For example, the dimension for City has the two key fields Country and City. The representative key field is City.

All key fields which are not the representative key field usually have a foreign key association or a text association. All non-key fields in a dimension become attributes in the analytical model.

The annotation @Aggregation.default is not required in a dimension view unless you want to create a query on top of a dimension.

Note

Refer to the lesson Working with Cube Views for more information on handling fields that might be considered as measures and dimensions.

If a text view is available, you should define a text association to the text view and add @ObjectModel.text.assocation referring this association to the representative key field. The ON condition of the association must include all key fields and the text view must have the same key fields.

If a text view doesn't exist but there is a text field already in the dimension view, you can add the annotation @Semantics.text: true to the text field and @ObjectModel.text.element to the representative key field.

If a hierarchy view exists, you should define an association to the hierarchy view and add the annotation @ObjectModel.association.toHierarchy: true to the association. If the hierarchy view is old style (defined via annotation @Hierarchy), you have to add the annotation @ObjectModel.hierarchy.association to the representative key field.

If the attributes are time-dependent, the dimension view needs additional date fields of type DATS or DATN. One of the date fields requires the annotation @Semantics.businessDate.to and it must be a key field. The other date field requires the annotation @Semantics.businessDate.from. The key field which is assigned the annotation @Semantics.businessDate.to must not be included in the ON condition of any foreign key association and it must not have a foreign key association

Here is the data preview of a dimension view for airports:

The data preview of a dimension view that provides the query with the attributes for each airport

Here is the code that defines this dimension:

Code Snippet
12345678910111213141516171819202122232425262728293031323334
@AccessControl.authorizationCheck: #NOT_REQUIRED @EndUserText.label: 'Airport' @Analytics.dataCategory: #DIMENSION @ObjectModel.representativeKey: 'AirportID' @ObjectModel: { supportedCapabilities: [ #ANALYTICAL_DIMENSION ], modelingPattern: #ANALYTICAL_DIMENSION } define view entity /DMO/ANA_I_Airport as select from /dmo/airport association [0..1] to I_Country as _Country on _Country.Country = $projection.Country association [0..1] to /DMO/ANA_I_City as _City on _City.country = $projection.Country and _City.city = $projection.City { @ObjectModel.text.element: ['Name'] key airport_id as AirportID, @Semantics.text: true name as Name, @ObjectModel.foreignKey.association: '_Country' country as Country, @ObjectModel.foreignKey.association: '_City' city as City, /* Associations */ _Country, _City }

Notice the associations for the dimension attributes country and city. These associations point to further dimension views to provide even more details for these two attributes. Defining associations in this way is how we develop a snowflake model.

Text View

Let's work through some of the key elements of a text view.

A text views needs the header annotation @ObjectModel.dataCategory: #TEXT and just as with dimension views, they also need the annotation @ObjectModel.representativeKey.

All key fields which are not the representative key field and not the language field require a foreign key association or a text association.

The field that provides the language of the text, must be a key field and it needs the annotation @Semantics.language: true.

All text fields must have the annotation @Semantics.text: true.

The representative key fields need the annotation @ObjectModel.text.element. The first element in this array becomes the default text in the analytical model. Up to three texts are supported by the analytical model:

  • short text (up to 20 characters)
  • medium text (up to 40 characters)
  • long text (more than 40 characters)

If text is time-dependent, then a field that provides the date to and also field with date from is needed. The time dependency can be handled independently of the dimension view.

Here is the output of the text view:

data preview of a text view that displays the name of each country in various languages

Here is the code to define this text view:

Code Snippet
123456789101112131415161718192021222324252627
@AbapCatalog.sqlViewName: 'IFICOUNTRYTEXT' @AccessControl.authorizationCheck: #NOT_REQUIRED @EndUserText.label: 'Country/Region - Text' @ObjectModel.dataCategory: #TEXT @ObjectModel.representativeKey: 'Country' @ObjectModel.supportedCapabilities: [#SQL_DATA_SOURCE, #CDS_MODELING_DATA_SOURCE, #CDS_MODELING_ASSOCIATION_TARGET, #LANGUAGE_DEPENDENT_TEXT] define view I_CountryText as select from t005t association [0..1] to I_Language as _Language on $projection.Language = _Language.Language association [0..1] to I_Country as _Country on $projection.Country = _Country.Country { @ObjectModel.foreignKey.association: '_Country' key land1 as Country, @ObjectModel.foreignKey.association: '_Language' @Semantics.language key spras as Language, @Semantics.text: true landx50 as CountryName, _Country, _Language }

This view defines three fields: country, language and country name.

Note

This view has been simplified to focus on the most important settings for a text view. It does not align to the standard SAP version of this particular text view, which includes additional settings that are not important here.

Log in to track your progress & complete quizzes