Imagine your sales team closes a record sales month, but the Customer Service phone will not stop ringing with complaints about late or incomplete orders. You sold a lot, yes, but you delivered badly. That invisible gap between what you promise and what you fulfill is exactly what is measured by the indicator SAP Business One OTIF, one of the most underrated and yet most revealing metrics in any operation. In this tutorial you will learn to calculate it with SQL queries ready for SQL Server and SAP HANA, so you stop guessing your service level and start managing it with data.

What OTIF is and why it defines your commercial reputation
OTIF stands for On Time, In Full: on time and in full. It is an indicator that combines two questions your customers ask on every order. First, did it arrive when you promised? Second, did it arrive complete, with no shortages or last-minute changes? Only when both answers are yes does the order count as OTIF. Therefore, an order that arrives on time but with half the boxes does not count; and a complete one that arrives three days late does not either.
This harshness is deliberate. The customer does not reward partial effort: for them, an order is either well delivered or it is not. As a result, OTIF is one of the few metrics that looks at your operation through the customer's eyes, not your own. It also tends to correlate directly with repurchase and with customer churn, something no sales spreadsheet shows you.
Why you need to measure OTIF in your company
Many industrial and distribution companies operate under a dangerous illusion: they believe they deliver well because they «almost always» comply. However, «almost always» is not a number, and what is not measured is not managed. When you finally calculate your real OTIF, the result is usually a cold shower that, paradoxically, becomes the best compass for improvement.
The strategic value is clear. For example, a low OTIF makes your operation more expensive with urgent freight, rework and overtime nobody budgeted. It also quietly erodes customer trust, until one day the customer leaves without warning. By contrast, a high and stable OTIF becomes a commercial argument: you can promise compliance and prove it with data. In this way, the indicator stops being a logistics technicality and becomes a lever of competitiveness.

