ERPClimb logoERPClimb
CDS Table Functions
RAP / CDS / ODataadvanced 8 min read

CDS Table Functions Part 4: Performance with HANA Plan Analysis

Preview · a free account unlocks the full lesson

Key takeaway

Make table functions fast: why consumer filters may not be pushed down, how to design parameters and set-based SQLScript, how to measure with ST05, SQL trace and HANA PlanViz / explain plan, and how to compare against a CDS alternative.

In this lessonShow sections

Visual overview

CDS Table Functions Part 4: Performance with HANA Plan Analysis — learning sheetIn one line: Make table functions fast: why consumer filters may not be pushed down, how to design parameters and set-based SQLScript, how to measure with ST05, SQL trace and HANA PlanViz / explain plan, and how to compare against a CDS alternative.ERPClimb.com / RAP / LESSON 4/5 / LEARNING SHEETCDS Table Functions Part 4: Performance with HANA PlanAnalysis1 · IN ONE LINEMake table functions fast: why consumer filters may not be pushed down, how to designparameters and set-based SQLScript, how to measure with ST05, SQL trace and HANA PlanViz /explain plan, and how to compare against a CDS alternative.2 · KEY IDEAS EXPLAINEDWhy Table Functions Can Be SlowThe function computes its full result, then theconsumer's WHERE, ORDER BY and paging apply — ifthe optimizer cannot push those conditions into…Window functions (ROW_NUMBER) over all rows of alarge table are expensive.Design RulesParameters for selective filters (company code,date range, supplier) — applied early insideSQLScript.Filter before ranking/aggregation: WHERE first,then ROW_NUMBER over the reduced set.MeasuringST05 SQL trace: which statement the consumersends, execution time, number of rows.Explain plan (from ST05 or the SQL console): joinorder and operators.Compare With The AlternativeIf the function exists for performance, build theCDS view entity version too and compare in thesame system with the same parameters. Keep the…3 · DO · AVOIDBest practice!Common mistakeMeasure with the real consumer query andrealistic volumes.Use parameters for selective filters; filterearly.Use table variables for readable, stillset-based steps.✕Assuming SQLScript is automatically fast.✕Relying on consumer WHERE for selectivefilters.✕Ranking or aggregating before filtering.4 · IN A REAL PROJECTA dashboard based on a table function needed five seconds per call. The function ranked all 2.4 millionrequests, and the Fiori app then filtered by company code. PlanViz showed 90% of the time in the windowfunction over the full table. The team added a company-code parameter with a default from the user's settings…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

"Runs on HANA" doesn't mean "runs fast" — performance needs to be measured with the real consumer query. Selective filters belong in parameters rather than relying on the consumer's WHERE clause being pushed down automatically. SQLScript should stay set-based: one SELECT, no cursors or row-by-row loops. The tools worth knowing are ST05 for the statement and its timing, the explain plan, and HANA PlanViz for operator-level analysis.

Parts 1 through 3 built a correct table function; this part is about making it fast.

Table functions can end up slow for a few recurring reasons. The function computes its full result first, and only then does the consumer's WHERE, ORDER BY and paging get applied — unless the optimizer can push those conditions directly into the SQLScript body. Window functions like ROW_NUMBER running over all rows of a large table are expensive. Imperative SQLScript — cursors, loops, scalar calls per row — prevents parallel, set-based execution. And joining the function's result with large views can create huge intermediate results.

A few design rules help avoid this. Use parameters for selective filters — company code, date range, supplier — applied as early as possible inside the SQLScript. Filter before ranking or aggregating: WHERE first, then ROW_NUMBER over the already-reduced set. Select only the columns actually needed.

Avoid reaching for SELECT DISTINCT as a fix for duplicate rows — find the join actually causing them instead. And prefer a single declarative statement; where steps are genuinely needed, table variables work well, as in lt_open = SELECT …; RETURN SELECT … FROM :lt_open, which HANA can still optimize as a whole.

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.