ABAP CDS. A Brief Overview (2)

💡
Версия на русском: ABAP CDS. Коротко о главном (2)

In this note, I want to touch on the option of defining a set of input parameters during the creation of an ABAP CDS View. These parameters can act as filters when retrieving the result set of data and may also depend, for example, on user input in an ABAP program, or on another scenario depending on where the CDS will be used.

See: ABAP CDS. A Brief Overview

Defining a CDS View with a Set of Input Parameters

See:  ABAP CDS - parameter

Example of Creating an ABAP CDS with Parameters

Creating the ABAP CDS View discussed in this note is very simple. To do so, using Eclipse IDE, you need to select the appropriate type of view being created.

For demonstration purposes, I will use an example provided earlier, defining one input parameter within a familiar query condition.

@AbapCatalog.sqlViewName: 'ZCDS_PRM'
@AbapCatalog.compiler.compareFilter: TRUE
@AbapCatalog.preserveKey: TRUE
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'CDS with params'
define VIEW zcds_params
  WITH parameters
    p_country_origin : char2
  AS SELECT FROM ztbl1 AS t1
    INNER JOIN   ztbl2 AS t2 ON t1.id = t2.id
{
  KEY t1.id            AS Id,
 
      t1.name          AS Name,
      t1.lastname      AS Lastname,
      t2.birthdate     AS Birthdate,
      t2.cellphone     AS Cellphone,
      t2.email         AS Email,
      t2.countryorigin AS Countryorigin
}
WHERE
  countryorigin = $parameters.p_country_origin;

Don't forget to activate the new CDS View.

Example of Executing a CDS View with Parameters

The following video snippet shows an example of executing an ABAP CDS View with a specified input parameter.

0:00
/0:18

Example of Use in an ABAP Program

A good description of using an ABAP CDS View with input parameters in an ABAP program is provided in the vendor's reference documentation.

See: ABAP SQL, Parameter Passing to a CDS View

In my example, I will use the following implementation option. Verifying the result:

0:00
/0:34