ERPClimb logoERPClimb
CDS Views
Architect / Cross-trackadvanced 8 min read

CDS Views Part 9: Parameters and Filtering

Preview · a free account unlocks the full lesson

Key takeaway

Define CDS views with input parameters, use $parameters in WHERE, calculations and path filters, default parameters from system fields, and pass parameters from ABAP. Learn when parameters are the right tool and when a simple WHERE by the consumer is better.

In this lessonShow sections

Visual overview

CDS Views Part 9: Parameters and Filtering — learning sheetFlow: Build ZI_OpenOrdersKeyDate with p_keydate and language parameter defaulted from #SYSTEM_LANGUAGE → Filter open orders (overall status not completed) created on or before the key date; calculate age at key date → Call it from an SE38 report with a key-date PARAMETER, omitting the language → Compare: would a WHERE on CreationDate by the consumer be enough? Decide per field. Key ideas: DEFINING PARAMETERS; USING PARAMETERS; SYSTEM FIELD DEFAULTS; PASSING FROM ABAP. Watch out: Passing parameters from ABAP needs strict ABAP SQL syntax (@ host variables, commas) — this is one of the few places where a classic report must use modern SQL.ERPClimb.com / ARCH / LESSON 9/10 / LEARNING SHEETCDS Views Part 9: Parameters and Filtering1 · HOW IT FLOWS1BuildZI_OpenOrdersKeyDatewith p_keydate…2Filter openorders (overallstatus not…3Call it from anSE38 report witha key-date…4Comparewould a WHERE onCreationDate by the…2 · KEY IDEAS EXPLAINEDDefining Parametersdefine view entity ZX with parameters p_keydate :abap.dats, p_currency : waers as select from …Types: built-in abap.* types or data elements.Using ParametersWHERE erdat <= $parameters.p_keydate.Calculations: dats_days_between( erdat,$parameters.p_keydate ).System Field Defaults@Environment.systemField: #SYSTEM_DATE,#SYSTEM_LANGUAGE, #CLIENT, #USER.Consumer may omit the parameter; the runtime fillsit.Passing From ABAPSELECT … FROM zview( p_keydate = @lv_date ) … —strict ABAP SQL with @ and comma-separated fieldlist.Views with parameters propagate: a view selectingfrom a parameterized view must pass the parameterson.3 · REMEMBER · WATCH OUTRememberwith parameters defines mandatory inputs; inside the view they areused as $parameters.<name> in WHERE, calculations, CASE and path…@Environment.systemField (e.g. #SYSTEM_DATE, #SYSTEM_LANGUAGE) fills aparameter automatically when the ABAP consumer does not pass it.Parameters are right when the value changes the calculation itself(key date, target currency, language) — not for plain row filters.!Watch outPassing parameters from ABAP needsstrict ABAP SQL syntax (@ hostvariables, commas) — this is one ofthe few places where a classicreport must use modern SQL.4 · IN A REAL PROJECTA team built its sales-order CDS views with parameters for sales organization, customer and date range"to make filtering fast". Every Fiori app on top showed a parameter dialog before any data appeared,and other reports could not reuse the views without inventing dummy values. In the redesign, those filters…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

Part 8 restricted rows by user; now we let the consumer supply values that actually shape the result, through CDS parameters.

A view declares them with with parameters, for example define view entity ZX with parameters p_keydate : abap.dats, p_currency : waers as select from ..., using either built-in abap.* types or data elements; every parameter is mandatory unless it's given a default through @Environment.systemField.

Parameters are the right tool when the value changes the calculation itself — a key date, a target currency, a language — not for plain row filtering.

Inside the view, parameters are used as $parameters.<name>, whether in a WHERE clause (WHERE erdat <= $parameters.p_keydate), in a calculation (dats_days_between( erdat, $parameters.p_keydate )), in a path filter (_Text[1: Language = $parameters.p_language]), or as the target of a currency conversion (target_currency => $parameters.p_currency).

@Environment.systemField lets a parameter fill itself automatically when the consumer doesn't pass it — common values are #SYSTEM_DATE, #SYSTEM_LANGUAGE, #CLIENT, and #USER. For simple needs like "today" or "the logon language," $session variables, covered in Part 2, can avoid the need for a parameter entirely.

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

Referenced SAP objects

Reviewed reference pages for the objects this page mentions.

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.