Methods of Running Total calculation in ABAP CDS views
The post is dedicated a of important aspect of reporting – calculating of Running Total or Cumulative Key Figures.
There is an example of cumulative amount key figure by fiscal year periods:
I could propose 3 methods of realization the calculation behavior in ABAP CDS views:
- Use SQL windows functions in ABAP CDS views based on Table Function.You could find technical step-by-step procedure in blog. Idea of running total calculation is similar to described in blog within HANA Calculation Views.
- Use basic view with parameters and union of many select statements in composite view. If we have 12 time periods there will be union of 12 select statements.
- Use join with special view that will multiply posting rows correctly for cumulative key figure calculation. The last, but I hope not the least, calculation method this post is about.
1.I am going to use “Universal Journal Entry” (ACDOCA) table in S/4HANA for demonstration purpose. This is basic view for financial postings selections:
2. Special view that we are going to join with:
I use standard view with company code field in key part just for demo purpose. Different company codes could have different fiscal variants and different number of periods (as I know). Hope it doesn’t make example to complicated. Total number of rows generated for one company code and 16 periods is 136 (sum of arithmetic progression).
3. New join in basic view was created:
4. Create other view with filtration and aggregation for demo purpose. In real life solution we could create cube view and needed analytical query views.
Data preview by only one document position. It was posted in 007 period of 2017 year.
Data preview by only 1 position of all documents.
Cumulative amount key figure is working correctly!
Main methods of running total calculation were discussed.
One method “with join” was considered in detail.
If more difficult calculations are needed, then RealRowFlag could help to distinguish between cumulative and normal keys figures and combine them accordingly.
Thank you for attention!