# Celonis Product Documentation

##### AR: Clear FI Documents
###### Overview
 Use Case Name Automatic clearing of customer documents in FI Execution Capacity Reduce manual effort & expedite open items clearing Process / Data Model Accounts Receivable data model Semi-/Fully automated Fully automated Systems SAP ECC SAP TCode in GUI F-32 Updated SAP field n/a (Clearing is executed)
###### Execution Gap

Payments are already assigned to the customer accounts but clearing open invoice positions and payments are typically a highly manual effort. This can be conducted automatically to reduce manual effort.

###### Business Case Calculation

Let’s look at a customer who has a team of eight people who only take care of clearing invoices. Automating 75% of the open invoice positions would save 6 FTE which corresponds to 480,000 € yearly savings on average.

Customer Example

A multinational distribution and logistics company has a large range of customers with a varying size of invoices. Therefore, multiple logics need to be applied to match and clear open invoice positions and payments. These different matching logics cannot be replicated with SAP which leads to a big team of clerks who only deal with invoice clearing. As a result of this time-consuming task, high labor costs occur while the workforce could be used for other value-adding activities. Following this inefficiency, the customer was looking for automation assistance to free capacities.

Customer Solution

Groups of invoice items that are ready to be cleared are identified applying various defined matching rules. The information of these invoice item groups can then be easily processed using a BAPI provided by Celonis. The easiest example is to clear open items on a customer account which has:

• the same reference assignment number

• the same currency

• the same customer

• the same company code

Why Celonis EMS Automation?

Matching open debit and credit items on debitor or customer accounts and clearing them is typically a highly manual and complex task. In SAP, automatic invoice clearing is only possible for trivial cases. However, applying different matching rules to different customer groups is not straightforward or even not possible at all on a granular level. In Celonis, specifying different rules per account group or document type is straightforward and very flexible using basic SQL commands or advanced PQL functions. Entire teams only take care of the invoice clearing which implies high labour costs. What if we fully automated the invoice clearing to save resources for other tasks?

###### Required IT Architecture

The IT architecture required to successfully implement this automation use case can be found in the following help page.

###### Project Timeline & Effort

The recommended timeline, milestones and project members needed to successfully implement this automation use case can be found in the following help page.

###### Technical Setup

The table below shows the technical setup steps required to configure this use case successfully.

Step

Documentation

Who

Effort

Update extractor to real-time extractor

Installation Guide

IT Contact

Data Scientist

2 h

Install Celonis on-prem Agent and set to automatic start

Installation Guide

IT Contact

Data Scientist

2 h

Import SAP transport for open FI document clearing

SAP Automation Package

IT Contact

2 h

Create technical SAP user with required permissions

Installation Guide

IT Contact

2 h

###### Import Use Case Package

The following import guide contains instructions for importing the Action Engine and Studio Skills for this automation use case.

###### Template Building Blocks

After importing the package (see technical setup above), you will find the following building blocks in your EMS team. The vast majority of the Data Scientist person days indicated in the project setup table above is allocated to customizing these building blocks and adjusting the business logic to the customer’s needs.

###### Data Jobs

Data Jobs are used to extract data from different connected IT systems, and transform the data to prepare it for process mining. Once a system connection has been established (e.g. SAP or Salesforce connection), you can configure new data extraction and transformation jobs. You can learn more about data jobs in the EMS help page EMS help page.

In this use case, we will extract accounting data from SAP in order to determine which documents can be automatically cleared.

Customer Example

The extraction job is configured to pull data from the "BSID" and "T043T" tables in SAP. The information from these tables is utilized in the transformation job to identify customer accounting documents that can be automatically cleared in SAP.

###### Data Job Configuration

As mentioned above, a data job is made up of a combination of extractions and/or transformations. In extractions, particular data elements (tables, fields, etc.) are extracted from connected IT systems (e.g. SAP, Salesforce, etc.). In transformations, the extracted data is prepared using SQL to be leveraged in Celonis Skills, analyses or automations.

Below, you will find a collection of data jobs required to identify accounting documents that can be automatically cleared.

Data Extraction Jobs

Extractions allow us to define new data tables and fields to extract from our connected IT systems. Below you will find the tables that should be included in your extraction jobs, alongside the standard data model tables.

BSID Table

The BSID (Accounting: Secondary Index for Customers) table is a standard table in SAP, but is not typically included in standard Celonis data models. The following fields should be extracted for this use case to be implemented successfully.

• "MANDT"-- Client

• "BUKRS"-- Company Code

• "KUNNR"-- Customer Number

• "ZUONR"-- Assignment Number

• "GJAHR"-- Fiscal Year

• "BELNR"-- Accounting Document Number

