on 09-29-2015 6:06 AM
Good Morning Experts,
Can you help me, i want create a query, which gives the sames results.
actual Stock, Incomming, Outgoing, order by Date
Thanks for your help.
Hi Markus,
There is a simple solution:
SELECT (OnHand - IsCommited + OnOrder) AS ATP FROM OITM
However if you need to take dates into account (when will new stock arrive, etc) or other logic (for example: first come first serve), then it gets more complicated, and you would have to describe in more detail what you need
Regards,
Johan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Johan, Hi Nagarajan,
I need this query for our Sales-Dept. because we have a Database für Sales and a Database for Production, so they can Start Query in Sales-Database, and the Calculations/Results are comming from Production-Database. (Sales Database doesn't have an own Stock)
Next time, I try to make some Queries with a UNION ALL
1. STOCK (Onhand)
2. Incomming from Purchase
3. Outgoing for Sales
4. Incomming from Production
5. Outgoing for Production (If Child-Item can be Sold, too)
If I have a query ready, I'll share it.
Thanks
Hi Markus,
Ok, please let us know if we can help you.
A few tips for developing this query:
Regards,
Johan
Hi again.
here is my first Query, but there I haven't a calculation of the Availible-Quantity...
Can you help me to get this, same as ATP-Function ?
I need this query for FMS...
SELECT 'Stock 01' AS Type,'' AS Source, | ||
'0' as 'Outgoing', '0' as 'Incomming', | ||
T0.onHand AS SALDO, '2000-01-01 00:00:000' AS Date, | ||
'' as 'Customer', '' as 'INTERN' | ||
FROM OITW T0 | ||
WHERE T0.ItemCode = '$[OITM.ItemCode]' AND T0.WhsCode IN ('01') | ||
UNION ALL | ||
SELECT CASE WHEN T0.Status = 'P' THEN 'Incomming from Prod - planned' ELSE 'Incomming from Prod' END AS Type ,T0.DocNum AS Source, | ||
'0', CASE WHEN (T0.PlannedQty - T0.CmpltQty) < '0' THEN '0' ELSE (T0.PlannedQty - T0.CmpltQty)END , | ||
CASE WHEN (T0.PlannedQty - T0.CmpltQty) < '0' THEN '0' ELSE (T0.PlannedQty - T0.CmpltQty)END AS SALDO, CONVERT(DATETIME,T0.DueDate, 104) AS Date, '', 'Stock' | ||
FROM OWOR T0 | ||
WHERE T0.ItemCode = '$[OITM.ItemCode]' AND T0.Status NOT IN ('L','C') and T0.Warehouse = '01' | ||
UNION ALL | ||
SELECT 'Eingang aus Einkauf'AS Type,T0.DocNum AS Source, | ||
'0', T1.OpenQty, | ||
T1.OpenQty AS SALDO, CONVERT(DATETIME,T1.ShipDate, 104) AS Date, '', 'Stock' | ||
FROM OPOR T0 | ||
INNER JOIN POR1 T1 ON T0.DocEntry = T1.DocEntry | ||
WHERE T1.ItemCode = '$[OITM.ItemCode]' AND T1.LineStatus = 'O' | ||
UNION ALL | ||
SELECT 'Outgoing for Production' AS Type, T0.DocNum AS Source, | ||
(T1.PlannedQty - T1.IssuedQty)*-1, '0', | ||
(T1.PlannedQty - T1.IssuedQty)*-1 AS SALDO, Date = | ||
CASE 'Y' | ||
WHEN 'Y' THEN CONVERT(DATETIME,T1.U_BXPDueDt, 104) | ||
ELSE | ||
CASE ISNull(T2.LeadTime,0) | ||
WHEN 0 THEN CONVERT(DATETIME,T0.DueDate, 104) | ||
ELSE DATEADD(day,T2.LeadTime,CONVERT(DATETIME,T0.DueDate, 104)) | ||
END | ||
END, '', 'Production' | ||
FROM OWOR T0 | ||
INNER JOIN WOR1 T1 ON T0.DocEntry = T1.DocEntry | ||
INNER JOIN OITM T2 ON T0.ItemCode = T2.ItemCode | ||
WHERE T1.ItemCode = '$[OITM.ItemCode]' AND T0.Status NOT IN ('L','C') and T1.wareHouse = '01' | ||
UNION ALL | ||
SELECT 'Outgoing Customer' AS Type, T0.U_BaseDocNum AS Source, | ||
T1.OpenQty * -1, '0', | ||
T1.OpenQty * -1 AS SALDO, CONVERT(DATETIME,T1.ShipDate, 104) AS Date, | ||
T0.U_CustCardName, '' | ||
FROM ORDR T0 | ||
INNER JOIN RDR1 T1 ON T0.DocEntry = T1.DocEntry | ||
WHERE T1.ItemCode = '$[OITM.ItemCode]' AND T1.LineStatus = 'O' | ||
order by date |
Thank you very much for help.
Markus
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Markus,
The OITM and OITW tables both have OnHand (actual stock), OnOrder (open purchase order rows), and Commited (open sales order rows) columns.
Usually to get Available, you would simply calculate (OnHand + OnOrder) - Commited.
But because your query includes purchase, sales and production data through UNION statements each with their own filters, I am not entirely sure what "available" means exactly in your scenario.
Regards,
Johan
Hello Johan,
thanks for your message. I'll try to explain what I mean.
For example:
ATP-Function from SAP:
For each row, I have the availible Qty, suitable to each Delivery-date
Calculation in Excel:
I'm looking for a solution, to calculate the "red" quantities in my Query... dependent from my Warehouse # 01.
Result of Query - without the new column "availible at Date"
I hope, you understand it now better ?
Thx
Markus
Hi Markus,
Ok, this will probably need some testing, but you could use an embedded query.
You said you wanted to use this query in an FMS. Do you mean that you need a query result with a single value ?
What I mean is, the parameters are the ItemCode and a date, and your result tells you only what the available saldo is on that date ?
Or do you need the list as in your middle screenshot ?
Regards,
Johan
User | Count |
---|---|
99 | |
11 | |
11 | |
6 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.