Prerequisites before starting
Before running the queries, it is worth being clear on a few points. That way you will avoid misleading results.
- Access to Query Manager or Query Generator in SAP Business One (Tools → Queries menu).
- A standardized sales process: Sales Order → Delivery. OTIF relies on deliveries being generated Desde the order, not as standalone documents.
- A reliable committed date. By default we will use the field Delivery date of the order (
DocDueDate). If your company negotiates dates line by line, further on you will see how to useRDR1.ShipDate. - Knowing your database engine: SQL Server or SAP HANA. That is why each query comes in both versions.
Step-by-step tutorial: how to measure OTIF in SAP Business One
We will build the analysis on three levels, from the particular to the general. First, the order-by-order detail. Next, the consolidated KPI for the period. Finally, the ranking by customer to spot where the pain is concentrated.
Step 1: Identify the key tables
The delivery process in SAP Business One lives in four tables. Sales orders are in ORDER (header) and RDR1 (lines). Deliveries are in ODLN (header) and DLN1 (lines). The link between the two documents is the key: each delivery line stores in DLN1 the fields BaseEntry, Baseline and BaseType = 17, which point exactly to the order line that originated it. Thanks to that link we can compare what was promised with what was fulfilled.
Step 2: OTIF detail by order
This first query evaluates each closed order in the period and flags, with a simple YES or NO, whether it was on time and whether it was complete. It is the level where your shipping team can take concrete action.
SQL Server
-- OTIF detail by order (SQL Server)
SELECT
T0.DocNum AS "Pedido",
T0.CardCode AS "Cliente",
T0.CardName AS "Nombre",
T0.DocDueDate AS "Fecha Comprometida",
MAX(T2.DocDate) AS "Ultima Entrega",
SUM(T1.Quantity) AS "Cant Pedida",
SUM(T1.Quantity - T1.OpenQty) AS "Cant Entregada",
CASE WHEN MAX(T2.DocDate) <= T0.DocDueDate
THEN 'SI' ELSE 'NO' END AS "On Time",
CASE WHEN SUM(T1.OpenQty) = 0
THEN 'SI' ELSE 'NO' END AS "In Full"
FROM ORDR T0
INNER JOIN RDR1 T1 ON T1.DocEntry = T0.DocEntry
LEFT JOIN DLN1 L1 ON L1.BaseType = 17
AND L1.BaseEntry = T1.DocEntry
AND L1.BaseLine = T1.LineNum
LEFT JOIN ODLN T2 ON T2.DocEntry = L1.DocEntry
WHERE T0.DocDate BETWEEN '[%0]' AND '[%1]'
GROUP BY T0.DocNum, T0.CardCode, T0.CardName, T0.DocDueDate
ORDER BY T0.DocDueDate;
SAP HANA
-- OTIF detail by order (SAP HANA)
SELECT
T0."DocNum" AS "Pedido",
T0."CardCode" AS "Cliente",
T0."CardName" AS "Nombre",
T0."DocDueDate" AS "Fecha Comprometida",
MAX(T2."DocDate") AS "Ultima Entrega",
SUM(T1."Quantity") AS "Cant Pedida",
SUM(T1."Quantity" - T1."OpenQty") AS "Cant Entregada",
CASE WHEN MAX(T2."DocDate") <= T0."DocDueDate"
THEN 'SI' ELSE 'NO' END AS "On Time",
CASE WHEN SUM(T1."OpenQty") = 0
THEN 'SI' ELSE 'NO' END AS "In Full"
FROM ORDR T0
INNER JOIN RDR1 T1 ON T1."DocEntry" = T0."DocEntry"
LEFT JOIN DLN1 L1 ON L1."BaseType" = 17
AND L1."BaseEntry" = T1."DocEntry"
AND L1."BaseLine" = T1."LineNum"
LEFT JOIN ODLN T2 ON T2."DocEntry" = L1."DocEntry"
WHERE T0."DocDate" BETWEEN '[%0]' AND '[%1]'
GROUP BY T0."DocNum", T0."CardCode", T0."CardName", T0."DocDueDate"
ORDER BY T0."DocDueDate";
Look at the logic. The column On Time compares the date of the last delivery against the committed date; if the delivery happened on or before that date, the order was on time. Meanwhile, In Full checks that no open quantity is left (Open Qty): if everything was delivered, the order was complete. As a result, one glance is enough to know which orders met both conditions.
Step 3: The consolidated OTIF KPI for the period
The detail is useful for acting, but management needs a single number that summarizes performance. Therefore, the following query wraps the previous logic in a subquery and calculates the overall OTIF percentage.
SQL Server
-- Consolidated OTIF KPI (SQL Server)
SELECT
COUNT(*) AS "Total Pedidos",
SUM(P.OnTimeFlag) AS "A Tiempo",
SUM(P.InFullFlag) AS "Completos",
SUM(CASE WHEN P.OnTimeFlag = 1 AND P.InFullFlag = 1
THEN 1 ELSE 0 END) AS "Pedidos OTIF",
CAST(100.0 * SUM(CASE WHEN P.OnTimeFlag = 1 AND P.InFullFlag = 1
THEN 1 ELSE 0 END) / COUNT(*)
AS DECIMAL(5,2)) AS "OTIF %"
FROM (
SELECT
T0.DocEntry,
CASE WHEN MAX(T2.DocDate) <= T0.DocDueDate THEN 1 ELSE 0 END AS OnTimeFlag,
CASE WHEN SUM(T1.OpenQty) = 0 THEN 1 ELSE 0 END AS InFullFlag
FROM ORDR T0
INNER JOIN RDR1 T1 ON T1.DocEntry = T0.DocEntry
LEFT JOIN DLN1 L1 ON L1.BaseType = 17
AND L1.BaseEntry = T1.DocEntry
AND L1.BaseLine = T1.LineNum
LEFT JOIN ODLN T2 ON T2.DocEntry = L1.DocEntry
WHERE T0.DocDate BETWEEN '[%0]' AND '[%1]'
GROUP BY T0.DocEntry, T0.DocDueDate
) P;
SAP HANA
-- Consolidated OTIF KPI (SAP HANA)
SELECT
COUNT(*) AS "Total Pedidos",
SUM(P."OnTimeFlag") AS "A Tiempo",
SUM(P."InFullFlag") AS "Completos",
SUM(CASE WHEN P."OnTimeFlag" = 1 AND P."InFullFlag" = 1
THEN 1 ELSE 0 END) AS "Pedidos OTIF",
CAST(100.0 * SUM(CASE WHEN P."OnTimeFlag" = 1 AND P."InFullFlag" = 1
THEN 1 ELSE 0 END) / COUNT(*)
AS DECIMAL(5,2)) AS "OTIF %"
FROM (
SELECT
T0."DocEntry",
CASE WHEN MAX(T2."DocDate") <= T0."DocDueDate" THEN 1 ELSE 0 END AS "OnTimeFlag",
CASE WHEN SUM(T1."OpenQty") = 0 THEN 1 ELSE 0 END AS "InFullFlag"
FROM ORDR T0
INNER JOIN RDR1 T1 ON T1."DocEntry" = T0."DocEntry"
LEFT JOIN DLN1 L1 ON L1."BaseType" = 17
AND L1."BaseEntry" = T1."DocEntry"
AND L1."BaseLine" = T1."LineNum"
LEFT JOIN ODLN T2 ON T2."DocEntry" = L1."DocEntry"
WHERE T0."DocDate" BETWEEN '[%0]' AND '[%1]'
GROUP BY T0."DocEntry", T0."DocDueDate"
) P;
Besides the OTIF percentage, the result gives you the components separately: how many orders arrived on time and how many complete. That separation is valuable, because it tells you where your chain fails. For example, if your «On Time» is high but your «Complete» is low, the problem is not transport but supply or inventory.

