Last year we were working on a mid-sized manufacturing client running SAP S/4HANA. Their procurement team kept missing duplicate invoices — sometimes the same vendor invoice would slip through twice, sometimes a PO would get approved with values 40% above the agreed contract price. Classic data quality issues that nobody caught until month-end closing. We built an anomaly detection layer directly in ABAP Cloud on BTP, and it changed how their finance team works.
Background / Why This Matters Now
SAP S/4HANA gives you a lot of data but very little intelligence around detecting when something is wrong before it hits the books. Traditional approaches rely on month-end reports and manual spot checks. With ABAP Cloud on BTP and the AI services available through SAP AI Core, you can now build lightweight anomaly detection that runs inline — catching issues at the point of entry rather than weeks later.
Technical Deep Dive
The core of our solution was a custom ABAP Cloud class that hooks into the purchase order approval workflow via RAP (RESTful Application Programming Model). On each approval event, we extract key fields — vendor ID, amount, cost center, material group — and compare them against a statistical baseline we build from the last 90 days of approved POs.
CLASS zcl_anomaly_detector DEFINITION PUBLIC FINAL.
PUBLIC SECTION.
METHODS detect
IMPORTING iv_po_number TYPE ebeln
RETURNING VALUE(rv_score) TYPE decfloat16.
ENDCLASS.
CLASS zcl_anomaly_detector IMPLEMENTATION.
METHOD detect.
DATA(lo_po) = NEW zpo_reader( iv_po_number ).
DATA(lv_amount) = lo_po->get_total_amount( ).
DATA(lv_baseline) = zcl_baseline_cache=>get_avg(
vendor = lo_po->get_vendor( )
material_group = lo_po->get_material_group( )
).
rv_score = ABS( lv_amount - lv_baseline ) / lv_baseline.
ENDMETHOD.
ENDCLASS.
Any score above 0.35 triggers a soft block and routes the PO to a secondary approver. We tuned this threshold over two weeks of shadow mode before going live.
What I Have Seen Break in Production
The biggest issue we hit was baseline drift. In seasonal businesses, what looks normal in Q4 is completely different from Q1. Our first version flagged half of December as anomalous because the baseline was trained on Q3 data. We solved this by using a rolling 90-day window and adding a seasonality coefficient per cost center. The second issue was vendor master data quality — duplicate vendor numbers meant our per-vendor baselines were split across two records and neither had enough data to be reliable.
Practical Implementation Guide
-
Start with a single document type — invoice or PO, not both at once
-
Run in shadow mode for at least two weeks before enabling soft blocks
-
Build your baseline from at least 90 days of clean historical data
-
Add a manual override with a mandatory comment field — auditors will thank you
-
Log every anomaly score, not just the ones that trigger blocks
My Current Approach
For new clients I now start with a simplified Z-score approach in pure ABAP before considering any AI Core integration. It covers 80% of the use cases with zero external dependencies. Once that is stable and the business trusts the scores, we layer in the SAP AI Core embeddings for semantic similarity — catching things like slightly different vendor names that are actually the same supplier. The ABAP Cloud + BTP combination makes this much cleaner than the old on-premise approach where you needed a separate middleware layer.
If you are working on a similar project or exploring anomaly detection for SAP finance processes, reach out at Feel free to reach out at kerimakkis.com if you want to discuss this further.
If you found this useful, check out my other articles and projects at kerimakkis.com. I write about full-stack development, AI integration, and the tools I actually use in production.
-Photoroom.png)
