ERPClimb logoERPClimb
Open SQL
ABAP Developmentadvanced 8 min read

Open SQL Part 9: HANA-Friendly SQL and Code Pushdown

Preview · a free account unlocks the full lesson

Key takeaway

Adapt classic SQL habits for SAP HANA: fewer round trips, aggregation and calculation in the database, SQL expressions (CASE, CAST, string/date functions), subqueries, and when to move logic into CDS views.

In this lessonShow sections

Visual overview

Open SQL Part 9: HANA-Friendly SQL and Code Pushdown — learning sheetIn one line: Adapt classic SQL habits for SAP HANA: fewer round trips, aggregation and calculation in the database, SQL expressions (CASE, CAST, string/date functions), subqueries, and when to move logic into CDS views.ERPClimb.com / ABAP / LESSON 9/10 / LEARNING SHEETOpen SQL Part 9: HANA-Friendly SQL and Code Pushdown1 · IN ONE LINEAdapt classic SQL habits for SAP HANA: fewer round trips, aggregation and calculation in thedatabase, SQL expressions (CASE, CAST, string/date functions), subqueries, and when to movelogic into CDS views.2 · KEY IDEAS EXPLAINEDWhat Changes With HANAColumn store: reading few columns of many rows isvery fast; SELECT * of wide tables is costly.In-memory aggregation and joins are very fast.Code Pushdown In ABAP SQL (7.40 SP05+…Calculations: price * seatsocc AS revenue.CASE: CASE WHEN seatsocc >= seatsmax THEN'FULL' ELSE 'OPEN' END AS status.Classic Anti-Patterns To RemoveSELECT … ENDSELECT with processing per row → INTOTABLE.SELECT inside LOOP → JOIN/FAE + internal table.When To Use CDS ViewsIf the same join/calculation is needed in severalprograms, services or analytics, model it once asa CDS view entity (see RAP/CDS module) and select…3 · DO · AVOIDBest practice!Common mistakeMinimize round trips and transferred data.Use SQL expressions, aggregation andsubqueries in strict syntax.Remove SELECT-in-loop and nested SELECTpatterns.✕Assuming HANA makes any code fastautomatically.✕SELECT * on wide tables in column store.✕Computing and aggregating in ABAP what SQL cando.4 · IN A REAL PROJECTAfter a migration to S/4HANA, a margin report was only slightly faster than before. ST05 showed it read 3million document lines with SELECT * and computed margins, statuses and totals in ABAP loops. Rewriting thecore as one SELECT with CASE expressions, arithmetic and GROUP BY — later moved into a CDS view reused by an…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

Parts 1 through 8 of this series taught correct and measured SQL; after a move to S/4HANA or Suite on HANA, the same code often runs faster, but classic patterns that move data to ABAP still waste most of HANA's strength, so this part is about adapting to the database's actual behavior rather than micro-optimizing ABAP.

What changes with HANA: its column store makes reading few columns across many rows very fast, while a SELECT * against wide tables becomes costly; in-memory aggregation and joins are very fast; many of the secondary indexes a classic database needed become unnecessary, and some statements need a different approach entirely; and the expensive part of the whole operation is the round trip and data transfer between the application server and the database — so the biggest wins come from fewer round trips and less data transferred, not from fine-tuning ABAP itself, and work should be pushed to the database wherever possible: filtering, joins, aggregation, and calculations expressed as SQL.

Code pushdown in ABAP SQL, using the strict syntax from release 7.40 SP05 onward, can include calculations such as price * seatsocc AS revenue; CASE expressions such as CASE WHEN seatsocc >= seatsmax THEN 'FULL' ELSE 'OPEN' END AS status; CAST, COALESCE, string functions (CONCAT, SUBSTRING, UPPER), date functions (DATS_DAYS_BETWEEN), and arithmetic functions (ROUND, DIV); aggregations with GROUP BY and HAVING, as covered in Part 6; subqueries such as WHERE EXISTS ( SELECT … ) or IN ( SELECT … ); and, in newer releases, common table expressions using WITH.

Free account

Create a free account to keep reading

You have read the opening of this lesson. A free ERPClimb account unlocks the rest of it, every other lesson and topic, and your learning history, so you can pick up exactly where you stopped. No card needed.

  • Full explanation
  • Code example
  • Real project scenario
  • Common mistakes
  • Best practices
  • Interview angle

One tap with Google works too. Every topic keeps its first lesson open to everyone.

Keep exploring

Referenced SAP objects

Reviewed reference pages for the objects this page mentions.

Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.