SAP Business One document traceability is the difference between answering «let me check and I'll let you know» and answering «your order 4412 was dispatched on Tuesday in delivery 8871 and was invoiced yesterday with document 15330.» A company loses credibility in that pause. Therefore, the ability to reconstruct the complete chain of a document is not a technical luxury: it is a commercial competency.
The scenario repeats itself in every productive company. The sales department promises a date. The warehouse makes partial shipments. Finance invoices what it can. And three weeks later no one knows how much of the original order remained pending, nor why. The information exists in the database, yet it is fragmented into tables that only connect if you know exactly where to look.
In this tutorial you will learn to reconstruct that chain with SQL queries, both in SQL Server and SAP HANA. In addition, you will see how to detect process breaks: orders that age without shipment, deliveries that were never invoiced, and manually created documents that break traceability.

Why you need to master document traceability
The documentary chain is not an audit issue. It is a money issue. Below are four direct consequences I have seen in real implementations.
First, revenues that fall by the wayside. A shipped and unbilled delivery is merchandise that left your warehouse without generating an accounts receivable. In medium-volume companies, the accumulated amount usually surprises the finance management. For example, an industrial client detected eighty million pesos in unbilled deliveries over forty-five days old.
Second, unsupported commercial promises. If you cannot measure how long an order takes to become a delivery, your deadline commitment is an intuition, not a data point.
Third, invisible committed inventory. Open order lines reserve logical stock. Consequently, a forgotten order from eight months ago distorts your availability and your purchasing plan.
Fourth, processes that bypass controls. When someone creates an invoice without starting from a delivery, the company loses control of the physical shipment. In this way, traceability becomes an indicator of operational discipline.
The anatomy of the link: BaseEntry, BaseType and BaseLine
SAP Business One does not store the chain in a relationship table. Instead, each line of the child document has three fields that point to its origin. Understanding this is ninety percent of the work.
- BaseEntry: the DocEntry (internal key, not the visible number) of the base document.
- BaseType: the object code of the base document. If it is -1, the document was created without a base.
- Baseline: the exact line number of the base document. This field enables line-by-line traceability, not just document-to-document.
Furthermore, mirror fields exist Target Type and TargetEntry in line with the base document. However, here is the warning that saves hours of debugging: when an order line is shipped in multiple partial deliveries, TargetEntry only keeps one reference. Therefore, always trace back from the child, never forward from the parent. It is the rule that separates a correct query from one that calculates incorrectly.
Object codes you will need
These are the most used ObjTypes in the sales and purchasing chain:
- 23 Sales Quotation (OQUT / QUT1)
- 17 Customer order (ORDR / RDR1)
- 15 Delivery (ODLN / DLN1)
- 16 Return (ORDN / RDN1)
- 13 AR Invoice (OINV / INV1)
- 14 Credit Memo (ORIN / RIN1)
- 22 Purchase order (OPOR / POR1)
- 20 Goods Receipt (OPDN / PDN1)
- 18 A/P Invoice (OPCH / PCH1)
Prerequisites before running
You need three things. First, access to the Query Manager of SAP Business One (Tools, Queries, Query Generator) or to SAP HANA Studio. Second, read permissions on the marketing document tables. Third, knowing if your installation runs on Microsoft SQL Server the envelope SAP HANA, because the syntax changes.
A practical recommendation: never test a new query directly in production with open ranges. Always filter by date. This way, you avoid locking the database with a full table scan that in mature companies exceeds a million rows.
Query 1: the complete Order, Delivery, and Invoice chain
This is the base query for all traceability. It returns one row per order line and attaches, when they exist, their corresponding delivery and invoice.
SQL Server
-- Line-by-line traceability: Sales Order -> Delivery -> Invoice
SELECT
T0.DocNum AS [Order],
T0.DocDate AS [Order Date],
T0.CardName AS [Customer],
T1.ItemCode AS [Item],
T1.Dscription AS [Description],
T1.Quantity AS [Ordered Qty],
T1.OpenQty AS [Open Qty],
T3.DocNum AS [Delivery],
T3.DocDate AS [Delivery Date],
T2.Quantity AS [Shipped Qty],
T5.DocNum AS [Invoice],
T5.DocDate AS [Invoice Date],
T4.Quantity AS [Invoiced Qty],
DATEDIFF(DAY, T0.DocDate, T3.DocDate) AS [Days to Ship]
FROM ORDR T0
INNER JOIN RDR1 T1 ON T1.DocEntry = T0.DocEntry
LEFT JOIN DLN1 T2 ON T2.BaseEntry = T1.DocEntry
AND T2.BaseLine = T1.LineNum
AND T2.BaseType = 17
LEFT JOIN ODLN T3 ON T3.DocEntry = T2.DocEntry
LEFT JOIN INV1 T4 ON T4.BaseEntry = T2.DocEntry
AND T4.BaseLine = T2.LineNum
AND T4.BaseType = 15
LEFT JOIN OINV T5 ON T5.DocEntry = T4.DocEntry
WHERE T0.DocDate >= DATEADD(MONTH, -3, GETDATE())
AND T0.CANCELED = 'N'
ORDER BY T0.DocNum, T1.LineNum;
SAP HANA
-- Line-by-line traceability: Sales Order -> Delivery -> Invoice
SELECT
T0."DocNum" AS "Sales Order",
T0."DocDate" AS "Order Date",
T0."CardName" AS "Customer",
T1."ItemCode" AS "Item",
T1."Dscription" AS "Description",
T1."Quantity" AS "Ordered Qty",
T1."OpenQty" AS "Open Qty",
T3."DocNum" AS "Delivery",
T3."DocDate" AS "Delivery Date",
T2."Quantity" AS "Delivered Qty",
T5."DocNum" AS "Invoice",
T5."DocDate" AS "Invoice Date",
T4."Quantity" AS "Invoiced Qty",
DAYS_BETWEEN(T0."DocDate", T3."DocDate") AS "Days to Delivery"
FROM ORDR T0
INNER JOIN RDR1 T1 ON T1."DocEntry" = T0."DocEntry"
LEFT JOIN DLN1 T2 ON T2."BaseEntry" = T1."DocEntry"
AND T2."BaseLine" = T1."LineNum"
AND T2."BaseType" = 17
LEFT JOIN ODLN T3 ON T3."DocEntry" = T2."DocEntry"
LEFT JOIN INV1 T4 ON T4."BaseEntry" = T2."DocEntry"
AND T4."BaseLine" = T2."LineNum"
AND T4."BaseType" = 15
LEFT JOIN OINV T5 ON T5."DocEntry" = T4."DocEntry"
WHERE T0."DocDate" >= ADD_MONTHS(CURRENT_DATE, -3)
AND T0."CANCELED" = 'N'
ORDER BY T0."DocNum", T1."LineNum";
How to read it. LEFT JOINs are deliberate: if an order line has no delivery, it still appears with empty columns. Those exact rows are the ones management is interested in. Furthermore, the join to the invoice starts from the delivery, not the order, because that is how the standard SAP Business One workflow operates.
orders aging without shipping
The previous query shows the overview. However, management needs focus. This second query isolates open order lines that never generated a delivery and classifies them by age using a traffic light system.
SQL Server
-- Open sales order lines without any associated delivery
SELECT
T0.DocNum AS [Order],
T0.DocDate AS [Date],
T0.CardCode AS [Customer Code],
T0.CardName AS [Customer],
T1.ItemCode AS [Item],
T1.Dscription AS [Description],
T1.Quantity AS [Ordered Qty],
T1.OpenQty AS [Open Qty],
(T1.OpenQty * T1.Price) AS [Open Value],
DATEDIFF(DAY, T0.DocDate, GETDATE()) AS [Days Open],
CASE
WHEN DATEDIFF(DAY, T0.DocDate, GETDATE()) > 60 THEN 'CRITICAL'
WHEN DATEDIFF(DAY, T0.DocDate, GETDATE()) > 30 THEN 'WARNING'
ELSE 'NORMAL'
END AS [Traffic Light]
FROM ORDR T0
INNER JOIN RDR1 T1 ON T1.DocEntry = T0.DocEntry
WHERE T0.DocStatus = 'O'
AND T1.LineStatus = 'O'
AND T0.CANCELED = 'N'
AND NOT EXISTS (
SELECT 1 FROM DLN1 D
WHERE D.BaseEntry = T1.DocEntry
AND D.BaseLine = T1.LineNum
AND D.BaseType = 17)
ORDER BY DATEDIFF(DAY, T0.DocDate, GETDATE()) DESC;
SAP HANA
-- Open order lines without any associated delivery
SELECT
T0."DocNum" AS "Order",
T0."DocDate" AS "Date",
T0."CardCode" AS "Customer Code",
T0."CardName" AS "Customer",
T1."ItemCode" AS "Item",
T1."Dscription" AS "Description",
T1."Quantity" AS "Ordered Qty",
T1."OpenQty" AS "Open Qty",
(T1."OpenQty" * T1."Price") AS "Open Value",
DAYS_BETWEEN(T0."DocDate", CURRENT_DATE) AS "Days Open",
CASE
WHEN DAYS_BETWEEN(T0."DocDate", CURRENT_DATE) > 60 THEN 'CRITICAL'
WHEN DAYS_BETWEEN(T0."DocDate", CURRENT_DATE) > 30 THEN 'ALERT'
ELSE 'NORMAL'
END AS "Status Light"
FROM ORDR T0
INNER JOIN RDR1 T1 ON T1."DocEntry" = T0."DocEntry"
WHERE T0."DocStatus" = 'O'
AND T1."LineStatus" = 'O'
AND T0."CANCELED" = 'N'
AND NOT EXISTS (
SELECT 1 FROM DLN1 D
WHERE D."BaseEntry" = T1."DocEntry"
AND D."BaseLine" = T1."LineNum"
AND D."BaseType" = 17)
ORDER BY DAYS_BETWEEN(T0."DocDate", CURRENT_DATE) DESC;
Using NOT EXISTS instead of a LEFT JOIN with a null filter has a performance reason. Consequently, the engine stops the search as soon as it finds the first match, instead of materializing the entire join. In large tables, the difference is noticeable.

