Skip to end of metadata
Go to start of metadata

Analytic (Query) Annotations

In this page we want to provide simple examples for the most important annotations used by the Analytic Engine. S ee also Embedded Reporting on ABAP CDS views for more information to the CDS Views used in BW. Please note that also some non-analytics annotations are used by the OLAP Engine as you can see below.

Two important analytic annotations:

  • CDS views with the annotation @Analytics.query: true are transient queries which can be interpreted by the Analytic Engine.
  • CDS views with the analytic annotation @Analytics.dataCategory:#CUBE are transient BW providers.

BW InfoProvider: @Analytic.dataCatgegory: #CUBE

The analytic annotation Analytics.dataCategory can be used to create an BW provider by using the value #CUBE, see Simple BW Provider based on CDS View.

Data Extraction

@Analytics.dataExtraction.enabled: If set to true, the view(CUBE) suitable for data replication. This is the default setting. See also Delta enabled extraction from CDS views .

(Component for @Analytics.dataExtraction:  BC-BW-ODP)

Aggregation

@Aggregation.default or @DefaultAggregation: When the DefaultAggregation annotation has been specified for an element, the corresponding elements are used as so called measures (elements that can be aggregated) in analytical scenarios. See Simple BW Provider based on CDS View.

Example

Currency Key Figures
  • @Semantics.currencyCode This annotation tags a field containing a currency code
  • @Semantics.amount.currencyCode The annotated field contains a monetary amount, and the corresponding currency code is contained in the referenced field.

See Simple BW Provider based on CDS View. key figure FlightPrice(text:Airfare).

Quantity Key Figures
Association to DIMENSION(BW Infoobject)

@ObjectModel.foreignKey.association: see CUBE with association to DIMENSION.

See also BW InfoObjects modeled by CDS Views and CDS cube views.

Access Control/Authorization Check

It is possible to restrict the access to certain values of fields/Infoobjects by using CDS access controls  which are based on CDS roles. The annotation @AccessControl.authorizationCheck: #CHECK  can be used for data category CUBE and DIMENSION( a query ignores such a annotation).  See CDS Access Controls for further details.

Important Consulting Notes

2835242 More Values in Cube CDS View than in Dimension View

BW InfoObject: @Analytic.dataCatgegory: #DIMENSION

Corresponds to a BW InfoObject: see CUBE with association to DIMENSION.

More info: IOBJ in CDS

BW Hierarchy: @ObjectModel.dataCategory: #HIERARCHY

Corresponds to a BW Presentation Hierarchy

Hierarchy is defined on infoprovider CDS, however they are only interpreted by the Analytic Engine when it is used in a CDS query with @AnalyticsDetails.query.

See: Using Hierarchies in CDS

BW Query: @Analytics.query: true

In order to specify which views will be exposed to the analytic engine, the following annotation is used:

@Analytics.query: true.

The query views are built on top of views classified as #CUBE or #DIMENSION (master data reporting). They inherit the dimensions, measures and the hierarchies from the reuse view.

Variables

Filter variables of the BW query can be expressed with @Consumption.filter annotations in CDS. As an alternative to the filter annotation, you can introduce a parameter and use it in the where clause. See below.

Variables and Filters are always so called hard filters  (characteristic restrictions, see OLAP Filter Handling).

Example