• "BUZEI"-- Line Item Number

• "BUDAT"-- Posting date in the document

• "WAERS"-- Currency Key

• "BLART"-- Document Type

• "SHKZG"-- Debit/Credit Indicator

• "WRBTR"-- Amount in Document Currency

• "XREF1"-- Business Partner Reference Key

• "XREF2"-- Business Partner Reference Key

• "XREF3"-- Reference Key for Line Item

• The BSID table is equivalent to all uncleared invoice positions in the accounting segment table (FILTER "BSEG"."AUGBL" IS NULL). However, not all required fields from the BSID table are found in BSEG. The remaining required associated fields can be found in the accounting header table, BKPF.

• For these kinds of filters, it’s often easiest to use the Column Filter in Action Engine to define the required organizational conditions for the Skill.

T043T Table

The T043T (FI Tolerance Groups for Employees) table is a standard table in SAP, but is not typically included in standard Celonis data models. As such, the following fields should be extracted.

• "MANDT"-- Client

• "RFPRO"-- Tolerance Group for Financial Accounting Employees

• "BUKRS"-- Company Code

• "BETRH"-- Maximum Payment Difference for Expense

• The T043T table is relatively small, and can thus be safely extracted in its entirety without us needing to define selected fields for the extraction job.

KNA1 Table

The KNA1 (General Data in Customer Master) table is a standard table in SAP, and is included in our standard Celonis data model. The following fields are required for this use case, so you should make sure they are included in your existing extraction jobs.

• "MANDT"-- Client

• "KUNNR"-- Customer number

• "KTOKD"-- Customer account group

Data Transformation Jobs

Transformations allow us to execute SQL transformations on the data elements extracted from connected IT systems during extraction jobs. Below you will find the transformation logic to create a "CLEARING" table in the data model that contains all invoice positions available to be cleared. A sample SQL script can be found below.

Grouping for debit and credit totals

When clearing open positions, credit and debit totals must be grouped by customer, currency, and other dimensions. Once grouped, these totals can be reconciled against one another and cleared.

Example grouping fields:

• "BSID"."BUKRS"-- Company Code

• "BSID"."KUNNR" -- Customer Number

• "BSID"."ZUONR" -- Assignment Number

• "BSID"."WAERS" -- Currency Key

Conditions for clearing

In many cases, open positions can only be cleared under certain conditions and for particular customers. As such, it is important to consider which conditions to apply when creating our table of open positions ready to be cleared.

Example conditions:

• "KNA1"."KUNNR" IN ('ABC', 'DEF')

-- Customer Number is ABC or DEF

• "KNA1"."KTOKD" = 'ABC'

-- Customer Account Group is ABC

• "BSID"."BLART" IN ('123', '456')

-- Document Type is 123 or 456

• "BSID"."SHKZG" = 'H'

OR

"BSID"."SHKZG" = 'S'

-- Debit/Credit Indicator is H (Credit) or S (Debit)

Expense tolerances

The T043T (FI Tolerance Groups for Employees) table defines tolerances for the difference between the debit and credit totals. If the difference between the totals is within the defined tolerance, the associated open positions can be cleared. Your customer's conditions may differ.

Example tolerance conditions:

• Balance of totals equals zero: can be cleared automatically

• Balance of totals within tolerances: can be cleared automatically

• Balance of totals not within tolerances: cannot be cleared automatically

###### SQL Transformation Script

SQL Transformation Script Expand source

DROP TABLE IF EXISTS CLEARING_BSID_S_RULE_1;

-- Debit side query
CREATE TABLE CLEARING_BSID_S_RULE_1 AS
SELECT
BSID_S."MANDT" || BSID_S."BUKRS" || BSID_S."BELNR" || BSID_S."GJAHR" || BSID_S."BUZEI" AS "_CASE_KEY"
,MANDT
,BELNR
,GJAHR
,BUZEI
,WRBTR
,BUKRS
,SHKZG
,XREF1
,XREF2
,XREF3
,ZUONR
,WAERS
,BSID_S.KUNNR
-- Define here grouping columns
,SUM(BSID_S.WRBTR) OVER (PARTITION BY BSID_S.BUKRS, BSID_S.ZUONR, BSID_S.WAERS, BSID_S.KUNNR) AS "WRBTR_SUM_S"
,DENSE_RANK() OVER (ORDER BY BSID_S.BUKRS, BSID_S.ZUONR, BSID_S.WAERS, BSID_S.KUNNR) AS "GROUP_MATCH_S"
FROM
"BSID_CLEARING" AS BSID_S
LEFT JOIN "CLEARING_KNA1" AS KNA1_S ON 1=1
AND BSID_S.MANDT = KNA1_S.MANDT
AND BSID_S.KUNNR = KNA1_S.KUNNR
WHERE 1=1
-- Define here the filter conditions for the debit side
AND KNA1_S.KTOKD = 'ABC'
AND BSID_S.ZUONR IS NOT NULL
AND BSID_S.SHKZG = 'S';

