SAP Business One Pending Orders - featured image of the tutorial

Publications

SAP Business One Pending Orders: SQL Query to Control Your Backlog

Hector Pincheira

Hector Pincheira

CIO | CTO
Digital Strategy & Technology Innovation

items

SAP Business One Pending Orders is probably the report with the most money hidden in your database and the fewest people looking at it. I mean the order lines a customer already signed, lines that already consumed your commercial capacity, and that are still sitting there: not shipped, not invoiced, nobody owning them. The sales module shows them one by one. Nobody looks at them as a whole.

Some time ago I had to review the operation of a distribution company that swore it had a demand problem. Sales were flat, the sales team was demotivated and management was already talking about cuts. So we ran a query over ORDR and RDR1 that nobody had written before, and up came a hundred and forty open lines whose delivery date had passed more than two months earlier, several of them for products sitting in the warehouse. It was not a demand problem. It was a follow-up problem.

That is the point of this tutorial. Below you will build, step by step, the queries that turn your delivery backlog into a usable dashboard —sorry, into something your operations manager can actually work with on a Monday at nine in the morning— with versions for SQL Server and for SAP HANA.

Why your backlog deserves a report of its own

An open order is not neutral. It consumes committed stock, blocks availability for other customers, inflates your sales forecast and, above all, it ages. Meanwhile, the customer who placed it is waiting and drawing their own conclusions about your company.

The cost of that wait has been measured. The landmark study by Bain & Company and Earl Sasser in Harvard Business Review established that raising customer retention by 5% lifts profits between 25% and 95%, depending on the industry. On the other hand, according to PwC data published in its report Future of Customer Experience, one in three consumers walks away from a brand they like after a single bad experience. A shipment that ran forty days late is exactly that experience.

There is also an accounting angle that usually goes unnoticed. Old open lines distort your MRP, your inventory reservations and your forecast reports. If the order is never going to be delivered, the right move is to close it, not leave it floating so it contaminates every decision downstream. And closing dead orders requires, first, knowing which ones they are.

SAP Business One Pending Orders - delivery truck waiting to be loaded in the shipping yard
Every open line in ORDR is a shipment that has not left the yard yet.

Prerequisites

Before you start, make sure you have the following:

  • Access to the Query Generator (Tools → Queries → Query Generator) or to the SAP Business One Query Manager.
  • Read permissions on the ORDR, RDR1, OITW and OCRD tables. A user with «Read only» authorization in the query module is enough.
  • Know which engine you run: Microsoft SQL Server or SAP HANA. The syntax changes and both versions are here.
  • SAP Business One 9.2 or higher. The queries work the same way in version 10.
  • A test environment. Every new query is tested outside production first.

Step by step: base query for SAP Business One Pending Orders

Before the code it helps to understand the structure, because there is a trap here that catches almost everyone the first time.

Step 1: Understand the two levels of status

SAP Business One keeps the order status in two different places. The field ORDR.DocStatus tells you whether the whole document is open (‘O’) or closed (‘C’). The field RDR1.LineStatus does the same thing but line by line. An order with five lines where four have already shipped is still flagged as open in the header, even though only one line is truly pending.

If you filter by the header alone, your report will show lines that were already delivered as if they were still pending. You have to filter on both fields. This split between header and line is, in my view, one of the least intuitive design decisions in SAP B1, and everyone who writes reports pays for it.

Step 2: Identify the quantity fields

In RDR1 you have Quantity (what the customer ordered) and Open Qty (what is still to be delivered). The difference between the two is what has already shipped. To measure real backlog you always use Open Qty, never Quantity.

Step 3: Exclude cancelled documents

The field ORDR.CANCELED flags cancelled orders with ‘Y’. If you do not filter it out, orders nobody is waiting for will show up in your report and your backlog will come out inflated. This one has cost me dearly more than once: I presented a backlog report in a committee with 12% cancelled orders inside it and had to correct it at the next meeting, in front of the same people.

Step 4: Write the query

SQL Server

-- Detailed backlog: sales order lines pending delivery
SELECT
    T0.DocNum                                AS 'Pedido',
    T0.DocDate                               AS 'Fecha_Pedido',
    T0.CardCode                              AS 'Cod_Cliente',
    T0.CardName                              AS 'Cliente',
    T1.ItemCode                              AS 'Articulo',
    T1.Dscription                            AS 'Descripcion',
    T1.Quantity                              AS 'Cant_Pedida',
    T1.OpenQty                               AS 'Cant_Pendiente',
    T1.Price                                 AS 'Precio_Unitario',
    T1.OpenQty * T1.Price                    AS 'Monto_Pendiente',
    T1.ShipDate                              AS 'Fecha_Entrega_Comprometida',
    DATEDIFF(DAY, T1.ShipDate, GETDATE())    AS 'Dias_Atraso'
