ERPClimb logoERPClimb

Code examples · Business Data Cloud · Advanced

Prepare S/4HANA data for a data product: a CDS view enabled for extraction with delta

The problem

A custom order table in S/4HANA must feed the analytics platform every day.

How we solve it

  1. 1Custom tableZORD_HDR
  2. 2CDS viewextraction enabled

The result

An activated view that the extraction tooling can list as a source with full and delta loading.

Overview drawn by ERPClimb from this example. The steps are the same as in the code below.

1. The requirement

A custom order table in S/4HANA must feed the analytics platform every day. Reloading the full table is too slow, so the platform should receive only new and changed rows.

2. How we design it

Data platforms such as SAP Datasphere read S/4HANA data through CDS views that are enabled for extraction. A view is enabled with an annotation, and delta handling is added either by a timestamp field or by change data capture. We use change data capture because it tracks changes by database trigger on the underlying table.

Why we decided it this way

  1. 1A dedicated extraction viewKeep extraction separate from user-facing views so that a change for the UI cannot break the load.
  2. 2Change data capture, not a timestampCDC records changes at the table, so it does not depend on every program filling a last-changed field. You can use either generic delta or CDC in one view, not both.
  3. 3Fact categoryOrder rows are transactions, so the data category is FACT.

Before you start

  • Nothing to prepare: step 1 creates the small demo table ZORD_HDR. Skip it if you already have your own table.
  • ADT and a package such as $TMP.
  • Confirm in the documentation of your release that the extraction annotations are allowed in your development environment.

3. The code, step by step

Step 1 of 2: Create the demo table

A small transparent table to extract from.

CDS · Database table · ZORD_HDR
// Table definition
@EndUserText.label : 'Orders for extraction demo'
@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE
@AbapCatalog.tableCategory : #TRANSPARENT
@AbapCatalog.deliveryClass : #A
@AbapCatalog.dataMaintenance : #RESTRICTED
define table zord_hdr {
  key client    : abap.clnt not null;
  key order_id  : abap.char(10) not null;
  customer_id   : abap.char(10);
  status        : abap.char(1);
  @Semantics.amount.currencyCode : 'zord_hdr.currency'
  net_value     : abap.curr(15,2);
  currency      : abap.cuky;
}
Part by part (plain text)
  1. Table definition. A transparent table with a client field, the order id as key, a status and an amount with its currency. The amount annotation links the amount to the currency field, which the view in the next step relies on.

Open in the portal

The SAP objects named in this code are linked in the code above and listed here. Each opens its page in the SAP Library.

4. The final outcome

An activated view that the extraction tooling can list as a source with full and delta loading.

What you should see

Example: view ZI_OrderExtract is active. In the extraction tool it appears as a source with delta capability.

Try it and check the result

  • Activate the view. Fix annotation errors first: they usually mean the annotation is not allowed in your environment.
  • Check that the view is listed as an extraction source in your platform tool (for example a replication flow in SAP Datasphere).
  • Change one row in ZORD_HDR and confirm that only that row arrives in the next delta load.

Common mistakes

  • Use either generic timestamp delta or CDC in one view, never both.
  • Do not enable extraction on arbitrary standard views. Use views SAP has released for extraction, or your own view on your own table.
  • A view with the analytical query annotation cannot be extracted.
  • CDC has prerequisites that joins and complex logic may not meet. Keep the extraction view simple and check SAP's CDC rules before you extend it.

Keep learning