In this first post of 2011 we are going to serve a query that will allow you, in case of company SAP B1 configured with perpetual inventory (stock continuous), get the weighted average cost price to a specific date. The purpose of this query is none other than knowing what the average price had an article on a given day.
It is therefore important to know that SAP B1 stores the input and output movements in the table OINM. From This yields the following query, which brings all movements generated to date, amount and value of stock divided by the total stock.
ROUND (SUM (CASE WHEN 0 THEN M. InQty M. CalcPrice -1 * ELSE * M. OutQty M. M. InQty CalcPrice * END), 2) AS [Value],
SUM (M. InQty)-SUM (M. OutQty) AS [Stock]
ROUND (ROUND (SUM (CASE WHEN 0 THEN InQty M. -1 * M. M. OutQty CalcPrice * ELSE
M. M. InQty CalcPrice * END), 2) / (SUM (M. InQty)-SUM (M. OutQty)), 2) AS [PMP]
FROM OINM M
OITW T0 INNER JOIN ON T0.ItemCode M. AND M. ItemCode = Warehouse = T0.WhsCode
INNER JOIN T1 ON OITM T0.ItemCode = T1.ItemCode
OWHS INNER JOIN T2 ON T2.WhsCode
T0.WhsCode = WHERE (M. ItemCode >='[% 2] 'or' [% 2 ]'='') AND (GROUP BY M. ItemCode <='[%3]' OR '[%3]'='') AND M.DocDate <= '[%1]'
T0.WhsCode, T2.WhsName, T0.ItemCode, T1.ItemName
ORDER BY T0. [WhsCode], T0. [ItemCode]
This example is passed as the date filter which we calculate the average price and a range of items. To add more filters just enough to add the fields in the WHERE clause of the query.
SEMICSince we want to emphasize that the behavior of this query is very similar to the standard report Inventory Audit , showing all movements into / out of stock and its value. In our case, the query simplifies the display by grouping all records and adding the PMP column, obtained by dividing the total amount between the amount accrued.
hope you find it useful.
0 comments:
Post a Comment