Sub topic 4
A simpler data model: fewer tables, no stored aggregates
What this chapter covers
The previous chapter introduced SAP HANA as the required database. This chapter looks at what SAP changed in the data model because of that database. You should already know FI, CO, MM and SD at a basic level and understand what a database table is. You should also know that custom ABAP code reads and writes those tables.
After this chapter you should be able to:
- Explain what an aggregate table is and why ECC stored them.
- Describe how S/4HANA replaces stored aggregates with calculation at read time.
- Recognize the three kinds of simplification: removed aggregates, merged tables, and compatibility views.
- Predict which kinds of custom code are affected.
The next chapters cover the Universal Journal, Business Partner and material documents in detail. Here we look at the principle they share.
Why ECC stored aggregates
ECC 6.0 ran on several databases, including Oracle, IBM Db2 and Microsoft SQL Server. These were row-oriented, disk-based databases. Summing millions of line items on every report request was too slow on them. SAP's answer was to store precomputed totals next to the line items.
An aggregate table holds sums that could be calculated from other tables. Typical ECC examples:
- Totals per account and period in finance, such as GLT0 and FAGLFLEXT.
- Customer and vendor balances per period, such as KNC1 and LFC1.
- Controlling totals, such as COSP and COSS.
- Stock quantities and values per material and plant, such as MARD and MBEW.
Every posting updated the line item table and then each aggregate table. A reporting transaction read the small aggregate table and skipped the large one. This design has costs:
- Redundancy. The same facts are stored several times, in different shapes.
- Reconciliation. Totals in one module can disagree with line items in another. Many projects ran reconciliation reports between FI and CO.
- Posting load. Each posting writes to several tables, so locks and update tasks are more complex.
- Rigid reporting. An aggregate answers only the question it was built for. A new grouping needs a new table or a trip to the line items.
What changes in S/4HANA
SAP HANA keeps data in memory and stores tables by column. A sum over one column of millions of rows is fast, so the performance reason for stored aggregates mostly disappears. S/4HANA applies the principle "store the facts once, calculate the totals when asked."
In practice this means the data model changes in three ways:
- Aggregates are removed. The table no longer holds data. Totals come from the line items.
- Tables are merged. Data that used to be spread over several tables is held in one wider table.
- Compatibility views keep old reads working. A view with the old table's name and structure computes its content from the new tables.
The three kinds of change in detail
Removed aggregates
In finance, GLT0 and similar total tables are no longer filled. The totals are derived from ACDOCA, the Universal Journal. The same applies to customer and vendor totals and to many Controlling totals. Stock quantities are derived from material document items instead of being updated in stock tables on each movement.
You can verify this in a system. Run a SELECT SINGLE on an old aggregate table and compare it with the line item sum. Where the table has become a view, the result matches the line items by construction.
Merged tables
Some data that ECC split into separate tables is now stored together. The best-known examples, covered in later chapters, are:
- Finance line items from FI, CO, Asset Accounting and Material Ledger in ACDOCA.
- Material document header and item data in MATDOC, in place of MKPF and MSEG as the physical store.
- Customer and vendor master data under the Business Partner model.
The benefit is a single source for each fact. A balance in FI and the matching amount in CO now come from the same row, so there is nothing to reconcile.
Compatibility views
SAP could not break every report and custom program on day one. For many removed tables it provides a compatibility view, a database view that reproduces the old table structure from the new data. Existing SELECT statements keep working.
This has limits that you must understand:
- Read only. You cannot insert, update or delete through the view. Custom code that writes directly to a former aggregate table will fail or have no effect. Direct writes to standard tables were never supported, but they exist in some systems.
- Calculation cost. Each read computes totals. A view over a large table is fast on HANA, but not free. A program that calls it in a loop for every record can be slower than expected.
- Not every table has a view. Some tables were removed with no equivalent, and SAP documents the replacement in the Simplification Item Catalog.
Reading a balance from line items
The following report calculates account balances from the Universal Journal. It does not use any aggregate table.
REPORT zdemo_balances.
PARAMETERS p_bukrs TYPE bukrs DEFAULT '1000'.
PARAMETERS p_gjahr TYPE gjahr DEFAULT '2024'.
START-OF-SELECTION.
SELECT racct, SUM( hsl ) AS balance
FROM acdoca
WHERE rldnr = '0L'
AND rbukrs = @p_bukrs
AND gjahr = @p_gjahr
GROUP BY racct
ORDER BY racct
INTO TABLE @DATA(lt_balances).
cl_demo_output=>display( lt_balances ).Points to notice:
rldnr = '0L'selects the leading ledger. Without it, you would add up lines from several ledgers.SUM( hsl )adds the amount in company code currency. The database does the work, and the application server receives only one row per account.- Changing the grouping, for example to cost center or profit center, only means changing the field list and
GROUP BY. No new aggregate table is needed.
Keep the aggregation in the SQL statement. Reading all line items into an internal table and summing them in a loop moves a large amount of data over the network and gives up the speed of HANA.
Effects on custom code and reporting
| Pattern in ECC code | What happens in S/4HANA | Typical action |
|---|---|---|
| `SELECT` from an aggregate table, such as GLT0 | Works through a compatibility view, with calculation at read time | Test results, then move to ACDOCA or a released CDS view |
| `INSERT` or `UPDATE` on an aggregate table | Not supported | Remove the write or redesign it |
| Reading stock from a table such as MARD | Stock is derived from material documents | Use the released replacement views or MATDOC |
| Joins across separate FI and CO tables | Data is in one table | Simplify the join |
| Reconciliation reports between FI and CO | Little left to reconcile | Review whether the report is still needed |
Reporting changes too. Because totals are not frozen in a table, a report can group by any field that ACDOCA carries. This is the reason SAP positions analytical views and Fiori apps on top of line items instead of on top of summary tables.
Common mistakes
- Assuming a missing aggregate means missing data. The data is still there. It is in the line items.
- Ignoring write access. Compatibility views make reads work, which hides write problems until a posting runs. Search your custom code for modifying statements on affected tables.
- Expecting a database size drop to be the only benefit. The memory footprint does shrink because aggregates and index tables go away. The larger benefit is that one version of each fact exists.
- Treating the compatibility view as permanent. SAP's Simplification Item Catalog is the place to check what is replaced and how. Chapter 13 covers the tool.
Summary
S/4HANA stores each business fact once and calculates totals when they are requested. Aggregate tables are removed, related tables are merged, and compatibility views keep read access to the old structures working. Writes to former aggregates are the main risk, followed by code that uses a view in an inefficient way.
Exercise
A custom ECC program reads period totals from table GLT0 and also inserts correction rows into it. After conversion to S/4HANA, which part is likely to keep working, and which part will need a redesign? What would you use instead of GLT0 for the read?
Show answer
The read is likely to keep working through the compatibility view, but you should test the results and plan a move to the Universal Journal table ACDOCA (or a released CDS view), summing HSL grouped by account and period. The insert needs a redesign. A compatibility view is read only, and totals are calculated from line items, so corrections must be made by posting a document that creates line items. Writing totals directly is not supported.
Exercise
Why does SAP HANA make stored aggregate tables less necessary, and what is the main data-consistency benefit of removing them?
Show answer
HANA keeps data in memory in columnar form, so summing a column over millions of line items is fast enough to do at read time. Removing aggregates means each fact is stored once, so totals cannot disagree with the line items they came from. This reduces the need for reconciliation between modules.