# Cortex Framework v6 compatibility

The v6 compatibility layer provides schema-compatible views and tables for
Google Cloud Cortex Framework v6 SAP workloads inside the
Cortex Framework v7 architecture. Deploying
`cortex_v6_compatibility` lets you adopt the v7 build and orchestration
framework without rewriting existing Looker dashboards, LookML models,
or downstream SQL consumers.

## Supported data sources

The `cortex_v6_compatibility` namespace supports SAP ECC and SAP S/4HANA data
sources exclusively. Existing Cortex Framework v6 Salesforce
workloads migrate directly to the standard v7
[Salesforce data foundation](https://docs.cloud.google.com/cortex/docs/source-system-integration/salesforce.md.txt)
and
[Salesforce data product](https://docs.cloud.google.com/cortex/docs/data-product.md.txt#data-products-for-salesforce)
modules (`cortex.sfdc.*`).

## How it works

The v6 compatibility layer acts as an adapter between conformed v7 foundations
and legacy v6 reporting consumers:

- **Schema-compatible views** : Exposes `PascalCase` reporting view names, column names, and data types matching Cortex Framework v6.
- **Target dataset isolation** : Deploys compatibility models from a separate namespace (`cortex_v6_compatibility`) into a dedicated BigQuery target dataset so compatibility views never collide with standard v7 tables.

## Deploy the compatibility content

Complete the following steps to deploy `cortex_v6_compatibility`:

1. Configure a dedicated BigQuery target dataset.
2. Register the `cortex_v6_compatibility` namespace and enable all compatibility modules in `config/config.yaml`.
3. Run the Cortex Framework build and deployment CLI.
4. Execute the generated Dataform pipelines.

### Dedicated target dataset

Deploy `cortex_v6_compatibility` to its own BigQuery dataset to
prevent physical table collisions with standard v7 data products:

```yaml
data:
  datasets:
    - id: product_target
      projectId: TARGET_PROJECT_ID
      datasetId: prod_sap_dataproducts # Core v7 tables
    - id: cortex_v6_compatibility_target
      projectId: TARGET_PROJECT_ID
      datasetId: prod_sap_cortex6 # Compatibility v6 tables
```

Replace the following:

- `TARGET_PROJECT_ID`: the destination Google Cloud project ID for your BigQuery datasets, for example: `my-target-project`.

### Configure Cortex Framework

Register the `cortex` and `cortex_v6_compatibility` namespaces and set
`enabled: true` on the `sap_cortex_v6_compatibility_*` modules in
`config/config.yaml`:

- `sap_cortex_v6_compatibility_master_data`
- `sap_cortex_v6_compatibility_accounts_payable`
- `sap_cortex_v6_compatibility_finance`
- `sap_cortex_v6_compatibility_inventory`
- `sap_cortex_v6_compatibility_purchasing`
- `sap_cortex_v6_compatibility_sales`

Because `data.namespaces` acts as a strict allowlist when present, you must
include `cortex` alongside `cortex_v6_compatibility` so compatibility modules
can bind to `cortex.sap.foundations.sap`. Omit `path` for built-in namespaces.

The following example enables `sap_cortex_v6_compatibility_inventory` and binds
its cross-module dependencies:

```yaml
data:
  datasets:
    - id: cortex_v6_compatibility_target
      projectId: TARGET_PROJECT_ID
      datasetId: prod_sap_cortex6

  namespaces:
    - name: cortex
    - name: cortex_v6_compatibility

  modules:
    products:
      - moduleId: sap_cortex_v6_compatibility_inventory
        modulePath: cortex_v6_compatibility.sap.products.inventory
        enabled: true # If using configuration file based on config.yaml.example, ensure the `enabled` flag is set to `true`
        syncToKc: false
        dependencyBindings:
          sapModule: erp
          sapMasterData: sap_cortex_v6_compatibility_master_data
          sapSales: sap_cortex_v6_compatibility_sales
        dataTargetId: cortex_v6_compatibility_target
        moduleSettings:
          targetCurrencies: ['USD']
          rateType: 'M'

#    You must ensure the `enabled` flag is set to `true` for all of the listed dependent modules. In this example:
#   `sap_cortex_v6_compatibility_master_data`
#   `sap_cortex_v6_compatibility_sales`
```

Replace the following:

- `TARGET_PROJECT_ID`: the destination Google Cloud project ID, for example: `my-target-project`.

#### SAP client (`mandt`) and product `moduleSettings`

Compatibility models read the SAP client from `moduleSettings.mandt` on the SAP
foundation module bound to `sapModule`. Configure `mandt` as a 3-character
alphanumeric string (`[0-9A-Za-z]{3}`, for example `"100"`); invalid or missing
values fail Dataform compilation:

- `cost_centers` and `profit_centers` (SAP S/4HANA), `fiscal_date_dim`, `vendor_lead_time_overview`, `vendor_performance_overview`, and models joining `fiscal_date_dim` on client (such as `FinancialStatement`) filter rows to this configured SAP client.
- `balance_sheet` and `profit_and_loss` convert amounts to target currencies for this client, and on SAP ECC `StockCharacteristicsConfig` seeds movement-type mappings for this client (if upgrading an SAP ECC deployment whose client isn't `"100"`, run `stock_weekly_snapshots` and `stock_monthly_snapshots` once with full refresh).

You can also customize per-module `moduleSettings` in `config/config.yaml` (see
`config/config.yaml.example` for defaults):

- **`sap_cortex_v6_compatibility_accounts_payable`** : `targetCurrencies` (`['USD']`), `rateType` (`'M'`), `paymentDocTypes` (`['KZ', 'ZP']`), `cashDiscountTransactionKey` (`'SKE'`), `parkedInvoiceStatuses` (`['A', 'B']`), and `invoiceDocTypes` (`['RE', 'RN', 'KR', 'KG', 'RA']`).
- **`sap_cortex_v6_compatibility_finance`** : `targetCurrencies` (`['USD']`), `receivablesTargetCurrency` (optional), `rateType` (`'M'`), `languages`, `profitCenterHierarchySubclass` (`'A000'`), and `costCenterHierarchySubclass` (`'A000'`).
- **`sap_cortex_v6_compatibility_inventory`** and **`sap_cortex_v6_compatibility_purchasing`** : `targetCurrencies` (`['USD']`), `rateType` (`'M'`), and `languages`.
- **`sap_cortex_v6_compatibility_sales`** : `languages` (`['E']`).

### Operational requirements

Enable all compatibility modules in `config/config.yaml` together. Compatibility
models contain cross-module dependencies (for example, billing models reference
master data dimensions, and inventory snapshot views reference the fiscal date
dimension), so enabling a subset causes unresolved `ctx.ref` errors during
Dataform compilation.

> [!TIP]
> **Tip:** When configuring declarative [data quality assertions](https://docs.cloud.google.com/cortex/docs/data-quality-assertions.md.txt) or table settings for `cortex_v6_compatibility` models in `table_settings.yaml` or `inlineTableSettings`, use the `snake_case` definition file stem as the entry key (for example, `sales_orders_v2` or `delivery_headers`). The default `PascalCase` `tableName` (for example, `SalesOrders_V2` or `DeliveryHeaders`) is preserved automatically.

#### Inventory snapshots

Keep `stock_weekly_snapshots` and `stock_monthly_snapshots` configured with
`materializationType: incremental` (the default):

- **Initial run**: Processes the full movement history to establish baseline stock quantities and values.
- **Subsequent runs** : Detects movements replicated since the previous run using `recordstamp` (stored in `source_last_updated_at`), rather than posting date, so late postings into an already written period are included. Each incremental run deletes and rebuilds every period starting from the earliest touched period (including later periods without additional movements) and carries forward each stock key's cumulative balance from that key's most recent remaining period.
- **Full-refresh trade-offs**: Running these tables in full-refresh mode recalculates the full historical movement log from scratch on every run, which increases query scan cost. Incremental runs don't detect physical deletes in the source (for example, archived material documents) or posting-date changes that move a movement to a later period. Run a full refresh when you need to remove archived or moved movements from cumulative totals.

> [!NOTE]
> **Note:** **Automatic rebuild when upgrading to v7.1.** Version 7.1 updates how inventory snapshot keys are classified and normalized: `stock_characteristic` and `werks` (in both `stock_weekly_snapshots` and `stock_monthly_snapshots`) and `sobkz`, `bwart`, `shkzg`, and `insmk` (in `stock_monthly_snapshots` only) are stored as `''` instead of `NULL`. On SAP S/4HANA, `StockCharacteristicsConfig` maps blank-`SOBKZ` stock with `BSTAUS_SG = 'A'` to `Unrestricted` instead of leaving it `NULL`. Because running totals are partitioned by these keys, rows from earlier versions can't be continued directly. On the first incremental run after upgrading, Cortex Framework detects the missing `source_last_updated_at` watermark, deletes existing rows from `stock_weekly_snapshots` and `stock_monthly_snapshots` (for both SAP ECC and SAP S/4HANA), and rebuilds both tables from the full movement history before resuming incremental runs---so no manual full refresh is required when upgrading from v7.0.x (for either SAP S/4HANA or any SAP ECC `moduleSettings.mandt` client). Only run a manual full refresh on `stock_weekly_snapshots` and `stock_monthly_snapshots` if you later change `moduleSettings.mandt` on an already-upgraded v7.1 deployment.

### Build and deploy the compatibility content

Build and deploy the compatibility modules by following the
[Deployment guide](https://docs.cloud.google.com/cortex/docs/deployment.md.txt) and
[Post-deployment steps](https://docs.cloud.google.com/cortex/docs/post-deployment-steps.md.txt).

## Known limitations

Customizations and custom reporting views aren't included in
`cortex_v6_compatibility`. The compatibility modules cover standard
Cortex Framework v6 SAP views only. If you want to migrate your
customizations and custom reporting views from Cortex Framework
v6, contact your Google sales representative.