FROM ORDR T0
INNER JOIN RDR1 T1 ON T0.DocEntry = T1.DocEntry
WHERE T0.DocStatus  = 'O'
  AND T1.LineStatus = 'O'
  AND T0.CANCELED   = 'N'
ORDER BY T1.ShipDate ASC;

SAP HANA

-- Detailed backlog: sales order lines pending delivery
SELECT
    T0."DocNum"                                 AS "Pedido",
    T0."DocDate"                                AS "Fecha_Pedido",
    T0."CardCode"                               AS "Cod_Cliente",
    T0."CardName"                               AS "Cliente",
    T1."ItemCode"                               AS "Articulo",
    T1."Dscription"                             AS "Descripcion",
    T1."Quantity"                               AS "Cant_Pedida",
    T1."OpenQty"                                AS "Cant_Pendiente",
    T1."Price"                                  AS "Precio_Unitario",
    T1."OpenQty" * T1."Price"                   AS "Monto_Pendiente",
    T1."ShipDate"                               AS "Fecha_Entrega_Comprometida",
    DAYS_BETWEEN(T1."ShipDate", CURRENT_DATE)   AS "Dias_Atraso"
FROM ORDR T0
INNER JOIN RDR1 T1 ON T0."DocEntry" = T1."DocEntry"
WHERE T0."DocStatus"  = 'O'
  AND T1."LineStatus" = 'O'
  AND T0."CANCELED"   = 'N'
ORDER BY T1."ShipDate" ASC;

Run the query and save it under a clear name, for example VTA_Backlog_Detalle. A negative value in Dias_Atraso means the delivery is still within the agreed window; a positive value is a broken commitment.

Advanced SAP Business One Pending Orders query: ageing and stock coverage

The line-by-line detail is what the shipping team works with. However, for a management conversation you need something different: the backlog grouped by item, split into ageing buckets and compared against the stock you hold today. This way you separate three problems that usually get mixed up: what does not ship because there is no product, what does not ship because nobody shipped it, and what is simply not due yet.

SAP Business One Pending Orders - SQL query with a SELECT statement on screen
Filtering on LineStatus is the difference between a useful report and one that inflates the numbers.

SQL Server

-- Backlog by item, ageing buckets and stock coverage
SELECT
    T1.ItemCode                                   AS 'Articulo',
    MAX(T1.Dscription)                            AS 'Descripcion',
    SUM(T1.OpenQty)                               AS 'Pendiente_Total',
    SUM(T1.OpenQty * T1.Price)                    AS 'Monto_Pendiente',
    SUM(CASE WHEN DATEDIFF(DAY, T1.ShipDate, GETDATE()) <= 0
             THEN T1.OpenQty ELSE 0 END)          AS 'En_Plazo',
    SUM(CASE WHEN DATEDIFF(DAY, T1.ShipDate, GETDATE()) BETWEEN 1 AND 15
             THEN T1.OpenQty ELSE 0 END)          AS 'Atraso_1_15',
    SUM(CASE WHEN DATEDIFF(DAY, T1.ShipDate, GETDATE()) BETWEEN 16 AND 30
             THEN T1.OpenQty ELSE 0 END)          AS 'Atraso_16_30',
    SUM(CASE WHEN DATEDIFF(DAY, T1.ShipDate, GETDATE()) > 30
             THEN T1.OpenQty ELSE 0 END)          AS 'Atraso_Mas_30',
    ISNULL(T2.StockTotal, 0)                      AS 'Stock_Disponible',
    ISNULL(T2.StockTotal, 0) - SUM(T1.OpenQty)    AS 'Brecha'
FROM ORDR T0
INNER JOIN RDR1 T1 ON T0.DocEntry = T1.DocEntry
LEFT JOIN (SELECT ItemCode, SUM(OnHand) AS StockTotal
           FROM OITW GROUP BY ItemCode) T2
       ON T2.ItemCode = T1.ItemCode
WHERE T0.DocStatus  = 'O'
  AND T1.LineStatus = 'O'
  AND T0.CANCELED   = 'N'
