on 07-14-2014 8:16 AM
Hi all,
I am trying to recreate the results of the Profit and Loss Statement so I can customize them for a user as they need to sort sales by customer group and territory. I have created a query but the trouble is that it doesn't seem to return the same value as the P&L statement. Are there any conditions I'm missing here?
This is my query:
SELECT GroupName [Group], Descript [Territory], SUM(Total) [Invoiced] FROM (
--Invoices
SELECT T2.[GroupName], T3.[descript], SUM(T0.[DocTotal]) [Total] FROM OINV T0 LEFT JOIN OCRD T1 ON T0.CardCode = T1.CardCode LEFT JOIN OCRG T2 ON T1.GroupCode = T2.GroupCode LEFT JOIN OTER T3 ON T1.Territory = T3.territryID WHERE T0.DocDate >= '20130701' AND T0.DocDate <= '20140630' GROUP BY T2.[GroupName], T3.[descript]
UNION ALL
--Credits
SELECT T2.[GroupName], T3.[descript], SUM(T0.[DocTotal]) * -1 [Total] FROM ORIN T0 LEFT JOIN OCRD T1 ON T0.CardCode = T1.CardCode LEFT JOIN OCRG T2 ON T1.GroupCode = T2.GroupCode LEFT JOIN OTER T3 ON T1.Territory = T3.territryID WHERE T0.DocDate >= '20130701' AND T0.DocDate <= '20140630' GROUP BY T2.[GroupName], T3.[descript]
) T GROUP BY GroupName, Descript ORDER BY GroupName, Descript
Is there a reason you're trying to do this in SQL, and not using the reports and transactions that already exist in the system? There are a bunch of out-of-the-box reports and queries in the Controlling module for profitability analysis and profit center accounting. Failing that, there are likely lots of flexible information structures in the SAP Query system (SQ01, SQ02, etc). You can probably get much better advice if you post your question in one of those application area forums, such as , or perhaps another like that.
Regards,
Matt
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.