Hello Ravi,
The format of your query is not right and hard to understand. I suggest you have a look at it and format it as I did with the first part of your query:
SELECT
T.ItmsGrpNam
, T.ItemCode
, T.ItemName
, SUM(T.OpeningQty)
, SUM(T.OpeningVal)
, SUM(T.InQty)
, SUM(T.InVal)
, SUM(T.OutQty)
, SUM(T.OutVal)
, SUM(T.ClosingQty)
, SUM(T.ClosingVal)
FROM
(SELECT
T2.ItmsGrpNam
, T1.ItemCode
, T1.ItemName
, SUM(T0.InQty - T0.OutQty) OpeningQty
, SUM
(CASE
WHEN T0.OutQty>0
THEN T0.TransValue
ELSE T0.TransValue
END) OpeningVal
, 0.00 InQty
, 0.00 InVal
, 0.00 OutQty
, 0.00 OutVal
, 0.00 ClosingQty
, 0.00 ClosingVal
FROM OINM T0
INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode
INNER JOIN OITB T2 ON T1.ItmsGrpCod = T2.ItmsGrpCod
WHERE T0.DocDate < 01012016 and (T0.Warehouse = '01' or '02' = 'ALL')
GROUP BY T2.ItmsGrpNam, T1.ItemCode, T1.ItemName) T
GROUP BY T.ItmsGrpNam, T.ItemCode, T.ItemName
You see that it is much more clearer to understand.
Also, when testing, do not use SAP variables ([%0], etc) but use hard values. You will notice that your WHERE statements are not working. And build your query's in the SQL Management Studio and when ready copy them to SAP.
I suggest you have a look at the rest of your query this way to resolve the errors.
Kind regards,
Andy Grootens
Asecom