Core Data Services (CDS) ABAP

Embedded Analytics

Embedded Analytics with CDS – Overview

The CDS InfoProvider views form a modeling layer that serves as the foundation for Embedded Analytics in S/4HANA using CDS Queries.
However, CDS InfoProviders can also be used directly as sources for queries in the Query Builder of the SAP BW Modeling Tools.

Visualization of how InfoProviders are structured

The Name of the CDS InfoProvider & Queries

Name of the Database View

To obtain the name of an InfoProvider or Query, we always need the name of the associated database view.

  • DDIC-based CDS View: The annotation @AbapCatalog.sqlViewName
  • CDS View Entities: The view name itself

Prefix 2C

To distinguish CDS-based InfoProviders and Queries from classic BW objects, SAP uses the prefix 2C.

The InfoProvider for the CDS View Entity ZI_DEMO_CUBE is called 2CZI_DEMO_CUBE.
The Query for the DDIC-based CDS View ZI_DEMO_QUERY is named after its SQL View ZVDEMOQUERY, resulting in 2CZVDEMOQUERY.

Use of the 2C Names

Relevant wherever an InfoProvider or Query name is required, including:

Metadata of the CDS InfoProvider

Transaction RSRTS_ODP_DIS
Using the 2C name.

Representation of an InfoProvider in transaction RSRTS_ODP_DIS

Ad-Hoc Queries on CDS InfoProviders

In Analysis for Office: If no query exists yet, search for the InfoProvider.

In the SAP Query Monitor (RSRT) you can query a CDS InfoProvider directly like any BW InfoProvider.
Enter in the Query field:
<InfoProvider>/!<InfoProvider>

Example: 2CZI_DEMO_CUBE/!2CZI_DEMO_CUBE

Structure of a CDS InfoProvider

Structure of CDS InfoProviders

CDS Cube Views

  • InfoProviders for measures – aggregation behavior matters for numeric values
  • Dimensions are modeled as associations
  • Used as sources for queries

CDS Cube Views – Annotations

On View Level

@Analytics.dataCategory: #CUBE

Associations to Dimensions

For characteristics with their own dimension, the annotation:
@ObjectModel.foreignKey.association: '<AssociationName>'
is required.

On Field Level

  • @DefaultAggregation: #SUM // #MIN, #MAX, ...
  • @Semantics.quantity.unitOfMeasure: '<unit field>'
  • @Semantics.amount.currencyCode: '<currency field>'
  • @EndUserText.label: '<field description>'

Example I_SalesAnalyticsCube from the VDM

define view I_SalesAnalyticsCube
...
association [0..1] to   I_Customer  as _Customer  
        on  $projection.Customer = _Customer.Customer
...
{
//key
  key SalesDocument,
  key SalesDocumentItem, 

//Dimensions
  @ObjectModel.foreignKey.association: '_SoldToParty'
  SoldToParty,      

//Measures
  @DefaultAggregation: #SUM
  @Semantics.quantity.unitOfMeasure: 'BaseUnit'
  OpnSlsOrdsForOrdReltdInvcsQty,

CDS Dimension Views

  • Contain the attributes of a dimension
  • May be time-dependent
  • Numeric fields are not aggregated

CDS Dimension Views – Annotations

On View Level

@Analytics.dataCategory: #DIMENSION

Time Dependency

@Semantics.businessDate.from – Date-from field if time-dependent
@Semantics.businessDate.to – Date-to field

Texts for a Field

@ObjectModel.text.element: ['<text field>'] – On key field
@Semantics.text: true – On text field

Or via association:
@ObjectModel.text.association: '<AssociationName>'

CDS Dimension Views – Additional Annotations

Additional Semantic Annotations

@Semantics
e.g., units, dates, addresses, etc.

CDS Dimension View – Example

@AbapCatalog.sqlViewName: 'SQL_VIEW_NAME'
@EndUserText.label: 'Material'

@Analytics.dataCategory: #DIMENSION
define view zjb_material_dim
  as select from /bi0/pmaterial as dim 

  association [0..*] to zjb_material_txt as _MaterialText
           on dim.material = _material_text.material
{
  @ObjectModel.text.association: '_MaterialText'
  key material,  
      changed,      
  @Semantics.systemDate.createdAt: true
      createdon,
      division,
      eanupc,
      ind_sector,
      matl_cat,
      matl_group,
      ...
}

CDS Text Views

  • Texts for attributes
  • May be time- and language-dependent
  • Are not InfoProviders – but can be associated to them
  • Data category defined via @ObjectModel instead of @Analytics

CDS Text Views – Annotations

On View Level

@ObjectModel.dataCategory: #TEXT

On Field Level

@ObjectModel.text.element: [ 'Text' ]
@Semantics.text: true – Text field
@Semantics.language: true – Language field (optional)
@Semantics.businessDate.from – Date-from field
@Semantics.businessDate.to – Date-to field

CDS Text View

@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Product Text'
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType:{  serviceQuality: #X,
                          sizeCategory: #S,
                          dataClass: #MIXED }

@ObjectModel.dataCategory: #TEXT

define view entity zcdse_txt_product 
as select from snwd_pd as pd
inner join snwd_texts as tx
on pd.name_guid = tx.parent_key
{
    @ObjectModel.text.element: [ 'text' ]
    key pd.node_key as ProductNodeKey,

    @Semantics.language: true
    key tx.language as Language,

    @Semantics.text: true
    tx.text
}

CDS Queries

  • A CDS Query inherits semantic properties from its InfoProvider
  • It defines the layout and initial drilldown of the data

define transient view entity <query name> provider contract analytical_query as projection on <cube name>

CDS Queries – View-Level Annotations

@Analytics.query: true

@Analytics.settings.zeroValues: { handling:   #HIDE_IF_ALL, // #HIDE, #SHOW
                                  hideOnAxis: #ROWS_COLUMNS // #COLUMNS, #ROWS
}

define transient view entity <query name> 
  provider contract analytical_query 
    as projection on <cube name>
{ 
  ...
}

CDS Queries – Filter Parameter Annotations

Alternative to input parameters.

  @EndUserText.label: 'Product'
  @Consumption.filter:{ selectionType:      #RANGE,       // #INTERVAL, #SINGLE, #HIERARCHY_NODE
                        multipleSelections: false,
                        mandatory:          true,
                        hidden:             false,
                        defaultValue:       '0000000000011675'  }

  @AnalyticsDetails.query:{ hidden: false,                           
                            display: #KEY_TEXT }  
  Product

CDS Queries – Annotations for Characteristics

  @UI.textArrangement: #TEXT_ONLY  
  @AnalyticsDetails.query:{ //display:       #KEY,    //#KEY_TEXT, #TEXT
                            axis:          #ROWS,   //#COLUMNS
                            totals:        #HIDE,   //#SHOW
                            hidden:        false,
                            sortDirection: #ASC     //#DESC
  }
  calday

CDS Queries – Annotations for Key Figures

@AnalyticsDetails.query:{ axis:     #COLUMNS,
                          decimals: 2,
                          scaling:  0,
                          hidden:   false
}
 quant_b,

  @EndUserText.label: 'Profit'
  @AnalyticsDetails.query:{ formula: '(price_vk - price_vek) * nodim(quant_b)' }
  1 as profit, 

  @EndUserText.label: 'Different Materials'
  @AnalyticsDetails.exceptionAggregationSteps:
              [{ exceptionAggregationBehavior: #COUNT,
                 exceptionAggregationElements: ['material'] }]
  1 as materialCount