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

CDS Table Functions Part 3: Parameters, Client Handling and Session Context

Preview · a free account unlocks the full lesson

Key takeaway

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 sections

Visual overview

CDS Table Functions Part 3: Parameters, Client Handling and Session Context — learning sheetFlow: Add p_bukrs with a clear meaning; filter inside SQLScript → Make the function client-dependent with #SESSION_VARIABLE; add the client filter to every client-dependent source → Add a language parameter for any texts → Pass all parameters through the wrapping view entity. Key ideas: PARAMETERS; SESSION DEFAULTS; CLIENT HANDLING; LANGUAGE. Watch out: Forgetting the client filter returns data from ALL clients.ERPClimb.com / RAP / LESSON 3/5 / LEARNING SHEETCDS Table Functions Part 3: Parameters, Client Handlingand Session Context1 · HOW IT FLOWS1Add p_bukrs witha clear meaning;filter inside…2Make thefunctionclient-dependent…3Add a languageparameter forany texts4Pass allparametersthrough the…2 · KEY IDEAS EXPLAINEDParametersDeclared in the CDS definition: with parametersp_keydate : abap.dats, p_bukrs : bukrs.Available in SQLScript as :p_keydate.Session Defaults@Environment.systemField: #SYSTEM_DATE — today'sdate.@Environment.systemField: #SYSTEM_LANGUAGE — logonlanguage (for texts).Client HandlingDeclare the function client-dependent:@ClientHandling.type: #CLIENT_DEPENDENT; the firstelement of "returns" is the client…@ClientHandling.algorithm: #SESSION_VARIABLE — theABAP runtime sets the session variable CDS_CLIENT;your SQLScript filters on it: WHERE client =…LanguageFor texts, filter on a language parameter(#SYSTEM_LANGUAGE) orSESSION_CONTEXT('LOCALE_SAP'); do not hard-code…3 · REMEMBER · WATCH OUTRememberSelective inputs (key date, company code) should be parameters — theyreach the SQLScript directly.Client-dependent functions: client as first return field + filter onSESSION_CONTEXT('CDS_CLIENT').Defaults from the session via @Environment.systemField (#SYSTEM_DATE,#SYSTEM_LANGUAGE, #CLIENT).!Watch outForgetting the client filter returnsdata from ALL clients.4 · IN A REAL PROJECTIn a multi-client test system, a supplier dashboard showed each supplier twice with different numbers. Thetable function had no client filter: rows from the test client and the training client were summed andreturned together. The team made the function client-dependent with #SESSION_VARIABLE and added…Original ERPClimb learning sheet • Verify against your SAP release and edition

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.

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.