GROUP BY T1.ItemCode, T2.StockTotal
ORDER BY SUM(T1.OpenQty * T1.Price) DESC;

SAP HANA

-- Backlog by item, ageing buckets and stock coverage
SELECT
    T1."ItemCode"                                      AS "Articulo",
    MAX(T1."Dscription")                               AS "Descripcion",
    SUM(T1."OpenQty")                                  AS "Pendiente_Total",
    SUM(T1."OpenQty" * T1."Price")                     AS "Monto_Pendiente",
    SUM(CASE WHEN DAYS_BETWEEN(T1."ShipDate", CURRENT_DATE) <= 0
             THEN T1."OpenQty" ELSE 0 END)             AS "En_Plazo",
    SUM(CASE WHEN DAYS_BETWEEN(T1."ShipDate", CURRENT_DATE) BETWEEN 1 AND 15
             THEN T1."OpenQty" ELSE 0 END)             AS "Atraso_1_15",
    SUM(CASE WHEN DAYS_BETWEEN(T1."ShipDate", CURRENT_DATE) BETWEEN 16 AND 30
             THEN T1."OpenQty" ELSE 0 END)             AS "Atraso_16_30",
    SUM(CASE WHEN DAYS_BETWEEN(T1."ShipDate", CURRENT_DATE) > 30
             THEN T1."OpenQty" ELSE 0 END)             AS "Atraso_Mas_30",
    IFNULL(T2."StockTotal", 0)                         AS "Stock_Disponible",
    IFNULL(T2."StockTotal", 0) - SUM(T1."OpenQty")     AS "Brecha"
FROM ORDR T0
INNER JOIN RDR1 T1 ON T0."DocEntry" = T1."DocEntry"
LEFT JOIN (SELECT "ItemCode", SUM("OnHand") AS "StockTotal"
           FROM OITW GROUP BY "ItemCode") T2
       ON T2."ItemCode" = T1."ItemCode"
WHERE T0."DocStatus"  = 'O'
  AND T1."LineStatus" = 'O'
  AND T0."CANCELED"   = 'N'
GROUP BY T1."ItemCode", T2."StockTotal"
ORDER BY SUM(T1."OpenQty" * T1."Price") DESC;

The column Brecha is the one that matters. When it comes out negative, you have nothing to fulfil with and the pending line is a supply problem. When it comes out positive and the line is late anyway, the product is in the warehouse and the order did not ship for an administrative reason: an approval stuck somewhere, a wrong address on file, a customer with blocked credit. That second group is the one that gets fixed quickly and almost nobody is watching it.

Useful variations for SAP Business One Pending Orders

Backlog by customer, in money

This version answers the question the sales manager asks: who are we letting down, and for how much money.

SQL Server

SELECT TOP 20
    T0.CardCode                                        AS 'Cod_Cliente',
    T0.CardName                                        AS 'Cliente',
    COUNT(DISTINCT T0.DocEntry)                        AS 'Pedidos_Abiertos',
    SUM(T1.OpenQty * T1.Price)                         AS 'Backlog_Valorizado',
    MIN(T1.ShipDate)                                   AS 'Compromiso_Mas_Antiguo',
    DATEDIFF(DAY, MIN(T1.ShipDate), GETDATE())         AS 'Dias_Esperando'
FROM ORDR T0
INNER JOIN RDR1 T1 ON T0.DocEntry = T1.DocEntry
WHERE T0.DocStatus  = 'O'
  AND T1.LineStatus = 'O'
  AND T0.CANCELED   = 'N'
GROUP BY T0.CardCode, T0.CardName
ORDER BY SUM(T1.OpenQty * T1.Price) DESC;

SAP HANA

SELECT
    T0."CardCode"                                           AS "Cod_Cliente",
    T0."CardName"                                           AS "Cliente",
    COUNT(DISTINCT T0."DocEntry")                           AS "Pedidos_Abiertos",
    SUM(T1."OpenQty" * T1."Price")                          AS "Backlog_Valorizado",
    MIN(T1."ShipDate")                                      AS "Compromiso_Mas_Antiguo",
    DAYS_BETWEEN(MIN(T1."ShipDate"), CURRENT_DATE)          AS "Dias_Esperando"
FROM ORDR T0
INNER JOIN RDR1 T1 ON T0."DocEntry" = T1."DocEntry"
WHERE T0."DocStatus"  = 'O'
  AND T1."LineStatus" = 'O'
  AND T0."CANCELED"   = 'N'
