This page offers an overview of all available CDS DDL features. It can be used like a cheat sheet to look up features and their release dates. It also offers links to data sources with further information on each feature. It will be updated regularly to always reflect the current ABAP CDS DDL feature scope. | Last update: 2023-08 ABAP CDS Feature Tables in the ABAP Keyword Documentation |
The following CDS entities are available in release ABAP Platform 2022 for data modeling.
Note: Column Release lists three release numbers. The first one refers to the ABAP release, the second one to the kernel release and the third one to the ABAP Platform Classic release.
CDS entity type | ABAP CDS statement | Purpose | Release | Further info |
CDS view entity | DEFINE VIEW ENTITY |
| 7.55 7.80 2020 | Docu Blog post |
CDS projection view of type transactional query | DEFINE VIEW ENTITY PROVIDER CONTRACT TRANSACTIONAL_QUERY AS PROJECTION ON |
| 7.54 7.76 1909 | Docu Blog post |
CDS projection view of type transactional interface | DEFINE VIEW ENTITY PROVIDER CONTRACT TRANSACTIONAL_INTERFACE AS PROJECTION ON |
| 7.57 7.86 2022 | Docu Blog post |
CDS projection view of type analytical query | DEFINE TRANSIENT VIEW ENTITY PROVIDER CONTRACT ANALYTICAL_QUERY AS PROJECTION ON |
| 7.57 7.86 2022 | Docu Blog post |
CDS table function | DEFINE TABLE FUNCTION |
| 7.50 7.61 1511 | Docu Blog post |
CDS hierarchy | DEFINE HIERARCHY |
| 7.53 7.73 1808 | Docu Blog post |
CDS custom entity | DEFINE CUSTOM ENTITY |
| 7.54 7.75 1909 | Docu |
CDS abstract entity | DEFINE ABSTRACT ENTITY |
| 7.53 7.70 1809 | Docu |
CDS DDIC-based view (obsolete) | DEFINE VIEW |
| 7.40 SP05 7.41 | Docu |
Did you know?
@EndUserText.label: 'This is a simple type' define type myType : abap.char(5);
@EndUserText.label: 'CDS enum type with base type char' define type DEMO_CDS_ENUM_CHAR : abap.char(1) enum { initial_value = initial; first_value = 'A'; second_value = 'B'; }
SQL-based scalar functions
An SQL-based scalar function is a user-defined function that accepts multiple input parameters and returns exactly one scalar value. A scalar function allows developers to encapsulate complex algorithms into manageable, reusable code that can then be used in all operand positions of CDS view entities that expect scalar values. A scalar function is linked with an AMDP function in which it is implemented using SQLScript.
A SQL-based scalar function consists of three repository objects:
Example:
CDS scalar function definition:
define scalar function DEMO_CDS_SCALAR_RATIO with parameters portion: numeric total : type of portion returns abap.decfloat34;
CDS scalar function implementation reference:
AMDP function implementation:
METHOD execute BY DATABASE FUNCTION FOR HDB LANGUAGE SQLSCRIPT OPTIONS READ-ONLY. result = portion / total * 100; ENDMETHOD.
Associations describe the relationships between CDS entities. They define a join that is instantiated only when fields are retrieved from the associated entity.
Use cases of CDS associations and how they are transformed into joins are documented here. Moreover, there's a blog post: From Open SQL Joins to CDS Associations | SAP Blogs.
Types of associations:
Regular, not specialized CDS association
ASSOCIATION [ OF {EXACT ONE | MANY | ONE} TO {EXACT ONE | MANY | ONE} ] TO target [AS _assoc] ON cds_cond [ WITH DEFAULT FILTER cds_cond ]
CDS composition
COMPOSITION [ OF {EXACT ONE | MANY | ONE} TO {EXACT ONE | MANY | ONE} ] target [AS _compos]
Association to parent
ASSOCIATION TO PARENT target [AS _assoc] ON $projection.cds_cond
In ABAP CDS, the following join types are available for modeling relationships between CDS entities:
Join type | Available as of |
Inner join | 7.4 SP05 |
Left outer join | 7.4 SP05 |
Right outer join | 7.4 SP05 |
Cross join | 7.51 |
Note: Column Release lists three release numbers. The first one refers to the ABAP release, the second one to the kernel release and the third one to the SAP BTP ABAP Environment release.
Clause | Function | Release | Further info |
WHERE | Defines a filter condition. | ABAP release 7.4 SP5 | Docu |
GROUP BY | Groups the rows in the result set by their content. Required as soon as there are aggregate expressions. | ABAP release 7.4 SP5 | Docu |
HAVING | Can be used together with GROUP BY to specify a further filter condition. | ABAP release 7.4 SP5 | Docu |
EXCEPT | Returns all distinct rows of the first result set that are not part of the following result sets. | 7.56 7.85 2108 | Docu |
INTERSECT | Returns all distinct rows that are part of all result sets. | 7.56 7.85 2108 | |
UNION | Merges the result sets of all queries. | ABAP release 7.4 SP5 |
Note: Column Release lists three release numbers. The first one refers to the ABAP release, the second one to the kernel release and the third one to the SAP BTP ABAP Environment release.
Operand | Explanation | Release | Further info |
Typed literal | Data types: Int1, int2, int4, int8, dec, decfloat16, decfloar34, fltp, char, string, sstring, raw, rawstring, numc, clnt, lang, dats, datn, tims, timn, utcl, curr, cuky, quan, unit. Syntax: abap.dtype’value’ Example: utcl'2020-01-02 23:59:59,1234567' | 7.56 7.83 2102 | Docu |
Untyped literal | Data types: char, int1, int2, int4, int8, fltp. Note: Typed should be preferred over untyped! | ABAP release 7.4 SP5 | Docu |
Field | Field of a data source of the current entity. Alias name using AS. If several data sources, prefix recommended. | ABAP release 7.4 SP5 | Docu |
Parameter | Input parameter from the parameter list. | ABAP release 7.4 SP8 | Docu |
Session variable | System fields that can be accessed with the syntax $session.<name>. Similar to ABAP system fields (sy-<name>). The following session variables are available:
| ABAP release 7.5, some were added later | Docu |
Arithmetic expressions
Operator | Meaning |
+ | Addition |
- | Subtraction |
* | Multiplication |
/ | Division |
Aggregate functions
Function | Meaning |
MAX (ALL | DISTINCT arg) | Returns the greatest value of arg. |
MIN (ALL | DISTINCT arg) | Returns the least value of arg. |
AVG (ALL | DISTINCT arg) | Average value of arg. Must be specified with the addition AS dtype. |
SUM (ALL | DISTINCT arg) | Sum of arg. |
COUNT (DISTINCT arg) | The number of distinct values of arg is counted. |
COUNT(*) | The number of rows in the result set is counted. |
Case distinction
A case expression in ABAP CDS always returns exactly one value, depending on the conditions. The simple case expression compares an expression to several other expressions for equality:
CASE operand WHEN operand1 THEN result1 [WHEN operand2 THEN result2] ... [{ELSE resultn | ELSE NULL}] END
The complex case expression (aka 'searched case') evaluates N independent conditions. The first case to be evaluated to TRUE returns the result. If none of the conditions are true, the result is determined by the ELSE branch:
CASE WHEN cds_cond1 THEN result1 [WHEN cds_cond2 THEN result2] [WHEN cds_cond3 THEN result3] ... [{ELSE resultn | ELSE NULL}] END
Cast expression
CAST( <expression> AS <datatype> [PRESERVING TYPE])
Reusing expressions from the SELECT list
$projection.elementName reuses an expression from the SELECT list in another operand position of the same CDS entity. This enables further processing of calculated fields and avoids the workaround of building a view stack for that purpose.
define view entity DEMO_CDS_EXPRESSION_REUSE as select from demo_expressions { //arithmetic expression abap.decfloat34'123.45E6' as arith, $projection.arith * 2 as arith_reuse, //cast expression cast(char1 as abap.numc(10)) as cast1, coalesce($projection.cast1, numc2) as cast_reuse, //built-in function abs(dec1) as builtIn, cast($projection.builtIn as abap.int4) as builtIn_reuse, }
Relational operators
Operator | Meaning | Release |
= | Equal | ABAP release 7.4 SP5 |
<> | Not equal | ABAP release 7.4 SP5 |
< | Less than | ABAP release 7.4 SP5 |
> | Greater than | ABAP release 7.4 SP5 |
<= | Less than or equal to | ABAP release 7.4 SP5 |
>= | Greater than or equal to | ABAP release 7.4 SP5 |
[NOT] BETWEEN | Interval comparison | ABAP release 7.4 SP5 |
LIKE | Pattern comparison | ABAP release 7.4 SP5 |
IS [NOT] NULL | Identifies the null value | ABAP release 7.4 SP5 |
IS [NOT] INITIAL | Identifies initial values | ABAP release 7.73 |
Path expressions
Path expressions can be used to include fields from associated sources in the field list of the CDS entity. A path expression can also go over several levels. It is also possible to add attributes to the evaluation of the associations, for example to filter or to define the join type.
Example:
_Items[1:currency <> 'EUR'].material = 'WOOD'
Amounts and quantities in expressions
Amount and quantity handling in expressions in ABAP CDS has been overhauled since ABAP release 7.56 | kernel release 7.84 | SAP BTP ABAP Environment 2105. See the following blog post for details: ABAP CDS Cheat Sheet: Amounts and Quantities in ABAP CDS | SAP Blogs.
Numeric functions
Function | Description | Release |
ABS(arg) | Positive absolute value of arg. | ABAP release 7.4 SP8 |
CEIL(arg) | Rounding up arg to the nearest integer | ABAP release 7.4 SP5 |
DIV(arg1, arg2) | Integer part of the division | ABAP release 7.4 SP8 |
DIVISION(arg1, arg2, dec) | arg1 divided by arg2 rounded to dec digits | ABAP release 7.4 SP8 |
FLOOR(arg) | Rounding down arg to the nearest integer | ABAP release 7.4 SP8 |
MOD(arg1, arg2) | Remainder of division of arg1 by arg2 (modulus) | ABAP release 7.4 SP5 |
ROUND(arg,pos) | Commercial rounding of arg, pos decimal places | ABAP release 7.4 SP8 |
String functions
Function | Description | Release |
CONCAT(arg1,arg2) | Concatenate arg1 and arg2. | ABAP release 7.4 SP8 |
CONCAT_WITH_SPACE(arg1, arg2, spaces) | Concatenate strings arg1 and arg2. The number of blanks specified in spaces is inserted between arg1 and arg2. | ABAP release 7.5 |
INSTR(arg,sub) | Position of the first occurrence of sub in arg. | ABAP release 7.5 |
LEFT(arg,len) | Left part of arg of length len. | ABAP release 7.5 |
LENGTH(arg) | Length of the string arg. | ABAP release 7.5 |
LOWER(arg) | Converts the string arg to lower case letters. | ABAP release 7.51 |
LPAD(arg,len,src) | Filling arg from left with src up to len. | ABAP release 7.4 SP5 |
LTRIM(arg,char) | Remove all occurrences of a character char from the left of arg, e.g. leading 0 or blank. | ABAP release 7.5 |
REPLACE(arg1, arg2, arg3) | Replaces arg2 in arg1 with arg3. | ABAP release 7.4 SP8 |
REPLACE_REGEXPR( PCRE => pcre, VALUE =>arg1, WITH => arg2, RESULT_LENGTH => res,optional:[OCCURRENCE], [CASE_SENSITIVE], [SINGLE_LINE], [MULTI_LINE], [UNGREEDY]) | Replaces the Perl Compatible Regular Expression (PCRE) pcre in the string arg1 with the character string arg2. Only available in CDS view entities. | ABAP release 7.57 kernel release 7.81 SAP BTP ABAP Environment 2208 |
RIGHT(arg,len) | Right part of arg of length len | ABAP release 7.5 |
RPAD(arg,len,src) | Filling arg from right with src up to len. | ABAP release 7.5 |
RTRIM(arg,char) | Remove all occurrences of a character char from the right of arg, e.g. trailing 0 or blank. | ABAP release 7.5 |
SUBSTRING(arg,pos,len) | Substring arg from the position pos with length len. | ABAP release 7.4 SP5 |
UPPER(arg) | Converts the string arg to upper case letters. | ABAP release 7.51 |
Coalesce function
The coalesce function checks for null values.
Syntax:
COALESCE( arg1, arg2 )
Conversion functions
Type conversion functions
Function | Description | Release |
FLTP_TO_DEC( arg AS dtype ) | Converts arg of data type FLTP to a packed number. | ABAP release 7.51 |
BINTOHEX( arg ) | Converts a byte string arg to a character string. | ABAP release 7.5 |
HEXTOBIN( arg ) | Converts a character string arg to a byte string. | ABAP release 7.5 |
Unit and currency conversion functions
Function | Description | Release |
UNIT_CONVERSION | Performs a unit conversion | ABAP release 7.4 SP8 |
CURRENCY_CONVERSION | Performs a currency conversion | ABAP release 7.4 SP8 |
GET_NUMERIC_VALIE | Returns the numeric value of a currency or quantity field without its currency or unit key. | ABAP release 7.56 Kernel release 7.83 SAP BTP ABAP Environment 2102 |
CURR_TO_DECFLOAT_AMOUNT | Converts a currency field of data type CURR into a currency field of data type DECFLOAT34. | ABAP release 7.56 Kernel release 7.83 SAP BTP ABAP Environment 2102 |
Date and time conversion functions
Function | Description | Release |
DATN_DAYS_BETWEEN(date1,date2) | Calculates the difference between date1 and date2. | ABAP release 7.54 kernel release 7.77 SAP BTP ABAP Environment 1908 |
DATN_ADD_DAYS(date,numdays) | Adds numdays days to date. | ABAP release 7.54 kernel release 7.77 SAP BTP ABAP Environment 1908 |
DATN_ADD_MONTHS(date,nummonths) | Adds nummonths months to date. | ABAP release 7.54 Kernel release 7.77 SAP BTP ABAP Environment 1908 |
DATS_IS_VALID(date) | Determines whether date contains a valid date. | ABAP release 7.5 |
DATS_DAYS_BETWEEN(date1,date2) | Calculates the difference between date1 and date2. | ABAP release 7.5 |
DATS_ADD_DAYS(date,numdays,on_error) | Adds numdays days to date. | ABAP release 7.5 |
DATS_ADD_MONTHS(date,nummonths,on_error) | Adds nummonths months to date. | ABAP release 7.5 |
TIMS_IS_VALID(time) | Determines whether time contains a valid time. | ABAP release 7.5 |
UTCL_CURRENT() | Generates a UTC time stamp (data type UTCLONG). | ABAP release 7.54 Kernel release 7.77 SAP BTP ABAP Environment 1908 |
UTCL_ADD_SECONDS(utcl,numseconds) | Adds numseconds seconds to the timestamp utcl. | ABAP release 7.54 Kernel release 7.77 SAP BTP ABAP Environment 1908 |
UTCL_SECONDS_BETWEEN(utcl1,utcl2) | Calculates the difference between utcl1 and utcl2. | ABAP release 7.54 Kernel release 7.77 SAP BTP ABAP Environment 1908 |
TSTMP_IS_VALID(tstmp) | Determines whether tstmp contains a valid time stamp. | ABAP release 7.5 |
TSTMP_CURRENT_UTCTIMESTAMP() | Generates a UTC time stamp (data type DEC). | ABAP release 7.5 |
TSTMP_SECONDS_BETWEEN(tstmp1,tstmp2,on_error) | Calculates the difference between tstmp1 and tstmp2. | ABAP release 7.5 |
TSTMP_ADD_SECONDS(tstmp,numseconds,on_error) | Adds numseconds seconds to the timestamp tstmp. | ABAP release 7.5 |
ABAP_SYSTEM_TIMEZONE(clnt,on_error) | Returns the current system time zone. | ABAP release 7.51 |
ABAP_USER_TIMEZONE(user,clnt,on_error) | Returns the current user time zone. | ABAP release 7.51 |
TSTMP_TO_DATS(tstmp,tzone,clnt,on_error) | Extracts the local data for the time zone specified in tzone from a time stamp tstmp. | ABAP release 7.51 |
TSTMP_TO_TIMS(tstmp,tzone,clnt,on_error) | Extracts the local time for the time zone specified in tzone from a time stamp tstmp. | ABAP release 7.51 |
TSTMP_TO_DST(tstmp,tzone,clnt,on_error) | Extracts the daylight saving time marker for the time zone specified in tzonefrom a time stamp tstmp. | ABAP release 7.51 |
DATS_TIMS_TO_TSTMP(date,time,tzone,clnt,on_error) | Constructs a time stamp from date and timein the time zone tzone. | ABAP release 7.51 |
TSTMPL_TO_UTCL(tstmpl,on_error,on_initial) | Converts a time stamp from data type TIMESTAMPL to UTCLONG. | ABAP release 7.54 Kernel release 7.77 SAP BTP ABAP Environment 1908 |
TSTMPL_FROM_UTCL(utcl,on_null) | Converts a time stamp from data type UTCLONG to TIMESTAMPL. | ABAP release 7.54 Kernel release 7.77 SAP BTP ABAP Environment 1908 |
DATS_TO_DATN(dats,on_error,on_initial) | Converts a date from data type DATS to data type DATN. | ABAP release 7.54 Kernel release 7.77 SAP BTP ABAP Environment 1908 |
DATS_FROM_DATN(datn,on_null) | Converts a date from data type DATN to data type DATS. | ABAP release 7.54 Kernel release 7.77 SAP BTP ABAP Environment 1908 |
TIMS_TO_TIMN(tims,on_error) | Converts a time from data type TIMS to data type TIMN. | ABAP release 7.54 Kernel release 7.77 SAP BTP ABAP Environment 1908 |
TIMS_FROM_TIMN(timn,on_null) | Converts a time from data type TIMN to data type TIMS. | ABAP release 7.54 Kernel release 7.77 SAP BTP ABAP Environment 1908 |
Expressions and built-in functions can be nested within each other. The expression matrix has been enhanced in the past releases.
Example:
case cast( _a.char1 as char3) when substring( cast( 'AA' as char2), $parameters.p1, 2*2) then 'text1' when case 'a' when 'b' then 'c' end then 'text2' else NULL end as CaseExp
System entity | Description |
SERIES_GENERATE_DATE | CDS table function that creates a table with a series of dates. |
SERIES_GENERATE_INTEGER | CDS table function that creates a table with a series of numbers. |
SERIES_GENERATE_TIME | CDS table function that creates a table with a series of times. |
SERIES_GENERATE_TIMESTAMP | CDS table function that creates a table with a series of time stamps. |
FINAL(current_date) = sy-datum. FINAL(one_year_later) = current_date + 365. SELECT * FROM series_generate_date( step = 30, from_value = @current_date, to_value = @one_year_later ) ORDER BY element_number INTO TABLE @FINAL(date_series_gen). cl_demo_output=>display( date_series_gen ).Returns a series of dates:
EXTEND VIEW ENTITY |
| 7.87 | 1911 | 7.55 |
EXTEND CUSTOM ENTITY | CDS custom entity | 7.89 | 2208 | 7.57 |
EXTEND ABSTRACT ENTITY | CDS abstract entity | 7.84 | 2105 | 7.56 |
EXTEND VIEW | CDS DDIC-based view | ABAP release 7.40, SP08 |
More role-based learning resources and opportunities to get certified are available in one place on the SAP Learning site: SAP Learning
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
3 | |
2 | |
2 | |
2 | |
2 | |
2 | |
2 | |
1 | |
1 |