cancel
Showing results for 
Search instead for 
Did you mean: 

EVOLUTION OF STOCK QUERY

bradderz
Explorer
0 Kudos

Dear Experts.

I am currently in the mist of trying to develop a query in SAP Business one in the aim to display visibility based on the MRP and forecasts.

what i would like to be able to see is each item stored in the MRP senario is populated in the results across 3 lines and then the next 17 months (a column a month) display the SALES, PURCHASES AND STOCK VALUE an ensample of which i have enclosed below:

Part CodeOverview CategoryPriceItem GroupMarMar-24AprApr-24MayMay-24JunJun-24JulJul-24AugAug-24
TOY ASTOCK10GDX17.00170.0012.00120.0012.00120.0015.00150.0015.00150.0015.00150.00
TOY APURCHASES10GDX0.000.000.000.005.0050.000.000.000.000.000.000.00
TOY ASALES25GDX5.00125.000.000.003.0075.000.000.000.000.000.000.00

i have been playing with some logic ideas however i have been unsuccessful to this point. this is what i managed to come up with to commence my logic :

SELECT
MRP."ItemCode",
MRP."Month",
SUM(Sales."Quantity") AS SalesQuantity,
SUM(Purchases."Quantity") AS PurchasesQuantity,
SUM(Stock."Quantity" * Item."Price") AS StockValue
FROM
"MRP1" MRP
LEFT JOIN
"INV1" Sales ON MRP."ItemCode" = Sales."ItemCode" AND MRP."Month" = MONTH(Sales."DocDate")
LEFT JOIN
"OPOR" Purchases ON MRP."ItemCode" = Purchases."ItemCode" AND MRP."Month" = MONTH(Purchases."DocDate")
LEFT JOIN
"OITW" Stock ON MRP."ItemCode" = Stock."ItemCode" AND MRP."Month" = Stock."Month"
LEFT JOIN
"OITM" Item ON MRP."ItemCode" = Item."ItemCode"
GROUP BY
MRP."ItemCode", MRP."Month"
ORDER BY
MRP."ItemCode", MRP."Month"
Any assistance would be greatly appreciated.
Many thanks 

 

 

Accepted Solutions (1)

Accepted Solutions (1)

LoHa
Active Contributor
0 Kudos

Hi,

it seems that you use HANA. Normally in SQL i would say th best practice would be a pivot table but it is not avaiable in HANA but here is a workaround
https://community.sap.com/t5/technology-blogs-by-sap/how-to-pivot-unpivot-in-sap-hana/ba-p/13420392 

regards Lothar

bradderz
Explorer
0 Kudos
Thanks Loha

Answers (0)