Lesson 1 of 5
Code pushdown
10 min
Listen to this lesson
After Contoso Motor Co.'s second mock conversion, Priya's team timed the nightly batch chain in the quality system CMQ. One custom job stood out: the fleet rebate run, which calls the legacy function module Z_FLEET_REBATE_CALC for every open order item. On ECC it had taken about 40 minutes. On SAP S/4HANA it took over three hours, which put the overnight chain at risk. Kenji's team found the cause in an hour: the code fetched rows one at a time and did all the arithmetic in ABAP. The database was barely working; the round trips were.
Code-to-data, not data-to-code
Classic ABAP grew up on databases where the advice was to keep the database simple and do the work on the application server. SAP HANA turns that around. It is an in-memory, column-oriented database that is very good at scanning, joining, filtering and aggregating large volumes. Code pushdown means moving data-intensive logic to the database layer, so that only the result travels to ABAP. SAP describes this as moving from data-to-code to code-to-data.
| Step | Data-to-code (before) | Code-to-data (after) |
|---|---|---|
| Read | SELECT all open items into an internal table, then one SELECT per item for pricing | One SELECT that joins items and pricing |
| Filter | LOOP with IF to skip non-fleet customers | WHERE condition on the customer group |
| Calculate | Sum rebates per customer in ABAP | SUM with GROUP BY in ABAP SQL or a CDS view entity |
| Transfer | Hundreds of thousands of rows | One row per fleet customer |
SAP's five rules still apply
The ABAP Keyword Documentation lists performance rules for ABAP SQL that hold on any database and matter even more on SAP HANA:
- Keep the result set small: use WHERE conditions so the database returns only the rows you need.
- Keep the transferred data small: select only the columns you need; use aggregates so summing happens in the database.
- Keep the number of reads small: use mass operations, joins, views and subqueries; no ABAP SQL inside loops.
- Use buffers: do not read the same data twice; buffer tables that are read often and changed rarely.
- Use indexes where they help the database find rows efficiently.
Choosing the pushdown technique
You have three main options, and they are not competitors. ABAP SQL is the first choice for data access that one program needs: modern ABAP SQL supports joins, subqueries, aggregates, CASE and many SQL functions. CDS view entities define reusable data models in the database, with associations and calculations that many consumers (reports, RAP business objects, analytics, APIs) can share. ABAP Managed Database Procedures (AMDP) run SQLScript in SAP HANA for logic that SQL cannot express well, such as complex multi-step calculations on large volumes. Reach for AMDP last: it is HANA-specific code that is harder to read, test and support.
- Does one program need this data shape?Yes → ABAP SQL with joins, WHERE and aggregates · No → next question
- Will several consumers reuse the model, or does a RAP BO or API need it?Yes → CDS view entity · No → next question
- Is the logic too complex for SQL and data-heavy enough to justify database code?Yes → AMDP, with tests and a named owner · No → keep it in ABAP
For the fleet rebate run, Kenji's team replaced the item loop with one ABAP SQL statement that joins open order items with their pricing elements, filters on fleet customers, and sums rebate-relevant amounts per customer. The function module keeps its interface, so callers do not change. In CMQ the job dropped to under 20 minutes on the same data.
What would you do?
A developer proposes moving the whole fleet rebate logic, including the business rules for exemptions and rounding, into an AMDP "because HANA is fast". What should Kenji say?
- Code pushdown moves data-intensive work to SAP HANA so only results travel to ABAP.
- SAP's ABAP SQL rules: small result sets, few columns, few reads, buffers, indexes.
- Use ABAP SQL first, CDS view entities for reusable models, AMDP last.
- Push down scanning and aggregation; keep business rules readable and testable in ABAP.
Check your understanding · not graded
Lesson check
1. What does code pushdown mean?
2. Which ABAP SQL rule does a SELECT SINGLE inside a LOOP break?
3. When is AMDP the right pushdown technique?
4. Why did the fleet rebate run get faster without changing its interface?