dispatched deliveries that were never invoiced
This query usually generates the most impact in the first meeting with finance. It detects merchandise that physically left the warehouse without becoming an accounts receivable.
SQL Server
-- Deliveries with open lines: dispatched and unbilled
SELECT
T0.DocNum AS [Delivery],
T0.DocDate AS [Delivery Date],
T0.CardCode AS [Customer Code],
T0.CardName AS [Customer],
SUM(T1.LineTotal) AS [Unbilled Amount],
COUNT(T1.LineNum) AS [Pending Lines],
DATEDIFF(DAY, T0.DocDate, GETDATE()) AS [Days Unbilled]
FROM ODLN T0
INNER JOIN DLN1 T1 ON T1.DocEntry = T0.DocEntry
WHERE T0.CANCELED = 'N'
AND T1.LineStatus = 'O'
AND ISNULL(T1.TargetType, -1) NOT IN (13, 14)
GROUP BY T0.DocNum, T0.DocDate, T0.CardCode, T0.CardName
HAVING SUM(T1.LineTotal) > 0
ORDER BY DATEDIFF(DAY, T0.DocDate, GETDATE()) DESC;
SAP HANA
-- Deliveries with open lines: dispatched and unbilled
SELECT
T0."DocNum" AS "Delivery",
T0."DocDate" AS "Delivery Date",
T0."CardCode" AS "Customer Code",
T0."CardName" AS "Customer",
SUM(T1."LineTotal") AS "Unbilled Amount",
COUNT(T1."LineNum") AS "Pending Lines",
DAYS_BETWEEN(T0."DocDate", CURRENT_DATE) AS "Days Unbilled"
FROM ODLN T0
INNER JOIN DLN1 T1 ON T1."DocEntry" = T0."DocEntry"
WHERE T0."CANCELED" = 'N'
AND T1."LineStatus" = 'O'
AND IFNULL(T1."TargetType", -1) NOT IN (13, 14)
GROUP BY T0."DocNum", T0."DocDate", T0."CardCode", T0."CardName"
HAVING SUM(T1."LineTotal") > 0
ORDER BY DAYS_BETWEEN(T0."DocDate", CURRENT_DATE) DESC;
Present these results sorted by age rather than by amount. For example, a payment of three hundred thousand pesos that has been outstanding for ninety days without an invoice indicates a much more serious process issue than one of five million pesos that has been outstanding for three days.
Query 4: Documents Created Without a Basis—The Silent Break
When a user creates a delivery or an invoice from scratch instead of copying it from the previous document, the chain is permanently broken. However, the system does not issue any alerts. This query exposes those cases.
SQL Server
-- Documents created without base document (process breaks)
SELECT
'Delivery' AS [Document Type],
T0.DocNum AS [Number],
T0.DocDate AS [Date],
T0.CardName AS [Business Partner],
T0.DocTotal AS [Total],
T0.UserSign AS [User ID]
FROM ODLN T0
WHERE T0.CANCELED = 'N'
AND T0.DocDate >= DATEADD(MONTH, -1, GETDATE())
AND NOT EXISTS (
SELECT 1 FROM DLN1 D
WHERE D.DocEntry = T0.DocEntry AND D.BaseType = 17)
UNION ALL
SELECT
'Invoice', T1.DocNum, T1.DocDate, T1.CardName, T1.DocTotal, T1.UserSign
FROM OINV T1
WHERE T1.CANCELED = 'N'
AND T1.DocDate >= DATEADD(MONTH, -1, GETDATE())
AND NOT EXISTS (
SELECT 1 FROM INV1 I
WHERE I.DocEntry = T1.DocEntry AND I.BaseType IN (15, 17))
ORDER BY 3 DESC;
SAP HANA
-- Documents created without a source document (process breaks)
SELECT
'Delivery' AS "Document Type",
T0."DocNum" AS "Number",
T0."DocDate" AS "Date",
T0."CardName" AS "Business Partner",
T0."DocTotal" AS "Total",
T0."UserSign" AS "User ID"
FROM ODLN T0
WHERE T0."CANCELED" = 'N'
AND T0."DocDate" >= ADD_MONTHS(CURRENT_DATE, -1)
AND NOT EXISTS (
SELECT 1 FROM DLN1 D
WHERE D."DocEntry" = T0."DocEntry" AND D."BaseType" = 17)
UNION ALL
SELECT
'Invoice', T1."DocNum", T1."DocDate", T1."CardName", T1."DocTotal", T1."UserSign"
FROM OINV T1
WHERE T1."CANCELED" = 'N'
AND T1."DocDate" >= ADD_MONTHS(CURRENT_DATE, -1)
AND NOT EXISTS (
SELECT 1 FROM INV1 I
WHERE I."DocEntry" = T1."DocEntry" AND I."BaseType" IN (15, 17))
ORDER BY 3 DESC;
The UserSign field allows you to cross-reference the OUSR table and name the pattern. However, do not use it as a punitive tool. In my experience, when a user bypasses the standard workflow, it is almost always because the formal process prevents them from meeting an urgent commitment. Therefore, the finding is a design signal, not bad faith.
Variations and use cases
The same logic carries over to other scenarios with minimal changes.
Purchasing chain. Replace ORDR with OPOR, RDR1 with POR1, DLN1 with PDN1, INV1 with PCH1 and BaseType 17 and 15 with 22 and 20. In this way you obtain traceability of purchase order, goods receipt and vendor invoice.
Chain from the offer. Add a previous level by linking RDR1 with QUT1 using BaseType 23. As a result, you can measure the actual quote-to-sale conversion rate.
Cycle time indicator. Group Query 1 by month and average the days between order and delivery. That number is your defensible commercial commitment.
Formatted search. Convert Query 3 into a counter and place it in a user-defined field in the business partner master data. This way, the salesperson can see the customer's documentary debt before taking a new order.