GROUP BY T0."CardCode", T0."CardName"
ORDER BY SUM(T1."OpenQty" * T1."Price") DESC
LIMIT 20;

Other cuts worth saving

  • By salesperson: add T0.SlpCode and join with OSLP. It lets each rep clean up their own pending portfolio.
  • By warehouse: group by T1.WhsCode and find out whether the delay is concentrated in a single warehouse.
  • Purchase orders: swap ORDR and RDR1 for OPOR and POR1. The field names are the same and you get your suppliers' backlog.
  • Pending with no movement: filter by T0.UpdateDate earlier than 30 days ago to isolate the orders nobody has touched.

Best practices and common mistakes

Use ShipDate, not DocDueDate. The field ORDR.DocDueDate is the due date of the header, whereas RDR1.ShipDate is the delivery commitment of each line. In orders with scheduled partial deliveries they are different dates, and only the second one reflects what the customer expects. This detail is in no manual; you learn it when a customer complains about a line your report was showing as on time.

Watch out for multicurrency. The field Price is in the document currency. If you sell in dollars and in pesos, adding them straight up gives you a meaningless number. In that case multiply by T0.DocRate or work with the system currency fields. If memory serves, in 9.3 the behaviour of DocRate for documents in local currency changed and several inherited reports had to be reviewed.

Close dead orders. A healthy backlog gets cleaned up. Set a policy: every line more than ninety days late is reviewed with the salesperson and closed manually (right-click on the line → Close) or rescheduled. Otherwise your MRP will keep planning purchases for phantom orders.

Do not run this at nine in the morning in production. The JOIN between ORDR and RDR1 over databases with years of history can be heavy. Schedule the report or narrow it with an order date filter.

Mistakes that keep repeating, in case you want to review your own version:

  • Filtering only by DocStatus = 'O' and forgetting LineStatus. Result: lines already delivered counted as pending.
  • using Quantity instead of Open Qty. Result: backlog inflated by everything already shipped.
  • Omitting CANCELED = 'N'. Result: cancelled orders inside the report.
  • Comparing OnHand without subtracting what is committed. If you need real availability, subtract IsCommited from OITW.
  • Presenting the backlog in units instead of money. A thousand units of a cheap input are not the same as ten units of expensive equipment.

One last warning, less technical. This report exposes work that was done badly, and that creates resistance. The first time you put it on the table, an explanation will appear for every single line. Present it as a sales recovery tool, not as a list of culprits, and you will have the team on your side by the second week.

Official SAP Resources

SAP Business One Pending Orders - truck on the road after clearing the delivery backlog
Cleaning up the backlog every week is what turns the report into results.

Conclusion: turn the backlog into a weekly routine

The queries you just built are worth nothing run once. They are worth something when they become routine: a report that lands every Monday at eight, with the detail for shipping and the valued summary for management, and a fifteen-minute meeting where every late line has an owner and a date. That boring grind is what moves the needle.

What you are doing, at bottom, is giving visibility to money your company already earned and has not collected yet. No sales campaign competes with that on effort-to-result. The order is already signed; it just needs to be delivered.

If you want to take it one step further, connect these queries to the SAP Business One alerts module so the system warns you automatically when a line goes past fifteen days late. You can also set them up as a SQL view and consume them from Crystal Reports or from your BI tool.

Did you implement this report in your company? What share of your backlog turned out to be recoverable? Tell me in the comments: I am especially interested in how many of those late orders had stock available. And if you want access to the rest of the SAP Business One technical tutorials with the full queries, I invite you to join the Círculo Estratégico at hectorpincheira.com.

Most Read

QlikSense Hierarchy: parent-child chart of accounts expanded by levels
QlikSense Hierarchy: the Chart of Accounts That Doesn't Add Up
QlikSense Sum TOTAL: share of each family over the total
QlikSense Sum TOTAL: the Percentage That Changes When You Filter
SAP Business One Inventory Revaluation - featured image of the tutorial
SAP Business One Inventory Revaluation: Fix Wrongly Loaded Costs
Empty chamber with wooden benches: the counterweight that required being present to be used
The Veto You Had to Say in Person: Your Decisions With No Counterweight
SAP Business One customizations - featured image of the pre-upgrade audit tutorial
SAP Business One Customizations: Pre-Upgrade Audit
SAP Business One Customer Concentration - featured image of the tutorial
SAP Business One Customer Concentration: Measure Your Risk with SQL

RELATED ARTICLES