Core Data Services (CDS) ABAP

Parameters & Client Handling

Parameters in Views

Use as expressions, for example in:

  • Operator expressions, e.g. calculations
  • Arguments of SQL functions
  • WHERE and ON conditions

Access to a parameter is done using
$parameters.<parameter>

Definition follows this pattern:

define view entity ZI_User
  with parameters
    p_user : xubname
  as select from ZBC_USERS
{
  ...
}

Annotations for Parameters

@EndUserText.label: <Description>

@EndUserText.tooltip: <Tooltip>

@Environment.systemField: // default values for parameters
  • #CLIENT → sy-mandt
  • #SYSTEM_DATE → sy-datum
  • #SYSTEM_TIME → sy-uzeit
  • #SYSTEM_LANGUAGE → sy-langu
  • #USER → sy-uname
  • Only #CLIENT cannot be overridden at runtime

Exercise – CDS Parameters

Extend the previous exercise with expressions in the field list:

  • The width of the column SummaryShort should be controlled by a parameter pSummaryShortLength.
  • For the threshold values between PrioCat A, B, and C, introduce two parameters pLevelA and pLevelB.

Define the required parameters and adjust the expressions in the view entity accordingly.

Client Handling

Client handling is active by default and normally requires no additional handling.

The annotation ClientDependent: [true | false] is obsolete.

Current annotation:

ClientHandling.type: [#INHERITED | #CLIENT_DEPENDENT | #CLIENT_INDEPENDENT]

Client Handling – Example

CDS View

@AbapCatalog: { sqlViewName: 'ZJB_DEMO',
                compiler.compareFilter: true,
                preserveKey: true }

@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'My First CDS View'
define view zjb_cds_demo
  as select from zbc_tasks as t

    left outer join zbc_users as u on t.assignee = u.user_id
{
      // Block mode: Alt + Shift + A
      // Pretty Printer: Shift + F1
  key t.task_key    as TaskKey,
      t.summary     as Summary,
      t.status      as Status,
      t.project     as Project,
      t.description as Description,
      t.assignee    as Assignee,
      u.firstname   as Firstname,
      u.lastname    as Lastname,
      t.type        as Type      
}

Generated SQL Statement

CREATE OR REPLACE VIEW "ZJB_DEMO" AS SELECT 
  "T"."CLIENT" AS "MANDT", 
  "T"."TASK_KEY" AS "TASKKEY", 
  "T"."SUMMARY" AS "SUMMARY", 
  "T"."STATUS" AS "STATUS", 
  "T"."PROJECT" AS "PROJECT", 
  "T"."DESCRIPTION" AS "DESCRIPTION", 
  "T"."ASSIGNEE" AS "ASSIGNEE", 
  "U"."FIRSTNAME" AS "FIRSTNAME", 
  "U"."LASTNAME" AS "LASTNAME", 
  "T"."TYPE" AS "TYPE"
FROM "ZBC_TASKS" "T" LEFT OUTER JOIN "ZBC_USERS" "U" ON ( 
  "T"."CLIENT" = "U"."CLIENT" AND 
  "T"."ASSIGNEE" = "U"."USER_ID" 
)