Note:

  1. Text variables are not supported yet. @EndUserText.label only uses static text.
  2. With @Consumption.filter:{selectionType: #RANGE or #INTERVAL, multipleSelections:true}, a selection option variable is generated. With this, exclude or contain patterns are possible. (see Example)
  3. Variable derivation troubleshooting, see KBA  2588590 Error 'Variable xxx could not be replaced' in a CDS Query (BRAIN 641)
  4. Variables from different CDS queries can be merged if:
    1. Both variables belong to the same fieldname in the CDS queries
    2. Both fields are generated InfoObjects that have the same CHABASNM ( for example, have the same foreign key association in the cube views)
    3. Both variables are of same type (Characteristic value, hierarchy, text, formula, …)
    4. Both variables have the same selection type (single, interval, selop, …)
Filters/Variables by using Parameters

As an alternative to the filter annotation, you can introduce a parameter and use it in the where clause. In that case only single values are supported. The variable is mandatory.

Example

Note:

  • In case a @Filter annotation is used for an element that is filtered in the WHERE condition as well, the filter annotation will be ignored! See Example (at the very bottum)
  • Parameter variable can only be single value variable, wildcard function is not supported. Wildcard function is only supported in contain patterns in a selection option variable.
    For a single value variable without master data, value 'A*' is treated as literally value 'A*'.
    For a single value variable with master data, if value 'A*' is not in master data, variable check will raise invalid value error (BRAIN_DEV 643)
Sort by Characteristic

If no additional annotation is used, the characteristic values are sorted as defined in filters.

Use annotation: @AnalyticsDetails.query.sortDirection  with #ASC, #DESC

Example

Decimal Places

Use annotation: @AnalyticsDetails.query.decimals

Calculated Elements

the annotation @AnalyticsDetails.query.formula  will only be interpreted by the BW query BADI. It contains an expression representing a numerical value. This expression can contain the following

  • cube measures and/or other numeric elements of the select list
  • arithmetic expressions using operators + - * /
  • functions NDIV0, NODIM, SQRT, SUMGT, SUMCT and SUMRT, which represent the corresponding BW formula functions
  • CASE expressions with at most a single THEN clause (will be translated into BW IF operator)
  • WHEN clause can contain conditional or boolean expressions of measures and/or other numeric elements of the select list
  • ELSE clause is optional (defaulted to ELSE 0 )

Examples

Simple CDS View Query with formulas and restrictions  

Restricted Measures

The filters for restricted measures will be modeled via the standard SQL case statement.

So far a restricted measure filtered by a hierarchy node in case statement is not supported yet.

Example

Hidden Key Figures

In order to hide measures initially but allow a user to unhide it - annotation @AnalyticsDetails.query.hidden can be used. In order to hide e.g. intermediate calculated fields permanently, the domain specific annotation @Consumption.hidden can be used.

Currency Conversion

Curreny conversion can be defined by using a CDS currency_conversion function expression in a select list entry. See the following examples and SAP Online Help: ABAP CDS - Conversion Functions for Units and Currencies

CUBE: Example

Query: Example

Multidimensional Layout

Attributes and measures can be put on several axes. For this the following annotation can be used: 

  • @AnalyticsDetails.query.axis: #ROWS
  • @AnalyticsDetails.query.axis: #COLUMNS
  • @AnalyticsDetails.query.axis: #FREE (default)

The default value is the free axis. Measures all need to be on the same axis. The default for the measures is to place them on the columns. If the measures should be put on the rows they all need to be annotated to be placed on the rows:

Example

Zero Suppression

Use annotation: @Analytics.settings.zeroValues

Example

Formula Variables

Numeric view parameters can be used as BW formula variables, see Example.

Value Help(F4)
  1. There is no annotation to control the F4 mode(see F4 Modes) of a variable in a CDS view.
  2. In query result(SF - see F4 Modes), Q and  M mode are supported. The mode can be set in front end and annotation @AnalyticsDetails.resultValuesSource, see below. If there is no setting specified, Q mode is used by default.
  3. When a dimension view is defined as DCL-0 (with annotation @AccessControl.authorizationCheck: #PRIVILEGED_ONLY), F4 help for field based on this characteristic will get empty value list since the values are protected from end users. 
    In this case, use annotation @Consumption.valueHelpDefinition to define a Value Help CDS view which contains fields that allows to see for this dimension view. 
    Example
  4. Regarding the display of the inital value(#) in the F4 help review note 2584290.
Value Help(F4) for Variables

Values of F4 help of a variable are retrieved from the corresponding Dimension:

Example

BW F4 D mode(see F4 Modes) is not possible. Only M mode supported.

Value Help(F4) for Parameters

Values of F4 help of a variable are retrieved from the corresponding Dimension:

Example

BW F4 D mode(see F4 Modes) is not possible. Only M mode supported.

Value Help in Query Result(see SF in F4 Modes) and displaying Unposted Values(see Access Type for Result Values) in Result Set

Annotation @AnalyticsDetails.resultValuesSource controls the list of values which should be taken into account for a specific characteristic: it is used in the value help at query runtime and for displaying the values in the query result. Following values exist:

#CUBE (default): corresponds to Query-mode for value help and shows only posted values in query result
#DIMENSION: corresponds to Masterdata-mode for value help and all master data(also unposted values) are shown in the query result(see Access Type for Result Values)

Example

Define and Translate Texts for Fields

Define your own label for a characteristic or variable by using annotation EnduserText.label

Example

Technical Names of CDS Fields in BW

CDS: Technical Names and Descritions of Fields

Display Attributes and Texts

Display Attributes and texts can be added by using associations of the cube in the projection list. Elements (keys) and their label elements (texts) are combined by the engine into one field. Whether the analytic engine shows key/text or text/key depends on the order in the projection list

Display Attributes: see CUBE with association to DIMENSION.

Texts: see Text in CDS and Cube with association to DIMENSION and TEXT 

Exception Aggregation

For calculated elements (not for Restricted Measures) exception aggregation can be defined for CDS queries using the annotaions

  • @AnalyticsDetails: {
  • exceptionAggregationSteps.exceptionAggregationBehavior: #Aggregation,
  • exceptionAggregationSteps.exceptionAggregationElements: ['FieldName']
  • }

The default aggregation behavior cannot be defined in the query. It needs to be defined on the cube layer. Therefore, usage of @DefaultAggregation is restricted to the values #FORMULA for formulas and #NONE for other select list entries.

Example

See also "Data Aging and Hana Pushdown" below.

Hierarchies

With the annotation @AnalyticsDetails.query.displayHierarchy you can specify a display hierarchy for an element. This annotation is an enumeration with the following values:

  • #OFF: No display hierarchy
  • #ON: With display hierarchy

Which hierarchy is taken is defined by @AnalyticsDetails.query.hierarchyBinding. If only one hierarchy exists, the hierarchy binding can be omitted.

A CDS hierarchy can be defined using the annotaion @ObjectModel.dataCategory: #HIERARCHY

See Using Hierarchy in CDS for details.

Structures with Hierarchical Display

With the annotation @AnalyticsDetails.query.elementHierarchy you can maintain hierarchical relationships for structural components in a structure

OData Service / ODataQuery

Using the annotation "@OData.publish: true" generates an OData Service when activating the CDS view. See BW OData Queries . 

OLAP Effort

With the annotation @Analytics.settings.maxProcessingEffort you can change the query property 'OLAP Effort', see note 2572550 for further details. Note that the default setting for CDS queries is High(so when the Annotation isn't used at all in the CDS query, the system takes the value High).

Data Aging and Hana Pushdown

as explained in BWonHANA: Analytical Engine, there are some OLAP features like a Exception Aggregation which can be processed on the Hana database(called 'pushdown') in order to improve the performance. In case of CDS queries, such a pushdown is supported as of the releases BW753 and BW/4Hana 2. Due to the default setting(trexops=9) in these releases, a pushdown is carried out if possible for CDS queries. There is no annotation which can be used to specify the trexops mode, however, if necessary(e.g. as a workaround when issues occur during the pushdown) the setting can be changed locally in RSRT(see trexops).

Note that when the annotation @DataAging.noAgingRestriction is set to 'true' (current and historical data is read), a pushdown isn't supported. See Data Aging and notes 2869647, 2657021 for further details.

Run CDS Query in AO and SAC

With the annotation @Analytics.query: true,  the CDS query 2C<sqlview name> can directly be executed in transaction RSRT (after CDS view activation). However, to run it in frontends like AO (what also means that it is available in AO query value help / search for a query),  it needs to be C1-released. In order to check this, you need to open the CDS view with the Hana  Studion(ABAP Development Tool) and check the Properties of the view:

You can use ther Change button to set the state to Released:

If 'API State' is not available, please apply latest ABAP Development tool by https://tools.hana.ondemand.com/#abap. See also note 2745500.

So far, there is no tool to massive release API State to 'C1 Released' yet.

Notes:

  • 2785573 CDS-based BW queries are not found by input help 
  • 2788839 CDS-based BW queries are not found by input help
  • 2810278 CDS-Based Queries: REPDIR Utilities
Extend a CDS Query View

A CDS view can be extended by an extend view to add additional query elements. Please note, an extend view itself can't generate a query by itself. Therefore it is not supported to run a query of 2C<extend_view_sqlview_name>. Please always run the query generated from the original query view. (Note 2950780)

Example:

Extend view for CDS query

'Classic' BW Queries based on CDS Cubes

It is possible to create BW queries on top of CDS Cubes with the help of the BW Modeling Tools(Hana Studio). This might be necessary if OLAP features are required which are not supported for Analytic CDS queries.

Example I: BW Query based on CDS Cube with Parameter

SAP Online Documentation

 



  • No labels

2 Comments

  1. Thank you so much for keeping all examples together at one place. CDS code syntax used in these examples are screen shots, is there a possibility of having the code which can be copy and use it in another place. 

    1. Hi Sreekanth,
      thank you for the feedback. Yes, that is a good idea. At least when the examples are based e.g. on table SFLIGHT it makes sense to offer the possibility of copying the code. I will try to do this at least for the upcoming examples.
      best regards
      Peter