How do you use parameters and session variables in a CDS view entity, and which should you prefer?
Say your answer out loud first.
Practise another way
Input parameters are declared with WITH PARAMETERS, typed with an elementary type or data element, and read as $parameters.name. Session variables like $session.user or $session.system_date read the runtime context directly.
They only have values when ABAP calls the view, so I prefer a parameter annotated with Environment.systemField: ABAP fills it automatically, but the view stays usable from other consumers that pass a value.
Parameters. Declared after the entity name, comma separated, each with an elementary type (abap.dats, abap.char(3) or a data element; structures and tables are not allowed).
Read them with $parameters. in the select list, in CASE, in expressions and on the right side of a WHERE or a path-expression filter. You can annotate them, for example @EndUserText.label.
define view entity ZI_OpenItems
with parameters
@EndUserText.label: 'Key date'
@Environment.systemField: #SYSTEM_DATE
p_keydate : abap.dats
as select from zitem
{
key ItemID,
DueDate,
case when DueDate < $parameters.p_keydate
then 'X' else ' ' end as IsOverdue
}
In ABAP SQL: SELECT FROM ZI_OpenItems( p_keydate = @date ) FIELDS ....
Session variables. Six built-in ones: $session.user, client, system_language, system_date, user_timezone, user_date. Example: $session.system_date.
They hold values only when the request comes from ABAP; elsewhere they have no defined value. There are also application session variables set by dedicated system programs.
Why prefer the annotated parameter. @Environment.systemField has seven values, for example #SYSTEM_DATE, #SYSTEM_LANGUAGE, #USER. If the consumer passes nothing, the ABAP runtime supplies the system field value, so the syntax check only forces you to pass other parameters.
In CDS and on the database the parameter stays mandatory, so other consumers can pass an explicit value (useful for tests and what-if dates).
Limits to mention
- Parameters need explicit values when the view is used as a data source in another CDS view.
- Entity buffering is not possible for views with parameters or with session variables other than the client.
- In ABAP Cloud, some system fields are better read through
CL_ABAP_CONTEXT_INFOin code. - Defaults for UI parameters:
@Consumption.defaultValue.
Shows declaration and access syntax, names the six session variables, and explains why an annotated parameter is more testable and robust than a bare session variable.
Uses $session.system_date everywhere and does not know the values are undefined when the view is not read from ABAP.
Hard-wiring $session variables into business logic. It makes the view impossible to test with a different date or user and breaks for consumers outside ABAP.
- How would you test a view that depends on today's date?
- Can a parameter be optional?
- Why can't a view with parameters be buffered?
- How do you pass a parameter in ABAP SQL?
4 official pages and 1 prep guide. Confidence: high. Checked 21 Nov 2026.
- Official page Backs the answer.
- Official page Backs the answer.
- Official page Backs the answer.
- Official page Backs the answer.
- Prep guide Gives the question.