DROP TABLE IF EXISTS CLEARING_BSID_H_RULE_1;

-- Credit side query
CREATE TABLE CLEARING_BSID_H_RULE_1 AS
SELECT
BSID_H."MANDT" || BSID_H."BUKRS" || BSID_H."BELNR" || BSID_H."GJAHR" || BSID_H."BUZEI" AS "_CASE_KEY"
,MANDT
,BELNR
,GJAHR
,BUZEI
,WRBTR
,BUKRS
,SHKZG
,XREF1
,XREF2
,XREF3
,ZUONR
,WAERS
,BSID_H.KUNNR
-- Define here grouping columns
,SUM(BSID_H.WRBTR) OVER (PARTITION BY BSID_H.BUKRS, BSID_H.ZUONR, BSID_H.WAERS, BSID_H.KUNNR) AS "WRBTR_SUM_H"
,DENSE_RANK() OVER (ORDER BY BSID_H.BUKRS, BSID_H.ZUONR, BSID_H.WAERS, BSID_H.KUNNR) AS "GROUP_MATCH_H"
FROM
"BSID_CLEARING" AS BSID_H
LEFT JOIN "CLEARING_KNA1" AS KNA1_H ON 1=1
AND BSID_H.MANDT = KNA1_H.MANDT
AND BSID_H.KUNNR = KNA1_H.KUNNR
WHERE 1=1
-- Define here the filter conditions for the credit side
AND KNA1_H.KTOKD = 'ABC'
AND BSID_H.ZUONR IS NOT NULL
AND BSID_H.SHKZG = 'H'
AND BSID_H.BLART IN ('ABC', 'DEF'); -- only certain credit document types (e.g. payments) are relevant for automatic clearing

DROP TABLE IF EXISTS "CLEARING_BSID_RULE_1_GROUPING";

CREATE TABLE "CLEARING_BSID_RULE_1_GROUPING" AS
SELECT
BSID_H.GROUP_MATCH_H
,BSID_S.GROUP_MATCH_S
,DENSE_RANK() OVER (ORDER BY BSID_H.GROUP_MATCH_H, BSID_S.GROUP_MATCH_S) AS "GROUP_MATCH"
,'Rule 1' AS "RULE"
,MAX(BSID_H.ZUONR) AS ZUORN
,MAX(BSID_S.WRBTR_SUM_S) AS WRBTR_SUM_S
,MAX(BSID_H.WRBTR_SUM_H) AS WRBTR_SUM_H
,ABS(MAX(BSID_H.WRBTR_SUM_H) - MAX(BSID_S.WRBTR_SUM_S)) AS "WRBTR_DIFFERENCE"
-- Define here the tolerance levels from T043T. Add or remove as needed. The absolute value (BETRH) is used.
,MAX(CASE WHEN T043T.RFPRO = 'FIRST' AND ABS(BSID_H.WRBTR_SUM_H - BSID_S.WRBTR_SUM_S) <= T043T.BETRH THEN 'Yes' END) AS "FIRST_TOLERANCE"
,MAX(CASE WHEN T043T.RFPRO = 'SECOND' AND ABS(BSID_H.WRBTR_SUM_H - BSID_S.WRBTR_SUM_S) <= T043T.BETRH THEN 'Yes' END) AS "SECOND_TOLERANCE"
,MAX(CASE WHEN T043T.RFPRO = 'THIRD' AND ABS(BSID_H.WRBTR_SUM_H - BSID_S.WRBTR_SUM_S) <= T043T.BETRH THEN 'Yes' END) AS "THIRD_TOLERANCE"
FROM
(SELECT * FROM CLEARING_BSID_S_RULE_1) AS BSID_S
INNER JOIN
(SELECT * FROM CLEARING_BSID_H_RULE_1) AS "BSID_H" ON 1=1
-- Define the join conditions based on the grouping columns
AND BSID_S.BUKRS = BSID_H.BUKRS
AND BSID_S.KUNNR = BSID_H.KUNNR
AND BSID_S.ZUONR = BSID_H.ZUONR
AND BSID_S.WAERS = BSID_H.WAERS
INNER JOIN "T043T" AS T043T ON 1=1
AND BSID_S.BUKRS = T043T.BUKRS
WHERE 1=1
AND BSID_H.GROUP_MATCH_H IS NOT NULL AND BSID_S.GROUP_MATCH_S IS NOT NULL
-- Define here the tolerance levels from T043T. Add or remove as needed. The absolute value (BETRH) is used.
AND ((T043T.RFPRO = 'FIRST' AND ABS(BSID_H.WRBTR_SUM_H - BSID_S.WRBTR_SUM_S) <= T043T.BETRH)
OR (T043T.RFPRO = 'SECOND' AND ABS(BSID_H.WRBTR_SUM_H - BSID_S.WRBTR_SUM_S) <= T043T.BETRH)
OR (T043T.RFPRO = 'THIRD' AND ABS(BSID_H.WRBTR_SUM_H - BSID_S.WRBTR_SUM_S) <= T043T.BETRH))
GROUP BY BSID_H.GROUP_MATCH_H , BSID_S.GROUP_MATCH_S;