Best practices and common mistakes
Do not confuse DocNum with DocEntry. It is the number one error. DocNum is the visible number the user knows and it resets by series. DocEntry is the internal and unique key. The BaseEntry and TrgetEntry links always point to DocEntry. Consequently, if you join by DocNum, you will get seemingly correct and silently wrong results.
Always include BaseType in the JOIN. Two documents of different types can share the same DocEntry. Therefore, omitting BaseType produces cross-joins that are impossible to detect at first glance.
Filter out the canceled documents. The CANCELED field equal to ‘Y’ marks canceled documents that still physically remain in the table. In addition, check the DocStatus field to separate open from closed ones.
Be careful with manual locks. A user can close a line by right-clicking on it without having processed it. As a result, the line disappears from your pending reports even though the business commitment is still active. Cross-reference with the ADOC table or the change log if you need confirmation.
Do not add up quantities at the document level. Partial postings generate multiple children for the same parent line. However, if you group them incorrectly, you'll duplicate amounts. Always group by DocEntry and LineNum from the base document.
Filter by date in production. These queries span four or more high-volume tables. This helps ensure system performance during business hours.
Official SAP Resources
For further study, these are the resources you should keep on hand:
- SAP Business One Database Tables Reference: the official dictionary of tables and fields, available on the SAP Help Portal.
- SAP Business One SDK Help Center: Documents the object codes (BoObjectTypes) used in BaseType and TargetType.
- SAP Note on Document Relationshipsthe SAP customer Relationship Map visually displays the chain and is used to validate your query on a case-by-case basis.
- SAP CommunityThe ERP forum focuses on real-world cases regarding BaseEntry and partial shipments.
Conclusion: traceability is a management decision
The SAP Business One document traceability It is not solved by buying a module. It is solved by understanding three fields and deciding that the company is going to look at that data every week. The four queries in this tutorial cover eighty percent of the questions that a management committee asks about the commercial cycle.
Now then, the value is not in running them once. It is in turning them into a routine: Query 3 on Mondays with finance, Query 2 on Wednesdays with sales, Query 4 monthly with the process owner. This way, the ERP stops being a filing cabinet and starts behaving like a control system.
If your company still answers «let me check» when a customer asks about their order, the problem isn't the system. It's that nobody decided to read it.
Implement these queries this week and share the result of Query 3 with your finance management. It's the most profitable conversation you're going to have this month. In the Strategic Circle We continue publishing practical SAP Business One tutorials with production-ready code, for both SQL Server and HANA.




