# SAP Integration

Emporix is designed to integrate seamlessly with ERP systems. To integrate an ERP system like SAP with Emporix, an integration layer (such as a middleware solution or API management platform) can be utilized to handle data exchange efficiently. This layer can collect and transform data, for example IDocs from SAP, into a suitable format, such as JSON, and make the necessary API calls to Emporix.\
Options for integration include using an IPaaS platform or an API management layer that supports OData, REST API, or other protocols, enabling flexible and scalable integration tailored to the specific requirements of the ERP and target systems.

Given SAP’s significant presence in the ERP software space, we highlight a scenario in which asynchronous pricing and order replication occur from the Emporix Commerce Engine to SAP ERP.\
In this example, we selected SAP BTP Integration Suite (formerly known as SCPI) to streamline the integration process, leveraging Emporix flexible API capabilities.

## Emporix - SAP integration

The video and the diagram show high level overview of the data replication between Emporix and S/4Hana using SAP Integration Suite.

{% hint style="warning" %}
This demo is a presentation of one potential approach to integrate with SAP. Alternatively, REST APIs or OData can be utilized for integration purposes.
{% endhint %}

{% embed url="<https://youtu.be/esIAv8BfH1c?feature=shared>" %}

## Master data replication

To create an order from Emporix into SAP, the following master data must be replicated to provide the information for the transactional IDoc:

| IDoc                          | SAP Name       | Types in Emporix              |
| ----------------------------- | -------------- | ----------------------------- |
| `MATMAS05`                    | Material       | Product                       |
| `COND_A04`                    | Condition      | Price, PriceModel, PriceList  |
| `DEBMAS07`                    | Customer       | Company                       |
| `ADRMAS03`                    | Contact Person | Customer                      |
| `ADR2MAS03`                   | Address        | Location                      |
| `ADR3MAS03`                   | Address        | Location                      |
| Transactional IDoc:           |                |                               |
| `SALESORDER_CREATEFROMDAT202` | Transaction    | Order created Webhook payload |

Here's how the replication process looks like:

<figure><img src="https://3057647601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbTY7EwZtYYQYC6GOcdTj%2Fuploads%2Fgit-blob-507ae2c25b8728bb2b319741812573958fe0477d%2FsapDiagram.png?alt=media" alt=""><figcaption></figcaption></figure>

### Product replication

Product replication uses the MATMAS IDoc generated by SAP ERP, which holds essential product details, for example, localized product name, tax type, and product code. Emporix can use the same product code as the ERP, allowing the upsert API to create or update the product as needed, thereby simplifying the integration process.

### Price replication

Product prices are replicated through the COND\_A IDoc, known as `conditions` in SAP, which contains details such as price validity, minimum quantity, and customer-specific price lists. Prices are assigned to either net or gross price models, depending on the price type, and customer assignments are made at the ship-to level.

### Customer data replication

Customer data is distributed across multiple IDocs. The diagram below shows SAP/Emporix object relations:

<figure><img src="https://3057647601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbTY7EwZtYYQYC6GOcdTj%2Fuploads%2Fgit-blob-5d2a61b3e40c2cea6d74218b73689fa5c62b37bd%2FsapERP2.svg?alt=media" alt=""><figcaption></figcaption></figure>

To accurately reflect this data in the Emporix Commerce Engine, the following entities must be created:

* **Company**

  The DEBMAS IDoc contains core company information, including functional assignments such as Sold To, Ship To, Bill To, Payer, and the Contact Person relationship.

  Address details are provided through the ADRMAS IDoc.
* **Location**

  Company location details, along with communication information, are derived from data in the DEBMAS and ADRMAS IDocs. Depending on the functional assignments of the addresses, locations are tagged as either shipping or billing.
* **Customer**

  The Emporix customer entity is created based on the Contact Person relationship from the ERP system. This relationship includes the customer’s assigned email, phone number, and address details. As illustrated in the diagram, the DEBMAS, ADR2MAS, and ADR3MAS IDocs are required for customer creation within the Emporix Commerce Engine.

### Order replication

Order replication from Emporix to SAP ERP is achieved through order creation webhooks, which are sent to the SAP BTP Integration Suite. The necessary company details (e.g., sold-to, ship-to) are added to the order using mixins, ensuring they are included in the webhook payload. The SAP BTP Integration Suite then converts the webhook data into a SALESORDER\_CREATEFROMDAT202 IDoc, which is sent to the SAP ERP system through the iFlow.

<figure><img src="https://3057647601-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbTY7EwZtYYQYC6GOcdTj%2Fuploads%2Fgit-blob-2ccf2fe13dbad0aaafcbcb888d3b9f4e0fc052b8%2FsapERP3.png?alt=media" alt=""><figcaption></figcaption></figure>
