Hi,
Tested with above query and transferred to total quantity to PO, not getting correct result. You may simplify the above query like below
SELECT sum(T1.[Quantity]) FROM ORDR T0
INNER JOIN RDR1 T1 ON T0.DocEntry = T1.DocEntry WHERE t0.docentry =
$[ORDR.docentry]
So, I would recommend to use system calculation for required quantity at the time of raising PO, if available quantity falls into negative.
Further system also includes committed quantity from sales and production order as well.
Thanks & Regards,
Nagarajan