Step 4: OTIF ranking by customer
Not every customer suffers equally. That is why the third query groups the indicator by customer and sorts from worst to best, with a minimum of five orders so the sample is representative. That way you identify who you are failing first.
SQL Server
-- OTIF by customer (SQL Server)
SELECT
P.CardCode AS "Cliente",
P.CardName AS "Nombre",
COUNT(*) AS "Pedidos",
CAST(100.0 * SUM(CASE WHEN P.OnTimeFlag = 1 AND P.InFullFlag = 1
THEN 1 ELSE 0 END) / COUNT(*)
AS DECIMAL(5,2)) AS "OTIF %"
FROM (
SELECT
T0.DocEntry, T0.CardCode, T0.CardName,
CASE WHEN MAX(T2.DocDate) <= T0.DocDueDate THEN 1 ELSE 0 END AS OnTimeFlag,
CASE WHEN SUM(T1.OpenQty) = 0 THEN 1 ELSE 0 END AS InFullFlag
FROM ORDR T0
INNER JOIN RDR1 T1 ON T1.DocEntry = T0.DocEntry
LEFT JOIN DLN1 L1 ON L1.BaseType = 17
AND L1.BaseEntry = T1.DocEntry
AND L1.BaseLine = T1.LineNum
LEFT JOIN ODLN T2 ON T2.DocEntry = L1.DocEntry
WHERE T0.DocDate BETWEEN '[%0]' AND '[%1]'
GROUP BY T0.DocEntry, T0.CardCode, T0.CardName, T0.DocDueDate
) P
GROUP BY P.CardCode, P.CardName
HAVING COUNT(*) >= 5
ORDER BY "OTIF %" ASC;
SAP HANA
-- OTIF by customer (SAP HANA)
SELECT
P."CardCode" AS "Cliente",
P."CardName" AS "Nombre",
COUNT(*) AS "Pedidos",
CAST(100.0 * SUM(CASE WHEN P."OnTimeFlag" = 1 AND P."InFullFlag" = 1
THEN 1 ELSE 0 END) / COUNT(*)
AS DECIMAL(5,2)) AS "OTIF %"
FROM (
SELECT
T0."DocEntry", T0."CardCode", T0."CardName",
CASE WHEN MAX(T2."DocDate") <= T0."DocDueDate" THEN 1 ELSE 0 END AS "OnTimeFlag",
CASE WHEN SUM(T1."OpenQty") = 0 THEN 1 ELSE 0 END AS "InFullFlag"
FROM ORDR T0
INNER JOIN RDR1 T1 ON T1."DocEntry" = T0."DocEntry"
LEFT JOIN DLN1 L1 ON L1."BaseType" = 17
AND L1."BaseEntry" = T1."DocEntry"
AND L1."BaseLine" = T1."LineNum"
LEFT JOIN ODLN T2 ON T2."DocEntry" = L1."DocEntry"
WHERE T0."DocDate" BETWEEN '[%0]' AND '[%1]'
GROUP BY T0."DocEntry", T0."CardCode", T0."CardName", T0."DocDueDate"
) P
GROUP BY P."CardCode", P."CardName"
HAVING COUNT(*) >= 5
ORDER BY "OTIF %" ASC;
Variations and use cases
The base model is flexible. Below are some frequent adaptations depending on each company's reality.
Commitment by line, not by header. If you negotiate different dates per product, replace T0.DocDueDate by T1.ShipDate (the committed date of each line in RDR1). This way your OTIF reflects real agreements and not a document average.
Day tolerance. Some companies accept a margin, for example one day of grace. In that case adjust the condition to MAX(T2.DocDate) <= DATEADD(DAY, 1, T0.DocDueDate) in SQL Server, or ADD_DAYS(T0."DocDueDate", 1) in HANA.
Monthly OTIF for trend. Group by month with MONTH(T0.DocDate) (SQL Server) o MONTH(T0."DocDate") (HANA) to chart the evolution and spot seasonality or deterioration.
Best practices and common mistakes
The technique is only half the job. The other half is interpreting it well. These, for example, are the stumbles I see most often in the field.
First, do not confuse the posting date with the physical delivery date. If your company records the Delivery days after the actual shipment, your OTIF is distorted; therefore, define a clear and consistent rule. Second, beware of orders cancelled or closed manually: they can artificially inflate «In Full» if they end up with no open quantity without ever having been delivered. That is why it is worth filtering by Document Status depending on your process.
Also, do not chase 100% OTIF. A realistic target for industrial companies is usually between 92% and 98%; chasing absolute perfection can cost more than it contributes. Finally, the worst mistake is measuring and not acting: OTIF only creates value when someone, every month, reviews the ranking by customer and attacks the root cause.
Official SAP Resources
To go deeper, it helps to lean on the official documentation. The SAP Help Portal for SAP Business One documents the structure of sales and delivery documents. Likewise, the SAP Community community keeps active forums on queries and reports where variations of these analyses are discussed.
Conclusion: from promise to measurable fulfillment
The indicator SAP Business One OTIF turns a fuzzy perception —»I think we deliver well»— into a number you can manage, compare and improve month after month. More than a logistics metric, it is a mirror that shows whether your company delivers what its sales team promises. As a result, it is one of the indicators that most quickly lifts the management conversation from «how much did we sell» to «how much did we fulfill».
My recommendation is concrete: run the consolidated query today over the last three months and find out your real number. Then share the ranking by customer with your operations team and pick a single root cause to attack this month. If you want to turn these queries into a live control dashboard inside your SAP Business One, that is the natural next step, and it is exactly the kind of transformation that separates a company that reacts from one that anticipates.




