Set up Delta Real-Time Transformations Script Real-Time Transformations for Data Model Tables
Below is a review of what you just watched in the video. It's an overview of steps to define real-time transformations for Data Model tables—i.e. any table that is part of your Data Model apart from the Activity table. These steps are how you would adapt a Data Job transformation script into a real-time delta transformation script.
The keyword here is Delta. Delta is the reason real-time transformations are different from Data Job transformations. Let’s go through these steps using the table KNA1 from the O2C process.
- Select the Staging Table
A first difference from a normal Data Job transformation is that you apply your transformation only to the Staging Table. If you recall, this where delta records are stored after a delta extraction with the Replication Cockpit. The syntax for your Staging Table is _CELONIS_TMP_{TABLE}_TRANSFORM_DATA → for KNA1 it is _CELONIS_TMP_KNA1_TRANSFORM_DATA
Visually here is the first change to your script.
- Use tables instead of views
Do you recall what views are? They are stored queries executed every time they are accessed. Since we need to add/update/delete records with our delta transformations and views don't store records, these changes are not possible with views. So we need to change views to tables. Here is the change in the script:
Note - this is not happening in your real-time transformations but rather either in your Data Jobs or Replication Cockpit initializations. Tables are not created in your real-time transformations. This will make sense once you read step 3 (DELETE & INSERT).
With this code, you could create the table directly based on an existing view:
CREATE TABLE O2C_KNA1 AS SELECT * from O2C_KNA1
- Change to Delete + Insert Approach
With Data Job transformations, everything is cropped and re-created at each execution. With Delta Transformations we want to incrementally add new records to an existing set. So we insert the new values from the staging table after we delete entries with the same primary key in order to avoid duplicates.
For deletion we replace the DROP TABLE statement with DELETE FROM and WHERE EXISTS statements.
For inserts we replace the CREATE TABLE statement with INSERT INTO.
- Move Temp Tables into queries or use triggered Temp Tables
With Delta Transformations, temporary tables used in multiple different transformations (with different trigger tables) are not possible anymore. Instead, the temporary tables are implemented as a subquery directly into the transformations or you create "triggered temporary tables" that are associated only with you trigger table.
Triggered temporary tables
Here the temporary tables are created before the other real-time transformations are run. They are triggered by the VBAP table's replication (delta extraction).
Subqueries directly in transformation
The results here are generated dynamically during run time, rather than in advance (before the execution of the transformation).
- Select all columns specifically
Metadata changes in the source tables can break the transformations if all columns are referenced (e.g. KNA.*).
To avoid errors as soon as there are metadata changes in your source system, we currently recommend referencing all columns of the Data Model Table (in our case O2C_KNA1) specifically.
These steps may be a bit overwhelming at first. What's important here is for you to understand the reason for these differences and the logic behind real-time transformations. Here is what a final real-time transformation could look like for KNA1:
DELETE FROM O2C_KNA1 WHERE EXISTS (SELECT 1 FROM _CELONIS_TMP_KNA1_TRANSFORM_DATA as NEW_DATA WHERE 1=1 AND O2C_KNA1.MANDT=NEW_DATA.MANDT AND O2C_KNA1.KUNNR=NEW_DATA.KUNNR);
INSERT INTO O2C_KNA1 SELECT "KNA1"."MANDT", "KNA1"."KUNNR", "KNA1"."LAND1", "KNA1"."NAME1", "KNA1"."NAME2", "KNA1"."ORT01", "KNA1"."PSTLZ", "KNA1"."REGIO", "KNA1"."SORTL", "KNA1"."STRAS", "KNA1"."TELF1", "KNA1"."TELFX", "KNA1"."XCPDK", "KNA1"."ADRNR", "KNA1"."MCOD1", "KNA1"."MCOD2", "KNA1"."MCOD3", "KNA1"."ANRED", "KNA1"."AUFSD", "KNA1"."BAHNE", "KNA1"."BAHNS", "KNA1"."BBBNR", "KNA1"."BBSNR", "KNA1"."BEGRU", "KNA1"."BRSCH", "KNA1"."BUBKZ", "KNA1"."DATLT", "KNA1"."ERDAT", "KNA1"."ERNAM", "KNA1"."EXABL", "KNA1"."FAKSD", "KNA1"."FISKN", "KNA1"."KNAZK", "KNA1"."KNRZA", "KNA1"."KONZS", "KNA1"."KTOKD", "KNA1"."KUKLA", "KNA1"."LIFNR", "KNA1"."LIFSD", "KNA1"."LOCCO", "KNA1"."LOEVM", "KNA1"."NAME3", "KNA1"."NAME4", "KNA1"."NIELS", "KNA1"."ORT02", "KNA1"."PFACH", "KNA1"."PSTL2", "KNA1"."COUNC", "KNA1"."CITYC", "KNA1"."RPMKR", "KNA1"."SPERR", "KNA1"."SPRAS", "KNA1"."STCD1", "KNA1"."STCD2", "KNA1"."STKZA", "KNA1"."STKZU", "KNA1"."TELBX", "KNA1"."TELF2", "KNA1"."TELTX", "KNA1"."TELX1", "KNA1"."LZONE", "KNA1"."XZEMP", "KNA1"."VBUND", "KNA1"."STCEG", "KNA1"."DEAR1", "KNA1"."DEAR2", "KNA1"."DEAR3", "KNA1"."DEAR4", KNA1"."DEAR5", "KNA1"."GFORM", "KNA1"."BRAN1", "KNA1"."BRAN2", "KNA1"."BRAN3", "KNA1"."BRAN4", "KNA1"."BRAN5", "KNA1"."EKONT", "KNA1"."UMSAT", "KNA1"."UMJAH", "KNA1"."UWAER", "KNA1"."JMZAH", "KNA1"."JMJAH", "KNA1"."KATR1", "KNA1"."KATR2", "KNA1"."KATR3", "KNA1"."KATR4", "KNA1"."KATR5", "KNA1"."KATR6", "KNA1"."KATR7", "KNA1"."KATR8", "KNA1"."KATR9", "KNA1"."KATR10", "KNA1"."STKZN", "KNA1"."UMSA1", "KNA1"."TXJCD", "KNA1"."PERIV", "KNA1"."ABRVW", "KNA1"."INSPBYDEBI", "KNA1"."INSPATDEBI", "KNA1"."KTOCD", "KNA1"."PFORT", "KNA1"."WERKS", "KNA1"."DTAMS", "KNA1"."DTAWS", "KNA1"."DUEFL", "KNA1"."HZUOR", "KNA1"."SPERZ", "KNA1"."ETIKG", "KNA1"."CIVVE", "KNA1"."MILVE", "KNA1"."KDKG1", "KNA1"."KDKG2", "KNA1"."KDKG3", "KNA1"."KDKG4", "KNA1"."KDKG5", "KNA1"."XKNZA", "KNA1"."FITYP", "KNA1"."STCDT", "KNA1"."STCD3", "KNA1"."STCD4", "KNA1"."XICMS", "KNA1"."XXIPI", "KNA1"."XSUBT", "KNA1"."CFOPC", "KNA1"."TXLW1", "KNA1"."TXLW2", "KNA1"."CCC01", "KNA1"."CCC02", "KNA1"."CCC03", "KNA1"."CCC04", "KNA1"."CASSD", "KNA1"."KNURL", "KNA1"."J_1KFREPRE", "KNA1"."J_1KFTBUS", "KNA1"."J_1KFTIND", "KNA1"."CONFS", "KNA1"."UPDAT", "KNA1"."UPTIM", "KNA1"."NODEL", "KNA1"."DEAR6", "KNA1"."/VSO/R_PALHGT", "KNA1"."/VSO/R_PAL_UL", "KNA1"."/VSO/R_PK_MAT", "KNA1"."/VSO/R_MATPAL", "KNA1"."/VSO/R_I_NO_LYR", "KNA1"."/VSO/R_ONE_MAT", "KNA1"."/VSO/R_ONE_SORT", "KNA1"."/VSO/R_ULD_SIDE", "KNA1"."/VSO/R_LOAD_PREF", "KNA1"."/VSO/R_DPOINT", "KNA1"."ALC", "KNA1"."PMT_OFFICE", "KNA1"."PSOFG", "KNA1"."PSOIS", "KNA1"."PSON1", "KNA1"."PSON2", "KNA1"."PSON3", "KNA1"."PSOVN", "KNA1"."PSOTL", "KNA1"."PSOHS", "KNA1"."PSOST", "KNA1"."PSOO1", "KNA1"."PSOO2", "KNA1"."PSOO3", "KNA1"."PSOO4", "KNA1"."PSOO5", "KNA1"."ZZVPOPNE", "KNA1"."ZZKFZTYPMIN", "KNA1"."ZZKFZTYPMAX", "KNA1"."ZZHAENGERKZ", "KNA1"."ZZTOBACCOCUST", "KNA1"."ZZTOBCUSTDAT", "KNA1"."ZZF_TYPE", "KNA1"."ZZTOBSERVICE", CAST("KNA1"."ERDAT" AS DATE) AS "TS_ERDAT", CAST("KNA1"."UPDAT" AS DATE) AS "TS_UPDAT" FROM "_CELONIS_TMP_KNA1_TRANSFORM_DATA" AS "KNA1" WHERE EXISTS( SELECT 1 FROM VBAK WHERE 1=1 AND "VBAK"."MANDT" = "KNA1"."MANDT" AND "VBAK"."KUNNR" = "KNA1"."KUNNR" AND "VBAK"."VBTYP" = '<%=orderDocSalesOrders%>' );