Sub topic 3
SAP HANA as the required database
This chapter assumes you know the difference between an application layer and a database, and that you have written or read basic ABAP Open SQL. It covers what "HANA is required" means, how HANA stores data, and what that changes for your code and your project.
ECC could choose a database, S/4HANA cannot
SAP ECC 6.0 is database-independent. A customer could run it on Oracle, IBM Db2, Microsoft SQL Server, SAP MaxDB, SAP ASE, or SAP HANA. The application server (the ABAP stack) talked to the database through Open SQL and a database interface that hid the differences.
SAP S/4HANA supports only SAP HANA. There is no Oracle or Db2 option, and a system conversion to S/4HANA includes a move to HANA if you are not already on it. This is a design decision. The S/4HANA data model and much of its application code assume HANA capabilities, so other databases cannot run it.
Two terms are easy to confuse:
- SAP Business Suite on HANA is ECC (or another Business Suite product) running on the HANA database. The application is unchanged. Only the database differs.
- SAP S/4HANA is a different application that also requires HANA. It has a changed data model, new code, and a new user interface.
Moving ECC to HANA is therefore a database migration, not an S/4HANA conversion. It can be a useful intermediate step, but it does not give you the simplified data model.
How HANA stores data
HANA is an in-memory, column-oriented database. Each part of that description affects how you work.
In-memory
Active data is held in main memory (RAM), not read from disk for each query. Disks still exist. HANA writes changes to a redo log and takes periodic savepoints, so the data survives a restart. On startup it reloads data into memory. RAM access is far faster than disk access, so reads and aggregations that were slow on a disk-based database become practical.
The consequence is sizing. A HANA system needs enough RAM for the data you want in memory, plus working space for queries. Memory is a main cost driver in an S/4HANA project, which is why data volume reduction (archiving, cleaning up old data) before conversion matters.
Column store
A row store keeps all fields of a record together. A column store keeps all values of one column together.
| Aspect | Row store | Column store |
|---|---|---|
| Best for | Reading or writing whole records | Aggregating or filtering a few columns over many rows |
| Compression | Limited | High, because a column holds similar values |
| Typical use in SAP | Small, frequently updated technical tables | Most application tables |
A query such as "sum the amount for one account" touches one or two columns. A column store reads only those columns and skips the rest. Columns with many repeated values compress well (for example, with dictionary encoding), which reduces the memory needed.
Main and delta storage
Column stores are good at reading and slower at single-row inserts. HANA handles this with two areas per column table. The main store holds compressed, read-optimized data. The delta store receives new writes in a write-optimized form. Queries read both. A background delta merge periodically moves delta data into main. You rarely manage this by hand, but it explains why write-heavy tables can show delta-related memory growth.
Why HANA enables the simplified data model
In ECC on a traditional database, aggregates were stored. Totals tables such as GLT0 for general ledger balances existed because summing millions of line items on every query was too slow. Every posting wrote the line item and also updated the aggregates.
On HANA, summing line items on demand is fast enough. S/4HANA therefore removes many stored aggregates and computes them when requested. This reduces data duplication and removes a source of inconsistency between line items and totals. The next chapters cover the specific tables. For now, keep the dependency in mind: the removal of aggregates is possible because of HANA, so the simplified data model cannot run on another database.
Code pushdown
The biggest change for ABAP developers is where calculation happens. The classic pattern was to fetch many rows to the application server and compute in ABAP loops. On HANA, the better pattern is code pushdown: let the database do the aggregation, joining, and filtering, and return only the result.
Here is a runnable example with the demo table SFLIGHT. The first part fetches every row and sums in ABAP. The second pushes the sum to the database.
REPORT zdemo_pushdown.
" Pattern 1: fetch all rows, then sum on the application server
SELECT carrid, paymentsum
FROM sflight
INTO TABLE @DATA(lt_flights).
DATA lv_sum_abap TYPE sflight-paymentsum.
LOOP AT lt_flights INTO DATA(ls_flight).
lv_sum_abap = lv_sum_abap + ls_flight-paymentsum.
ENDLOOP.
" Pattern 2: let the database aggregate and return one row per carrier
SELECT carrid, SUM( paymentsum ) AS total
FROM sflight
GROUP BY carrid
INTO TABLE @DATA(lt_totals).
WRITE: / 'Sum calculated in ABAP:', lv_sum_abap.
LOOP AT lt_totals INTO DATA(ls_total).
WRITE: / ls_total-carrid, ls_total-total.
ENDLOOP.With a few demo rows, both patterns finish instantly. With hundreds of millions of rows, pattern 1 moves all of them across the network into ABAP memory, while pattern 2 returns a handful of rows.
SAP provides several tools for deeper pushdown:
- Open SQL enhancements, such as aggregate functions,
CASEexpressions, and arithmetic inSELECT, as shown above. - ABAP Core Data Services (CDS) views, which define reusable, annotated data models in the database layer. Many S/4HANA standard applications and Fiori apps are built on them.
- ABAP-managed database procedures (AMDP), which let you write database procedures (for example in SQLScript) inside ABAP classes.
Prefer Open SQL and CDS first. Use AMDP only when they cannot express the logic, because AMDP code is tied to HANA and is harder to test.
Common errors and edge cases
- Assuming HANA fixes slow code. Fetching all rows, then nested
SELECTstatements inside loops, still performs badly on HANA. In-memory speed hides some problems and exposes others. - Native SQL written for another database.
EXEC SQLblocks, Oracle optimizer hints, or Db2-specific syntax will fail or be ignored after migration. Search custom code for them early. - Relying on implicit sort order. Some databases returned rows in a predictable order, such as primary key order, even without
ORDER BY. Code that depended on this can break. AddORDER BYorSORTexplicitly. - Direct reads of removed tables. Code that selects from a table removed in S/4HANA may fail even though HANA itself works. Compatibility views exist for some, but not all, of them.
- Underestimating memory. Sizing from the old database's disk size is wrong, because compression differs and S/4HANA data structures change. Use SAP's sizing reports and guidance instead of a ratio from memory.
- Treating the database move as the whole project. A Business Suite on HANA migration alone gives faster reporting but not S/4HANA's functionality or the simplified data model.
How the database move happens in a conversion
When the source system is not on HANA, the conversion tooling can combine the database migration with the software update in one downtime window. SAP's Software Update Manager (SUM) offers this as Database Migration Option (DMO). If the source is already on HANA, only the software conversion runs. Plan downtime, testing, and rollback for whichever path applies. The approaches themselves are compared in a later chapter.
Exercise
A colleague says, "Our ECC system already runs on HANA, so we are basically on S/4HANA." Give two reasons this is wrong, and name one thing the HANA database does make possible in S/4HANA.
Show answer
First, ECC on HANA (Business Suite on HANA) keeps the ECC application and data model, including stored aggregates such as GLT0. S/4HANA is a different application with a changed data model, so a software conversion is still needed. Second, S/4HANA brings new functionality, such as the Universal Journal and the Business Partner, which ECC on HANA does not have. The HANA database makes it possible to remove stored aggregates and compute totals on demand from line items, because column-store aggregation over line items is fast enough.
Exercise
Your custom report selects all rows from a large table into an internal table, loops over them to compute totals per company code, and uses an Oracle optimizer hint in its SELECT. List the changes you would make for HANA.
Show answer
Remove the Oracle-specific hint, because it is database-specific and not valid on HANA. Replace the ABAP loop with a SELECT that uses SUM( ... ) and GROUP BY on company code, so the database returns one row per company code. Add ORDER BY if the output order matters, because the code must not depend on implicit ordering. If the logic is reused or complex, consider a CDS view as the next step.