Module 22: Performance Optimization (HANA)
Performance optimization in S/4HANA is about thinking in sets, not loops, and placing logic at the right layer.
This module consolidates everything learned so far—internal tables, Open SQL, CDS, and AMDP—into concrete performance rules.
1. Internal Table Performance
Internal tables are fast, but wrong usage can destroy performance.
1.1 Choosing the Right Table Type
| Table Type | Access Pattern | Performance |
|---|---|---|
| STANDARD | Sequential | Slow for key access |
| SORTED | Key + Range | Good |
| HASHED | Key-based | Best |
DATA gt_hashed TYPE HASHED TABLE OF ty_emp
WITH UNIQUE KEY emp_id.
If you frequently use READ TABLE ... WITH KEY, use HASHED or SORTED tables.
1.2 Table Expressions (7.4+)
DATA(ls_emp) = gt_emp[ emp_id = lv_id ].
With safe access:
DATA(ls_emp) = gt_emp[ emp_id = lv_id ] OPTIONAL.
Table expressions are faster and cleaner than classic READ TABLE.
2. SELECT Optimization (HANA-Aware)
2.1 Select Only What You Need
❌ Bad
SELECT * FROM zsales INTO TABLE @DATA(lt_sales).
✅ Good
SELECT company, amount
FROM zsales
INTO TABLE @DATA(lt_sales).
Unnecessary fields increase network transfer and memory usage.
2.2 Push Filtering to Database
❌ Bad
SELECT * FROM zsales INTO TABLE @DATA(lt_sales).
DELETE lt_sales WHERE amount < 1000.
✅ Good
SELECT * FROM zsales
WHERE amount >= 1000
INTO TABLE @DATA(lt_sales).
2.3 Use JOINs Instead of Multiple SELECTs
SELECT a~id, b~text
FROM ztab1 AS a
INNER JOIN ztab2 AS b
ON a~id = b~id
INTO TABLE @DATA(lt_result).
One JOIN is almost always better than many SELECT SINGLEs.
3. Avoiding Nested SELECTs (Very Important)
3.1 Classic Anti-Pattern
❌ Very Bad
LOOP AT lt_sales INTO DATA(ls_sale).
SELECT SINGLE * FROM zcustomer
WHERE id = ls_sale-cust_id.
ENDLOOP.
3.2 Optimized Pattern
✅ Good
SELECT * FROM zcustomer
INTO TABLE @DATA(lt_customers).
LOOP AT lt_sales INTO DATA(ls_sale).
READ TABLE lt_customers
INTO DATA(ls_customer)
WITH KEY id = ls_sale-cust_id.
ENDLOOP.
Or better (pushdown):
SELECT s~id, c~name
FROM zsales AS s
INNER JOIN zcustomer AS c
ON s~cust_id = c~id
INTO TABLE @DATA(lt_result).
Nested SELECTs are one of the top 3 ABAP performance issues.
4. Parallelization in ABAP
Parallelization improves throughput for independent workloads.
4.1 When Parallelization Makes Sense
-
Independent data chunks
-
CPU-bound processing
-
Large volumes
-
No shared state
4.2 Common Parallelization Techniques
-
Background jobs (job chains)
-
Asynchronous RFC (CALL FUNCTION ... STARTING NEW TASK)
-
Parallel cursor (internal tables)
CALL FUNCTION 'Z_PROCESS_DATA'
STARTING NEW TASK lv_task
PERFORMING callback ON END OF TASK.
Parallelization increases system load and must be coordinated with BASIS.
5. Code Inspector & ATC (Mandatory)
5.1 Code Inspector
-
Transaction: SCI
-
Detects:
-
Performance issues
-
Syntax problems
-
Security risks
-
5.2 ABAP Test Cockpit (ATC)
-
Central quality gate
-
Mandatory in S/4HANA
-
Used in transports & CI pipelines
ATC Checks:
- SELECT *
- Nested SELECTs
- Obsolete syntax
- Security violations
No transport is allowed without clean ATC checks in most landscapes.
6. Performance Decision Matrix
| Scenario | Best Option |
|---|---|
| Simple read | Open SQL |
| Complex joins | CDS |
| Aggregations | CDS / SQL |
| Procedural DB logic | AMDP |
| UI reporting | CDS + SALV |
7. Common Performance Myths
-
“HANA is fast, performance doesn’t matter”
-
“SELECT SINGLE is always fast”
-
“Indexes are irrelevant on HANA”
-
“More parallel jobs = better performance”
8. Interview-Grade Performance Answer
Q: How do you optimize ABAP performance on HANA?
Answer:
I reduce data volume early, push set-based logic to the database using Open SQL or CDS, avoid nested SELECTs, choose the right internal table types, and validate code using ATC. I use AMDP only when CDS is insufficient.
This is exactly what senior interviewers expect.
9. Summary
-
Choose the right internal table type
-
Use table expressions
-
Optimize SELECT statements
-
Avoid nested SELECTs
-
Push logic to DB where appropriate
-
Use parallelization carefully
-
Enforce quality with ATC
10. Practice Exercises
-
Replace nested SELECT with JOIN.
-
Convert STANDARD table to HASHED and compare.
-
Identify pushdown candidates.
-
Run ATC and fix performance findings.
-
Design a performance-safe report.
11. What’s Next?
➡️ Module 23: SAP Locking & Update Concepts
On HANA, good performance is a design decision, not a tuning step.