CDS Table Functions and AMDP Explained
A CDS table function is a CDS entity whose data retrieval logic is not expressed in DDL but delegated to an AMDP class method containing SQLScript, which runs natively on the HANA database. It exists for calculations that plain CDS expressions cannot express, such as hierarchy traversal or procedural allocation logic, at the cost of portability, testability, and further optimizer push-down.
This page covers what a CDS table function actually is structurally, when dropping into AMDP SQLScript is justified versus a lazy shortcut, and the specific ways this pattern degrades at production volume or under clean core constraints. It focuses on the decision of whether to reach for this tool at all, since most projects that use it never needed to.
Published 16 Sept 2026· 1,508 words
What it is
A CDS table function has a DDL source with a defined signature, parameters, and return structure, so from the outside it looks like any other CDS entity and can be selected from, joined to, and exposed like a view. The structural fact that causes confusion is that no SQL view is generated underneath it. Instead the DDL source is only an interface; execution jumps into an AMDP method, a class implementing the AMDP marker interface, containing SQLScript that runs directly on the HANA database. This makes the table function a black box to the rest of the CDS stack: the ABAP CDS compiler cannot inline it, cannot push filters or aggregations into it, and cannot optimize across the boundary the way it does with nested CDS views. It is declarative on the outside and fully procedural on the inside, and that mismatch is what trips people up when they treat it like an ordinary view for performance planning.
When to use it
Legitimate use cases are calculations that CDS view syntax genuinely cannot express: recursive hierarchy resolution such as cost center or profit center groups, complex allocation or apportionment logic requiring loops or branching, statistical or forecasting functions available in SQLScript but not exposed as ABAP CDS built-in functions, or algorithms that need intermediate result sets and control flow. It is the wrong tool when a CASE expression, arithmetic operation, standard currency conversion annotation, or an association would produce the same result, because those stay analyzable by the optimizer and by anyone reading the model. It is also the wrong tool for transactional read paths where every millisecond matters, since the SQLScript boundary blocks the kind of push-down that keeps normal CDS views fast, and for any scenario needing write access, since table functions are read-only by construction.
How it fits the stack
Below the table function sits raw SQLScript reading database tables or other CDS entities directly, with no association navigation available inside the procedure body, only explicit joins written by hand. Above it, the table function is consumed exactly like a CDS view entity: it can be wrapped in a further CDS view to add associations, annotations, or an access control layer, exposed as a RAP read-only entity, or surfaced directly through OData. It sits at the seam between the declarative CDS layer and imperative ABAP/HANA-native code, and it replaces the older pattern of calling an AMDP class or a native SQL function module directly from an ABAP report to fetch precomputed data. Because it is a terminal node for optimization, teams typically wrap it in one thin CDS view immediately on top so the rest of the model can attach annotations without touching the SQLScript.
A worked example
A profitability report needs margin figures allocated down a cost center hierarchy that changes depth and structure by company code, something no CDS association or CASE expression can walk generically. The DDL source for the table function declares input parameters for company code and period and a return structure with cost center, allocated margin, and hierarchy level. The backing AMDP class implements the marker interface and its method contains SQLScript that uses a HANA hierarchy function to traverse the cost center hierarchy table and join it against actual postings, computing allocated values level by level. A plain CDS view entity is then defined on top of the table function purely to attach annotations such as label and currency conversion metadata, and to expose an association to the cost center master data view, since the table function itself cannot expose associations. That CDS view entity is what gets projected and exposed as a RAP read-only entity for the Fiori reporting app, keeping the SQLScript layer isolated and undocumented logic out of the consuming model.
How to choose
- Can the requirement be met with CASE logic, arithmetic, a built-in CDS function, or a standard currency or unit conversion annotation. If yes, stay in plain CDS; only fall to AMDP when the calculation is genuinely procedural or recursive.
- Does the calculation need to run set-based against large data volumes on the database, or is the relevant data small enough after filtering to handle in ABAP. SQLScript earns its complexity cost only when it saves a materially larger data transfer or loop in the application layer.
- Is HANA-only acceptable for this scenario. AMDP ties the logic to HANA SQLScript syntax with no database abstraction; ordinary ABAP CDS views remain portable across supported databases.
- Does anything above this entity need to filter, aggregate, or paginate against it at scale. Because push-down stops at the table function boundary, filters applied on top run against the full materialized result, not against the source tables.
- Who maintains this in two years. SQLScript inside an AMDP class is harder to unit test, version-control meaningfully, and hand over than declarative CDS, and it requires a developer comfortable with both ABAP and SQLScript.
- Is this development happening in a clean core context. If the target is a public cloud ABAP environment, AMDP is not available in the restricted development model and the requirement needs a different design entirely, possibly side-by-side.
Common pitfalls
- Works fine against test data volumes and slows sharply in production because the database optimizer treats the AMDP body as an opaque procedure and cannot integrate it into the surrounding query plan.
- A filter or aggregation added in a CDS view sitting on top of the table function does not push down; the full result set is computed and materialized first, then filtered afterward, which shows up as a runtime cliff nobody predicted at design time.
- Data access control defined at the DCL layer is not automatically enforced inside the SQLScript body; authorization has to be coded explicitly inside the AMDP or applied strictly at the consuming CDS view, and it is easy to leave a gap where the table function itself is unrestricted.
- Currency or unit conversion coded by hand inside SQLScript instead of through the standard conversion mechanism drifts out of sync when configuration changes, since it bypasses the normal conversion logic entirely.
- SQLScript syntax errors are only caught at activation or execution time on the database, not by the ABAP syntax checker, so a broken table function can pass a transport review and only fail when it actually runs.
- Associations from other CDS entities into a table function are limited or unavailable, breaking an expected reuse pattern and forcing an extra wrapping view that people forget to document as mandatory.
- Behavior can shift across HANA versions when the specific SQLScript functions used change availability or semantics, turning a routine platform upgrade into a regression hunt.
- Used as a deadline shortcut for logic that could have been modeled declaratively, it accumulates as technical debt that is expensive to unwind later because the business logic is buried in procedural code with no annotation trail.
ECC, S/4HANA and clean core
CDS table functions and AMDP work on S/4HANA on-premise and in embedded steampunk-style extensibility scenarios where a developer has full development access and HANA is guaranteed as the database. In a clean core setup targeting the public cloud ABAP environment, this pattern is out of scope: AMDP and native SQLScript are classic on-stack development, not part of the restricted extensibility language released for cloud development, and are not something an extension project can use. Teams committing to clean core should treat any existing table function as something to re-platform or replace with standard CDS modeling or a side-by-side service where possible, and should avoid writing new ones once that migration path is set as the target architecture.
Whose problem this is
This is developer territory, specifically a developer comfortable with both ABAP CDS and HANA SQLScript, working with an architect on the decision of whether procedural logic belongs here at all. Handover needs inline comments explaining the business logic in the SQLScript body, since there is no annotation layer to carry that intent, plus test data covering edge cases and a performance test run at realistic production volume, not development sample data.
Related SAP objects
Reviewed pages this object connects to in the ERPClimb knowledge graph.
Source: ERPClimb — https://erpclimb.com/sap-technical-topics/cds-table-functions-and-amdpERPClimb is an independent platform and is not affiliated with SAP SE. Reference pages are written and reviewed by SAP consultants for learning and troubleshooting.