> For the complete documentation index, see [llms.txt](https://docs.riff.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.riff.ai/integrations/native-integrations-v2/sap.md).

# SAP S/4HANA

Connect Riff to SAP S/4HANA or the SAP Business Technology Platform (BTP) to give your apps and agents live access to purchase orders, vendor data, materials, invoices, and cost centres.

## What you connect

Riff connects to SAP using the **SAP OData V4 APIs** (for S/4HANA Cloud) or the **SAP API Business Hub** REST APIs. Authentication uses an **OAuth 2.0 service key** issued from SAP BTP.

**Credentials needed:**

| Credential                | Where to find it                                  |
| ------------------------- | ------------------------------------------------- |
| OAuth token URL           | SAP BTP → Service Instances → OAuth credentials   |
| Client ID + Client Secret | SAP BTP service key JSON                          |
| API endpoint base URL     | SAP API Business Hub or your S/4HANA instance URL |
| SAP Client (MANDT)        | Your SAP system configuration                     |

## What your apps and agents can read

| SAP object             | API                                | Common use                                      |
| ---------------------- | ---------------------------------- | ----------------------------------------------- |
| Purchase Orders        | `/API_PURCHASEORDER_PROCESS_SRV`   | Confirmation status, delivery dates, line items |
| Goods Receipts / GR-IR | `/API_MATERIAL_DOCUMENT_SRV`       | Posted receipts, quantity variances             |
| Vendor Master          | `/API_BUSINESS_PARTNER`            | Supplier contacts, payment terms, bank details  |
| Supplier Invoices      | `/API_SUPPLIERINVOICE_PROCESS_SRV` | Invoice headers, line items, payment status     |
| Material Master        | `/API_PRODUCT_SRV`                 | Material descriptions, units, plant data        |
| Cost Centres           | `/API_COSTCENTER_0002`             | Cost centre hierarchy, budget vs. actuals       |

## What your agents can do

| Action                         | Example                                                                     |
| ------------------------------ | --------------------------------------------------------------------------- |
| **Monitor overdue deliveries** | Query PO lines where delivery date has passed with no GR → alert buyer      |
| **Chase confirmations**        | Read unconfirmed POs → send confirmation request → log response             |
| **Three-way match**            | Compare PO quantity/price → GR posting → supplier invoice → approve or flag |
| **Cost variance reporting**    | Read cost centre actuals vs. plan → flag variances above threshold          |
| **GR/IR reconciliation**       | List GR/IR open items → identify blocked invoices → route to AP             |

## App use cases

### Procurement Dashboard

Build an App that reads open PO lines from S/4HANA and displays delivery status by supplier, site, and category — colour-coded by days overdue. Buyers filter, search, and click through to the original PO. No SAP login needed for the team.

### Invoice Verification Queue

Display all supplier invoices pending three-way match. Show PO quantity, GR quantity, and invoice quantity side by side. AP clerks approve matched invoices directly in the app — the agent posts the approval back to SAP.

### Cost Centre Variance Monitor

Pull cost centre actuals and planned values from SAP. Flag cost centres where actuals exceed plan by more than 10%. Output a weekly digest to Finance with drill-down by GL account.

## Agent use cases

### Overdue Delivery Monitor

**Trigger:** Daily at 06:30\
**Input:** Open SAP PO lines where scheduled delivery date is before today\
**Action:** Group by supplier → send delivery status request via Outlook → log replies\
**Output:** Slack digest to procurement team; unresolved items escalated to buyer

### Invoice Matching Agent

**Trigger:** New invoice notification (Outlook or SAP workflow)\
**Input:** Invoice header and lines from `/API_SUPPLIERINVOICE_PROCESS_SRV`\
**Action:** Match against PO and GR; calculate quantity and price variance\
**Output:** Auto-post matched invoices; queue mismatches for manual review with match summary

### GR/IR Reconciliation Agent

**Trigger:** Weekly, Monday 07:00\
**Input:** GR/IR open items list from SAP\
**Action:** Categorise by root cause (price difference, quantity difference, missing GR, missing invoice)\
**Output:** Structured exception report to AP manager with recommended actions per item

## Connecting SAP in Riff

1. In SAP BTP, create a service instance for the SAP API you need (e.g., Purchase Orders)
2. Download the service key JSON — this contains your Client ID, Client Secret, and token URL
3. Open **Secrets** in Riff and store each credential
4. In your app or agent, reference the secrets to authenticate via OAuth 2.0 and call the API
5. Ask your agent: *"Read all open purchase orders from SAP where the delivery date is in the past and no goods receipt has been posted"*

{% hint style="info" %}
**S/4HANA Cloud vs. On-Premise:** The OData V4 APIs described here are for S/4HANA Cloud Public Edition. For on-premise or private cloud deployments, connection is via SAP Integration Suite or direct OData V2 — ask your SAP Basis team for the correct endpoint and authentication method.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.riff.ai/integrations/native-integrations-v2/sap.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
