CDS Table Functions Part 3: Parameters, Client Handling and Session Context
Preview · a free account unlocks the full lesson
Handle runtime inputs in table functions correctly: parameters with system defaults, client handling with @ClientHandling and SESSION CONTEXT, language and date from the session, and passing parameters through wrapping views.
In this lessonShow sectionsHide sections
Visual overview
Explanation
Part 2 built a table function. Real functions need correct inputs — dates, language, organizational units, and above all the right client.
Parameters are declared in the CDS definition, for example "with parameters p_keydate : abap.dats, p_bukrs : bukrs", and become available inside SQLScript as :p_keydate. Consumers must pass them explicitly, as in "FROM ztf_…( p_keydate = @date )", and wrapping views pass them through in turn, with something like "as select from ZTF_…( p_keydate: $parameters.p_keydate )".
Parameters can be filled automatically from the session when the consumer — an OData service, say, or an analytics tool — doesn't supply them, by annotating them with session defaults: @Environment.systemField: #SYSTEM_DATE for today's date, #SYSTEM_LANGUAGE for the logon language (useful for texts), #CLIENT for the client, and #USER for the user.
Client handling needs special attention because, unlike ABAP SQL, SQLScript does not handle the client implicitly — this has to be done by hand. The function must be declared client-dependent with @ClientHandling.type: #CLIENT_DEPENDENT, where the first element of "returns" is the client field.
With @ClientHandling.algorithm: #SESSION_VARIABLE, the ABAP runtime sets the session variable CDS_CLIENT, and the SQLScript must filter on it with WHERE client = SESSION_CONTEXT('CDS_CLIENT') on every client-dependent table it reads, including in joins. Alternatively, the client can be passed as a parameter annotated with #CLIENT and filtered on directly.
Forgetting this filter is a real risk: without it, the function returns rows from every client in the database, which is both a data leak and a source of duplicate-looking results.
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.