> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# SAP gateway and S/4HANA OData

> Read SAP gateway streams and S/4HANA OData resources, and write S/4HANA business partners and sales orders.

Mount [app-rest](https://docs.bijection.com/integrations/native-rest.md#mount-and-bind) against the
existing Bijection SAP gateway. The gateway operator supplies SAP JCo and,
for CDC, the Bijection ABAP add-on and a complete seed. Bind `restEndpoint`
to a reachable HTTPS ingress for the gateway. Seal an installation read token
as bearer auth. Bind the receiver and the mount under the same `data` label.

* **SAP CDC.** Bind `/v1/streams/<name>/<digest>/<epoch>/changes` and
  initialize with `{ profile: { mode: "provider", provider: "sap.cdc", limit: 128 } }`.
  Use the captured stream digest and exact epoch. The app requests from
  position zero, validates contiguous sequence positions and checkpoints
  `through` for the next page or poll. The gateway supplies exact composite
  keys and full images. Explicit deletes remove rows and repeated changes
  for the same key in one page land the last change. A page admits up to
  128 changes and 36 KiB. A larger gateway page fails without moving the
  cursor. This mode publishes each page independently. An expired or
  replaced stream needs operator review and a fresh mount for a new epoch.
* **Captured functions.** Bind `/v1/functions/<name>/<digest>/records`
  and initialize with
  `{ profile: { mode: "provider", provider: "sap.functions", selection: "<digest>", limit: 10 } }`.
  Use the same 64-character digest for path and selection. In the gateway
  path, write a namespace slash as `~`. Each poll publishes metadata by
  the gateway's function `key` from one answer of at most 100 records and
  36 KiB. Prior observations survive omissions. BAPI invocation is outside
  this mode.

[SAP gateway installation and captured interface](https://github.com/bijectionhq/bijection/tree/main/external/provider_gateways/sap-gateway)

## S/4HANA OData and CDS views

Use [app-rest](https://docs.bijection.com/integrations/native-rest.md#mount-and-bind) and
`declaredResourceEndpoint(selection, auth, data)`. Bind the receiver as
`receivers.resource`, using a sealed read credential for the SAP communication
arrangement. Bind the mount and its receivers under the same protected `data` label.
For a CDS view, activate its OData exposure and use the published collection
path.

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
const selection = {
  provider: "sap",
  resource: "sap.s4hana.odata-v2.entities",
  origin: "https://gateway.example",
  path: "/sap/opu/odata/sap/ZORDERS_CDS/Orders",
};
const profile = {
  mode: "declared",
  selection,
  keys: ["CompanyCode", "SalesOrder"],
  fields: [{ name: "company", path: ["CompanyCode"], type: "string" }],
  limit: 16,
};
```

Pass the profile to `source.initialize`. Declare the complete one- to
eight-field immutable key and a typed projection of direct fields. Record keys
encode the ordered key tuple. Each answer is limited to the installed 1–100
rows and 36 KiB. For v4, use the published OData v4 path such as
`/sap/opu/odata4/sap/zorders/srvd/sap/zorders/0001/Orders`.

* `sap.s4hana.odata-v2.entities` and `sap.s4hana.odata-v4.entities` sweep
  entity sets ordered by key. Each next position must stay within the
  installed collection. Missing rows remain.
* `sap.s4hana.odata-v2.delta` requires Gateway JSON `d.__delta` with a
  `$deltatoken` or `!deltatoken` on the same collection. The service must
  return full after-images. Gateway v2 JSON does not carry tombstones, so
  missing and deleted provider rows remain published.
* `sap.s4hana.odata-v4.delta` requires a terminal same-collection
  `@odata.deltaLink` with `$deltatoken` and full after-images. Explicit
  tombstones must carry all key fields and reason `deleted`. Other delta
  shapes fail the page. Omission leaves existing rows in place.

Tracking modes commit each page with its next position. A terminal delta
token seeds the next poll. An HTTP 410 on a retained cursor stops automatic
advancement until an operator resets the source. A reset rereads the
collection and retains previously landed rows that the provider omits.

[SAP Gateway delta query support](https://help.sap.com/docs/ABAP_PLATFORM_NEW/68bf513362174d54b58cddec28794093/19a426519eff236ee10000000a445394.html)

## Write S/4HANA business partners and sales orders

Use [providerWriter](https://docs.bijection.com/integrations/native-rest.md#native-provider-writes)
with the communication arrangement's HTTPS origin and a protected label.
Bind the REST mount and its writer under the same label. Enable the corresponding A2X service for the writer.

Declare `multiSecret` with three sealed HTTP headers. Set `Authorization`
with prefix `Basic ` or `Bearer `. Seal the SAP session's `X-CSRF-Token`
and matching `Cookie` header without prefixes. The credential operator
obtains the pair from the same SAP origin and service using
`X-CSRF-Token: Fetch` and rotates it before expiry. The writer sends the
sealed values together. Expired or mismatched session credentials can
produce an SAP refusal.

| Mode | Evidence |
| - | - |
| `sap.s4hana.odata-v2.business-partners.create-update` | POST to `API_BUSINESS_PARTNER/A_BusinessPartner`. HTTP 201 lands `d.BusinessPartner`. PATCH to the OData `BusinessPartner` key lands HTTP 204 and the command ID. |
| `sap.s4hana.odata-v2.sales-orders.create-update` | POST to `API_SALES_ORDER_SRV/A_SalesOrder`. HTTP 201 lands `d.SalesOrder`. PATCH to the order key lands HTTP 204 and the command ID. |

Submit one JSON object up to 24 KiB. For updates, place the target ID on
the command and omit the provider key from the JSON body. An optional
`ifMatch` property carries the quoted ETag and is sent as a header.
Bijection retains only status and record ID as write evidence. These
modes dispatch each exact command once and have no read cursor.
SAP owns deep insert support and the business rules for each service.

[Business Partner A2X](https://help.sap.com/docs/SAP_S4HANA_CLOUD/3c916ef10fc240c9afc594b346ffaf77/85043858ea0f9244e10000000a4450e5.html) ·
[Sales Order operations](https://help.sap.com/docs/SAP_S4HANA_CLOUD/03c04db2a7434731b7fe21dca77440da/17f4a94ed364458ba96b399d43fd1779.html) ·
[SAP CSRF session handling](https://help.sap.com/docs/SUPPORT_CONTENT/plm/3472705633.html)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.