###### Data Job Scheduling

Once the data extraction and transformation jobs have been configured, you can add them to your existing data job schedules, or create a new schedule for them. In this way, you can ensure your open positions are automatically collected and aggregated in the "CLEARING" table, without any further manual intervention required. More information on scheduling can be found in the EMS help page.

###### Action Engine Skill

The Action Engine pulls all invoice groups identified in the above created table “CLEARING” and executes the corresponding SAP action.

Action Engine Skills work by scanning all relevant records (i.e. invoice groups) for certain rules and criteria whenever the underlying data model is reloaded. These Action Engine Skills trigger actions and automations that are defined in associated Studio Skills.

This action Engine Skill will check the "CLEARING" table for new customer invoice positions that can be cleared.

Signal ID

The Signal ID for the Action Engine Skill will be determined by the grouping defined in the data transformation job (above).

Customer Example

The Action Engine Skill identifies open customer positions grouped by company code ("BSID"."BUKRS"), customer number ("BSID"."KUNNR"), assignment number ("BSID"."ZUONR") and currency key ("BSID"."WAERS").

If the balance of these open positions is within the tolerances defined for the respective company code in the "T043T" table, the respective positions can be cleared and the Studio Skill is triggered. This Studio Skill executes BAPI or RFC calls to clear the relevant FI documents in SAP.

###### Skill Filters

No filters are required in this Skill, as the data transformation job defines the conditions for which clearing is available.

###### Studio Skill

Studio Skills define the actions and system automations that are performed against a record (e.g. sales order) when an Action Engine Skill is triggered.

This Studio Skill clears open invoice positions in SAP.

Customer Example

The Studio Skill is triggered by an Action Engine Skill when a customer’s open debit and credit positions, balanced against one another, fall within defined tolerance limits. The Studio Skill executes a BAPI or RFC call in the SAP system to clear the associated invoice positions.

###### Skill Configuration

Studio Skills are composed of a sensor and one or more actions performed in Celonis or connected IT systems. When an Action Engine Skill is triggered, the sensor executes the system actions defined in the associated Studio Skill. Usually, a combination of different types of actions are defined in the Studio Skill. These can be Celonis actions (query a data model, write data to a table or execute a machine learning script), system actions (apply data filters, process routers, or loops), ERP actions (remove a delivery block in SAP or update an account in Salesforce), communication actions (email a customer or Slack a colleague), and many others.

Below you will find the sequence of actions required to clear open FI documents in SAP.

1) Action Engine Sensor

The Action Engine sensor will execute the Studio Skill when the associated Action Engine Skill is triggered.

Example custom inputs:

• Customer account group ("KNA1"."KTOKD"): ${b1["customer account group"]} -- Defines the customer account group for the FI documents to be cleared • Posting date ("BSID"."BUDAT"):${b1["posting date"]}

-- Defines the posting date in the document

• Company code ("BSID"."BUKRS"): ${b1["company code"]} -- Defines the company code • Currency key ("BSID"."WAERS"):${b1["currency key"]}

-- Defines the currency key of the open positions

• Assignment number ("BSID"."ZUONR"): ${b1["assignment number"]} -- Defines the assignment number Additional remarks: • Based on your customer’s needs, further input fields may be required. 2) Execute SAP Action (Advanced) The Execute SAP Action (Advanced) step will trigger a BAPI or RFC call in SAP to create or change defined elements (delivery dates, payment terms, order details, etc.) of a business object (sales order, purchase order item, schedule line, etc.). Example function module: • /CELONIS/FI_F32 -- Clears already-posted customer accounts and positions Example input requirements: • Customer account group --${b1["customer account group"]} ("KNA1"."KTOKD")

• Posting date

-- ${b1["posting date"]} ("BSID"."BUDAT") • Company code --${b1["company code"]} ("BSID"."BUKRS")

• Currency key

-- ${b1["currency key"]} ("BSID"."WAERS") • Assignment number --${b1["assignment number"]} ("BSID"."ZUONR")