Core Data Services (CDS) ABAP

CDS Extractors

Creating an Extractor View

Create a CDS view with the annotation
@Analytics.dataExtraction.enabled: true

And specify the data category:
@Analytics.dataCategory: #CUBE
@ObjectModel.dataCategory: #TEXT

@AbapCatalog.sqlViewName: 'ZSQL_EXTRACTOR'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@Analytics.dataCategory: #CUBE
@Analytics.dataExtraction.enabled : true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Extractor for SO Data'
define view zcds_extractor as
  select from snwd_so as so

  left outer join snwd_so_i as soi
  on so.node_key = soi.parent_key

  left outer join snwd_pd as pd
  on soi.product_guid = pd.node_key 
{
      so.so_id,
      so.created_at,
      ...
}

Setting the API Status

Set API status to C1 (not always necessary)

API state setting in SAP

Restrictions via authorization

Consuming Extractors from BW

Connect source system as ODP

Type ABAP_CDS

Connecting the source system as ODP

Create DataSource

Replication is not required.
The name of the extractor corresponds to the SQL view name of the CDS view or the CDS View Entity name.

Creating a DataSource

Selecting the CDS view

Delta Methods

Using Timestamp

  • Application data contains a timestamp of the last change
  • Alternatively: last change date

Change Data Capture

  • Available from SAP S/4HANA Cloud 1905 and S/4HANA 1909 FPS01
  • Based on DB triggers similar to SLT

Delta with Timestamp or Date

If an appropriate timestamp/date exists in the data, annotate on view level:
@Analytics.dataExtraction.delta.byElement.name: <fieldname>

And annotate the field:
@Semantics.systemDateTime.lastChangedAt: true
or
@Semantics.systemDate.lastChangedAt: true

Safety Interval for Delta

Default safety interval is 30 minutes.
Can be changed with:

@Analytics.dataExtraction.delta.byElement.maxDelayInSeconds: 3600

Keys and hash values of extracted data are stored.
If a record appears twice due to the overlap, it is removed.

Safety interval diagram

Delta with Deletion Detection

To extract deletions:

@Analytics.dataExtraction.delta.byElement.detectDeletions: true

However, this requires comparing full datasets and can be slow.
Limit deletion search with:

@Analytics.dataExtraction.delta.byElement.ignoreDeletionAfterDays: 30

Delta Without Own Timestamp

If no timestamp exists in application data, additional tables can be joined, e.g.
CDHDR and CDPOS can be used as delta basis.

Exercise – Delta Method using CDPOS and CDHDR

Create an extractor for address data (table ADRP) that returns only changes since last load.

Every time address data changes (e.g. via SU01), a change document is written to CDHDR/CDPOS.

CDHDR, CDPOS, ADRP Data

CDHDR

MANDANT OBJECTCLAS OBJECTID CHANGENR USERNAME UDATE UTIME TCODE
100 ADRESSE3 ... 151598 DEVELOPER 20210301 152830 SU01

CDPOS

MANDANT OBJECTCLAS OBJECTID CHANGENR TABNAME TABKEY FNAME VALUE_NEW VALUE_OLD
100 ADRESSE3 ... 151913 ADRP ... TITLE 2

ADRP

CLIENT PERSNUMBER DATE_FROM NAME_FIRST NAME_LAST
100 11405 00010101 Jörg Brandeis

Delta via CDPOS/CDHDR – Solution

@AbapCatalog.sqlViewName: 'ZSQL_EXT_CDPOS'
...
@Analytics.dataCategory: #FACT
@Analytics.dataExtraction: { enabled: true,
                             delta: { byElement.name: 'TSTMP' } }

define view zcds_extractor_cdpos
  as select distinct from cdpos as pos

    inner join cdhdr as hdr 
         on pos.objectclas = hdr.objectclas
        and pos.objectid   = hdr.objectid
        and pos.changenr   = hdr.changenr

    inner join adrp as ad  
         on ad.persnumber = substring(pos.tabkey, 4, 10)
        and ad.date_from  = substring(pos.tabkey, 14, 8)
{
  key ad.persnumber as Persnumber,
  key ad.date_from  as DateFrom,

  @Semantics.systemDateTime.lastChangedAt: true
  dats_tims_to_tstmp(hdr.udate, hdr.utime, 'UTC', $session.client, 'NULL') as Tstmp,

  ad.nation as Nation,
  ad.date_to as DateTo,
  ...
}

CDS Extractors – Delta with Change Data Capture (CDC)

Available from SAP S/4HANA Cloud 1905 and S/4HANA 1909 FPS01.

Concept

DB-level changes (INSERT/UPDATE/DELETE) are captured via triggers and written to ODQ.

Required Annotation

@Analytics.dataExtraction.enabled: true

For 1:1 projections without JOINs:

@Analytics.dataExtraction.delta.changeDataCapture.automatic: true

CDC Mapping for JOINs in CDS

For JOINs, mapping rules must be defined:

@Analytics.dataExtraction: { enabled: true,
  delta.changeDataCapture.mapping: [
    { table: 'ZBC_TASKS', role: #MAIN,
      tableElement: ['TASK_KEY'], viewElement: ['TaskKey'] },
    { table: 'ZBC_USERS', role: #LEFT_OUTER_TO_ONE_JOIN,
      tableElement: ['USER_ID'], viewElement: ['Assignee'] }
  ]
}

View element order must match DB key element order.

CDC Details

Database Trigger

Triggers are created when:

  • CDS annotations exist
  • DataSource exists
  • A delta DTP is executed for the first time

They can be viewed in the HANA Catalog.

Master Logging Table (ML)

Name begins with /1DH/ML...
One ML table per DB table in CDC context.

Observer Job

Job /1DH/OBSERVE_LOGTAB (DHCDCR_OBSERVE_LOGTAB) runs continuously.
It checks ML tables and processes entries, then waits 1 second.

Subscriber Logging Table (SL)

Same fields as ML, but same key as DB table.
Name begins with /1DH/SL....

Transfer Job

Job /1DH/PUSH_CDS_DELTA (Report DHCDCR_PUSH_CDS_DELTA):

  • Reads delta data using mapped keys
  • Writes to ODQ
  • Deletes processed SL records

CDC Transactions (1/2)

ODQMON – Monitor Delta Queues

  • List of queues
  • Subscribers
  • DTP requests with timestamps

DHCDCMON – CDC Monitoring

  • Registered CDC objects
  • ML/SL table names
  • Job settings
  • Links to logs and statistics

CDC Transactions (2/2)

RODPS_REPL_TEST – Extract Test Data

  • Test ODP extraction including CDC
  • Has its own subscriber and delta pointer