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

CDS Table Functions Part 5: Testing, Clean Core and Alternatives

Preview · a free account unlocks the full lesson

Key takeaway

Keep table functions maintainable: test them with ABAP Unit and test doubles, protect them with access control on the wrapping view, respect ABAP Cloud rules for AMDP, and know the modern alternatives in CDS.

In this lessonShow sections

Visual overview

CDS Table Functions Part 5: Testing, Clean Core and Alternatives — learning sheetIn one line: Keep table functions maintainable: test them with ABAP Unit and test doubles, protect them with access control on the wrapping view, respect ABAP Cloud rules for AMDP, and know the modern alternatives in CDS.ERPClimb.com / RAP / LESSON 5/5 / LEARNING SHEETCDS Table Functions Part 5: Testing, Clean Core andAlternatives1 · IN ONE LINEKeep table functions maintainable: test them with ABAP Unit and test doubles, protect themwith access control on the wrapping view, respect ABAP Cloud rules for AMDP, and know themodern alternatives in CDS.2 · KEY IDEAS EXPLAINEDTestingUnit tests with the CDS Test Double Framework(cl_cds_test_environment) for the wrapping view,and test doubles for the database tables used by…Insert controlled test data (two suppliers,several dates, two clients if relevant) andassert: ranking, day counts, client isolation…Access ControlTable functions themselves typically have no DCLrole; consumers should read the wrapping viewentity, which gets…Do not let consumers bypass the wrapper — documentthat the function is internal.ABAP Cloud And Clean CoreAMDP is available in ABAP for Cloud Developmentwith restrictions: the USING clause may referenceonly your own objects and SAP objects released…SAP tables are not C4-released — read your owntables or C4-released views.Alternatives To CheckCDS view entity features: CASE, aggregations, datefunctions, UNION, parameters.CDS hierarchies for parent-child structures.3 · DO · AVOIDBest practice!Common mistakeTest via the wrapping view with the CDS TestDouble Framework.Secure the wrapper with DCL; treat thefunction as internal.Restrict USING to own or C4-released objects.✕No automated tests for SQLScript logic.✕Consumers reading the table function directlywithout access control.✕Using SAP tables in USING in ABAP Cloud.4 · IN A REAL PROJECTA table function behind a supplier dashboard had no tests. A developer "optimized" the ranking andaccidentally changed ORDER BY created_on to ORDER BY request_id; the dashboard silently showed the wrong"oldest" requests for weeks. The team added ABAP Unit tests with test doubles for ranking, client…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

Table functions are tested with ABAP Unit, using test doubles for the tables they read. Access control (DCL) belongs on the wrapping CDS view entity that consumers actually use, not on the table function itself. In ABAP Cloud, AMDP may only access your own objects and SAP objects released for AMDP use under contract C4. It's worth periodically re-checking whether a newer CDS release has made the table function unnecessary altogether.

Parts 1 through 4 built a correct and fast table function; this part is about keeping it safe and maintainable.

For testing, unit tests use the CDS Test Double Framework, cl_cds_test_environment, on the wrapping view, with test doubles standing in for the database tables the AMDP actually reads — depending on your release, the framework may be able to double the table function's dependencies directly.

Controlled test data — say two suppliers, several dates, and two clients if that's relevant — should be inserted, with assertions covering ranking, day counts, client isolation and parameter filtering. It's also worth testing edge cases: no data at all, equal dates that create ranking ties, and boundary dates. These tests should run as part of ATC and transport checks.

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

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.