# SAP Business Data Cloud integration

Google Cloud Cortex Framework connects to **SAP Business Data Cloud (SAP BDC)**
using BigLake Delta Sharing (`lakehouse_delta_share`)
so you can query governed SAP data products directly in BigQuery with
zero data duplication and join them in downstream analytical models.

The integration combines the following core mechanisms:

- **Zero-copy federated querying**: SAP BDC publishes curated data products through Delta Sharing endpoints that BigQuery queries in place through a Google Cloud BigLake catalog.
- **Declarative catalog registration** : You register the SAP BDC catalog once under `data.modules.catalogs` in `config/config.yaml` using `type: lakehouse_delta_share`.
- **Logical dependency bindings** : Downstream data products bind logical inputs to specific Delta Sharing schemas using two-part (`<catalog_id>.<schema_name>`) or three-part (`<catalog_id>.<share_id>.<schema_name>`) bindings without hardcoding environment-specific catalog paths in SQL.

## Hybrid enterprise architecture and use cases

Integrating SAP BDC with Cortex Framework supports the following
enterprise architecture patterns:

- **Centralized governance and orchestration** : Manage federated SAP BDC inputs, conformed foundation tables, and downstream consumption views from a single `config/config.yaml` file. Cortex Framework compiles a unified Dataform DAG, enforces [data quality assertions](https://docs.cloud.google.com/cortex/docs/data-quality-assertions.md.txt), and publishes business metadata to [Knowledge Catalog](https://docs.cloud.google.com/cortex/docs/knowledge-catalog.md.txt).
- **Unified hybrid SAP landscapes** : Harmonize data across legacy **SAP ECC** , modern **SAP S/4HANA** , and standalone **SAP Business Warehouse (SAP BW)** systems exposed through SAP BDC shares alongside raw-replicated [SAP ERP data foundations](https://docs.cloud.google.com/cortex/docs/source-system-integration/sap-erp.md.txt).
- **Cross-platform composite data products** : Join SAP BDC shares with [Salesforce CRM](https://docs.cloud.google.com/cortex/docs/source-system-integration/salesforce.md.txt) foundations or external zero-copy datasets in [BigQuery sharing](https://docs.cloud.google.com/cortex/docs/source-system-integration/analytics-hub.md.txt)---such as Google WeatherNext forecasts or Dun \& Bradstreet shipping intelligence---to deliver cross-domain supply chain, finance, and sales insights.

## Prerequisites for SAP BDC

Before configuring SAP BDC in Cortex Framework, complete the
following setup steps in Google Cloud and SAP:

1. Enable the required Google Cloud APIs on the catalog host project: `biglake.googleapis.com`, `bigquery.googleapis.com`, `bigqueryreservation.googleapis.com`, and `cloudresourcemanager.googleapis.com` (and enable `dataform.googleapis.com` on your Dataform repository project).
2. Ensure that your catalog project (or its parent folder or organization) has an active BigQuery Enterprise Plus `QUERY` reservation assignment in the catalog location.
3. Set up a BigQuery BigLake Delta Sharing catalog connection in your Google Cloud project by following [Set up cross-cloud connection for SAP Business Data Cloud](https://docs.cloud.google.com/lakehouse/docs/set-up-cross-cloud-connection-sap-bdc.md.txt).
4. Retrieve the Delta Sharing `shareId` and schema names published by your SAP BDC tenant by following [Query SAP data](https://docs.cloud.google.com/lakehouse/docs/query-sap-data.md.txt) (for example, share IDs such as `customer_v1_he2_100_p8123` or `salesorder_v1_he2_100_p8124`, and schema names such as `customer` or `salesorder`).
5. Grant the required Identity and Access Management (IAM) roles for each principal:
   - **CLI build principal** (`uv run cortex-build`): BigLake Viewer (`roles/biglake.viewer`) and BigQuery Data Viewer (`roles/bigquery.dataViewer`) on the subscribed BigLake catalog project and resources.
   - **CLI deploy principal** (`uv run cortex-deploy` and `uv run cortex-build-and-deploy`): BigQuery Resource Viewer (`roles/bigquery.resourceViewer`) on the catalog project to validate the Enterprise Plus `QUERY` reservation assignment, Browser (`roles/browser`) on parent folders or the organization when Enterprise Plus capacity is assigned at a parent folder or organization level, Dataform Editor (`roles/dataform.editor`, or `roles/dataform.admin` to create a repository) on the Dataform repository project, and BigQuery Data Editor (`roles/bigquery.dataEditor`) on target projects or datasets (to inspect or create target datasets with `--create-datasets`). Running `uv run cortex-build-and-deploy` requires both the CLI build principal and CLI deploy principal roles.
   - **Dataform execution service account** : BigLake Viewer (`roles/biglake.viewer`) and BigQuery Data Viewer (`roles/bigquery.dataViewer`) on the subscribed BigLake catalog project and resources, BigQuery Data Editor (`roles/bigquery.dataEditor`) on the writable target dataset, and BigQuery Job User (`roles/bigquery.jobUser`) on the execution project.

## Configuration example

The following `config/config.yaml` excerpt registers an SAP BDC catalog under
`data.modules.catalogs` and binds two shared schemas to a downstream sales
performance consumption data product:

```yaml
buildEnvironment:
  buildProjectId: BUILD_PROJECT_ID

data:
  bigQueryLocation: europe-west3
  namespaces:
    - name: cortex
    - name: cortex_samples
  datasets:
    - id: sap_bdc_data_products
      projectId: TARGET_PROJECT_ID
      datasetId: sap_bdc_data_products

  modules:
    # 1. Register the SAP BDC BigLake catalog connection (using lakehouse_delta_share type)
    catalogs:
      - id: sap_bdc_catalog
        type: lakehouse_delta_share
        enabled: true
        bindsNamespaces: [sap_bdc]
        connectionSettings:
          catalogId: sap_bdc_catalog
          projectId: CATALOG_PROJECT_ID
          location: europe-west3
          shares:
            - shareId: CUSTOMER_SHARE_ID
            - shareId: SALES_ORDER_SHARE_ID
        # Optional: restrict discovered tables with tableSettings or inlineTableSettings:
        # inlineTableSettings:
        #   tables: [customer, salesorder, salesorderitem]

    # 2. Reference the catalog schemas in downstream products
    products:
      - moduleId: sap_bdc_sales_performance
        modulePath: cortex_samples.sap_bdc.products.sales_performance
        dependencyBindings:
          # Bind logical dependencies to catalog schemas (2-part or 3-part format)
          sapBdcCustomer: sap_bdc_catalog.CUSTOMER_SHARE_ID.customer
          sapBdcSalesOrder: sap_bdc_catalog.SALES_ORDER_SHARE_ID.salesorder
        dataTargetId: sap_bdc_data_products
```

Replace the following:

- `BUILD_PROJECT_ID`: the Google Cloud project ID where build jobs run, for example: `my-build-project`.
- `TARGET_PROJECT_ID`: the destination Google Cloud project ID for BigQuery views, for example: `my-target-project`.
- `CATALOG_PROJECT_ID`: the Google Cloud project ID hosting the BigLake catalog, for example: `my-catalog-project`.
- `CUSTOMER_SHARE_ID`: the Delta Sharing `shareId` identifier exposed by SAP BDC for customer data, for example: `customer_v1_he2_100_p8123`.
- `SALES_ORDER_SHARE_ID`: the Delta Sharing `shareId` identifier exposed by SAP BDC for sales order data, for example: `salesorder_v1_he2_100_p8124`.

Optionally, you can add `tableSettings` (path to a YAML file relative to
`config/`) or `inlineTableSettings` (`tables` or `variants`, mutually exclusive
with `tableSettings`) on the `lakehouse_delta_share` catalog entry to limit
discovery to an explicit table allowlist. For the complete catalog parameter
schema, see
[Deployment configuration (`data.modules.catalogs`)](https://docs.cloud.google.com/cortex/docs/deployment-configuration.md.txt#data_modules_catalogs).

When binding a data product input to a BigLake Delta Sharing catalog in
`dependencyBindings`, use one of the following schema binding formats:

- **Two-part binding (`<catalog_id>.<schema_name>`)** : Use this shorter format (for example, `sap_bdc_catalog.customer` or `sap_bdc_catalog.salesorder`) when `<schema_name>` is unique across the shares configured under that catalog.
- **Three-part binding (`<catalog_id>.<share_id>.<schema_name>`)** : Use this explicit format to disambiguate when the same `<schema_name>` exists in multiple configured shares:
  - `<catalog_id>` matches the catalog `id` under `data.modules.catalogs`.
  - `<share_id>` matches one of the declared `connectionSettings.shares[].shareId` entries.
  - `<schema_name>` matches the schema exposed inside that share (individual tables inside the schema are referenced by name in `ctx.ref(...)`).

## Table settings and materialization rules

Data products built with `builder: flat_product` (the canonical builder for SAP
BDC products; `sap_bdc_product` is a deprecated alias) enforce the following
configuration rules in `table_settings.default.yaml` (or custom
`table_settings.yaml` and `inlineTableSettings` overrides):

- **Explicit `view` materialization and optional `table` or `incremental`
  materialization** : Because `ProductTableItem` defaults to `materializationType: incremental`, explicitly configure `materializationType: view` in `table_settings.default.yaml` for zero-copy pushdown against SAP BDC Delta Sharing tables. If physical materialization is needed, `materializationType: table` and `materializationType: incremental` also support optional `partitionDetails` and `clusterDetails`.
- **Flat table-key structure** : Declare each output view or table directly at the top level of `table_settings.yaml`. Don't nest entries under `ecc:`, `s4:`, or `common:` section keys---doing so fails pre-flight validation with `section_keys_not_allowed`.

```yaml
sales_performance:
  materializationType: view
  dataformTags: [sap_bdc, sales, consumption]
  bigQueryLabels:
    - key: line_of_business
      value: sales
```

## Downstream Dataform dependency binding

During compilation (`uv run cortex-build`), Cortex Framework
resolves catalog bindings into fully qualified BigQuery federated
table references. Reference the bound inputs in your `.js` definition using the
three-argument `ctx.ref(source_project_id, source_dataset_id, "TableName")`
signature:

```javascript
// Example JS definition referencing SAP BDC inputs
// ___MODULE_CONTEXT___
// ___TABLE_CONFIG___

const publish_config = require("includes/publish_config.js");
const publisher = require("includes/publisher.js");

const moduleConfig = config.product[moduleContext.moduleId];
const customerSource = moduleConfig.sources.sapBdcCustomer;
const salesOrderSource = moduleConfig.sources.sapBdcSalesOrder;

const materializationType = tableConfig.materializationType || "view";
const publishConfig = publish_config.getPublishConfig(
  materializationType,
  tableConfig,
  moduleConfig
);

publisher.publish(moduleContext.moduleId + "_" + tableConfig.tableName, publishConfig).query(
  (ctx) => `
    SELECT
      orders.SalesOrder AS sales_order,
      cust.Customer AS customer,
      orders.TotalNetAmount AS total_net_amount,
      CURRENT_TIMESTAMP() AS bq_loaded_at
    FROM ${ctx.ref(
      salesOrderSource.projectId,
      salesOrderSource.datasetId,
      "salesorder"
    )} AS orders
    LEFT JOIN ${ctx.ref(
      customerSource.projectId,
      customerSource.datasetId,
      "customer"
    )} AS cust
      ON orders.SoldToParty = cust.Customer
  `
);
```

## What's next

- [Solution samples overview](https://docs.cloud.google.com/cortex/docs/solution-samples/overview.md.txt)
- [Data product module creation](https://docs.cloud.google.com/cortex/docs/extensibility-guide-data-product.md.txt)
- [Deployment configuration](https://docs.cloud.google.com/cortex/docs/deployment-configuration.md.txt)