Feature Matrix: Data Modeling with ABAP Core Data Services
source link: https://blogs.sap.com/2022/10/24/feature-matrix-data-modeling-with-abap-core-data-services/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Feature Matrix: Data Modeling with ABAP Core Data Services
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: 2022-10 |
Contents:
- CDS entities
- CDS associations (“normal”, compositions, and to-parent)
- Clauses
- Operands and expressions
- Operands
- Typed literal
- Untyped literal
- Field
- Parameter
- Session variable
- Expressions
- Arithmetic expression
- Aggregate function
- Case distinction (simple and complex)
- Cast expression (including new casts since release 7.55)
- Reusing expressions from the SELECT list with $projection
- Relational operators
- Path expressions
- Amounts and quantities in expressions
- Built-in functions
- Numeric functions
- String functions
- Coalesce function
- Conversion functions (type conversion, unit and currency conversion, date and time conversion)
- Operands
- CDS system entities
- CDS tuning objects
- CDS entity extensions
- Development pipeline
1. CDS entities
The following CDS entities are available in release ABAP Platform 2022 for data modeling.
CDS entity type | ABAP CDS statement | Purpose | Release | Further info |
CDS view entity |
DEFINE VIEW ENTITY |
|
||
CDS projection view of type transactional query | DEFINE VIEW ENTITY PROVIDER CONTRACT TRANSACTIONAL_QUERY AS PROJECTION ON |
|
||
CDS projection view of type transactional interface | DEFINE VIEW ENTITY PROVIDER CONTRACT TRANSACTIONAL_INTERFACE AS PROJECTION ON |
|
||
CDS projection view of type analytical query | DEFINE TRANSIENT VIEW ENTITY PROVIDER CONTRACT ANALYTICAL_QUERY AS PROJECTION ON |
|
||
CDS table function | DEFINE TABLE FUNCTION |
|
||
CDS hierarchy | DEFINE HIERARCHY |
|
||
CDS custom entity | DEFINE CUSTOM ENTITY |
|
Docu | |
CDS abstract entity | DEFINE ABSTRACT ENTITY |
|
||
CDS DDIC-based view (obsolete) | DEFINE VIEW |
|
7.40 SP05 |
Did you know?
- Check our Data Source Matrix to learn how to combine data sources in CDS: Data sources after FROM and association targets.
- CDS entities are like chameleons: even after you’ve activated and transported an entity, you can change the type of your CDS entity. For example, you have a CDS view and want to convert it into a custom entity for specialization. Or you want to convert an abstract entity into a view to have more options. As long as the consumers are not affected, just change the syntax and activate and transport the changed object.
2. CDS associations
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:
“Normal”, not specialized CDS association
- Available since 7.4 SP5.
- Available in CDS view entities, CDS projection views, CDS custom entities, CDS abstract entities, and CDS DDIC-based views.
- Docu
- Syntax:
ASSOCIATION [ [min..max] ] TO target [AS _assoc] ON cds_cond
[ WITH DEFAULT FILTER cds_cond ]
CDS composition
- Specialized CDS association that defines the current entity as parent and the composition target as child.
- Available since ABAP 7.75, OP 1809 SP01.
- Available in CDS view entities, CDS projection views, CDS custom entities, CDS abstract entities, and CDS DDIC-based views.
- Docu
- Syntax:
COMPOSITION [ [min..max] ] OF target [AS _compos]
Association to parent
- Specialized CDS association that defines the current entity as child and the association target as parent. The child depends on the parent and cannot exist without the parent. For example, a sales order item (composition child) always belongs to a sales order header (composition parent).
- Available since ABAP 7.75, OP 1809 SP01.
- Available in CDS view entities, CDS projection views, CDS custom entities, CDS abstract entities, and CDS DDIC-based views.
- Docu
- Syntax:
ASSOCIATION TO PARENT target [AS _assoc] ON $projection.cds_cond
3. Clauses
Clause | Function | Release | Further info |
WHERE | Defines a filter condition. | 7.4 SP5 | Docu |
GROUP BY | Groups the rows in the result set by their content. Required as soon as there are aggregate expressions. | 7.4 SP5 | Docu |
HAVING | Can be used together with GROUP BY to specify a further filter condition. | 7.4 SP5 | Docu |
EXCEPT |
Returns all distinct rows of the first result set that are not part of the following result sets. |
Docu | |
INTERSECT |
Returns all distinct rows that are part of all result sets. |
||
UNION |
Merges the result sets of all queries. |
7.4 SP5 |
4. Operands and expressions
4.1 Operands
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′ |
Docu | |
Untyped literal |
Data types: char, int1, int2, int4, int8, fltp. Note: Typed should be preferred over untyped! |
7.4 SP5 | Docu |
Field | Field of a data source of the current entity. Alias name using AS. If several data sources, prefix recommended. | 7.4 SP5 | Docu |
Parameter | Input parameter from the parameter list. | 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:
|
7.5, some were added later | Docu |
4.2 Expressions
Arithmetic expressions
- Available since 7.4 SP5
- Docu
Operator | Meaning |
+ | Addition |
– | Subtraction |
* | Multiplication |
/ | Division |
Aggregate functions
- Available since 7.4 SP5
- Docu
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
- Simple case is available since 7.4 SP5
- Searched case is available since 7.4 SP8
- New in release 7.89 | 7.57 | 2208: THEN ELSE NULL is available to explicitly define the null value as return value if no matches are found.
- Docu
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
- Data type conversion
- Available since 7.4 SP5, but the cast matrix has been extended over time.
- Docu (including full cast matrix)
- Syntax:
-
CAST( <expression> AS <datatype> [PRESERVING TYPE])
- New casts since release 7.55
-
FROM TO SSTRING DEC, CURR, QUAN, INT1, INT2, INT4, INT8, DECFLOAT16, and DECFLOAT34 CHAR DEC, CURR, QUAN, INT1, INT2, INT4, INT8, DECFLOAT16, and DECFLOAT34 DATS DEC, CURR, QUAN, INT1, INT2, INT4, INT8, DECFLOAT16, and DECFLOAT34 TIMS DEC, CURR, QUAN, INT1, INT2, INT4, INT8, DECFLOAT16, and DECFLOAT34 DECFLOAT16 CHAR DECFLOAT34 CHAR FLTP DEC, CURR, QUAN, INT1, INT2, INT4, INT8, DECFLOAT16, and DECFLOAT34
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.
- Available since 7.56 | 7.84 | 2105
- Docu
- Example:
-
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 | 7.4 SP5 |
<> | Not equal | 7.4 SP5 |
< | Less than | 7.4 SP5 |
> | Greater than | 7.4 SP5 |
<= | Less than or equal to | 7.4 SP5 |
>= | Greater than or equal to | 7.4 SP5 |
[NOT] BETWEEN | Interval comparison | 7.4 SP5 |
LIKE | Pattern comparison | 7.4 SP5 |
IS [NOT] NULL | Identifies the null value | 7.4 SP5 |
IS [NOT] INITIAL | Identifies initial values | 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 release 7.56 | 7.84 | 2105. See the following blog post for details: ABAP CDS Cheat Sheet: Amounts and Quantities in ABAP CDS | SAP Blogs.
4.3 Built-in functions
Numeric functions
Function | Description | Release |
ABS(arg) | Positive absolute value of arg. | 7.4 SP8 |
CEIL(arg) | Rounding up arg to the nearest integer | 7.4 SP5 |
DIV(arg1, arg2) | Integer part of the division | 7.4 SP8 |
DIVISION(arg1, arg2, dec) | arg1 divided by arg2 rounded to dec digits | 7.4 SP8 |
FLOOR(arg) | Rounding down arg to the nearest integer | 7.4 SP8 |
MOD(arg1, arg2) | Remainder of division of arg1 by arg2 (modulus) | 7.4 SP5 |
ROUND(arg,pos) | Commercial rounding of arg, pos decimal places | 7.4 SP8 |
String functions
Function | Description | Release |
CONCAT(arg1,arg2) | Concatenate arg1 and arg2. | 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. | 7.5 |
INSTR(arg,sub) | Position of the first occurrence of sub in arg. | 7.5 |
LEFT(arg,len) | Left part of arg of length len. | 7.5 |
LENGTH(arg) | Length of the string arg. | 7.5 |
LOWER(arg) | Converts the string arg to lower case letters. | 7.51 |
LPAD(arg,len,src) | Filling arg from left with src up to len. | 7.4 SP5 |
LTRIM(arg,char) | Remove all occurrences of a character char from the left of arg, e.g. leading 0 or blank. | 7.5 |
REPLACE(arg1, arg2, arg3) | Replaces arg2 in arg1 with arg3. | 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. |
|
RIGHT(arg,len) | Right part of arg of length len | 7.5 |
RPAD(arg,len,src) | Filling arg from right with src up to len. | 7.5 |
RTRIM(arg,char) | Remove all occurrences of a character char from the right of arg, e.g. trailing 0 or blank. | 7.5 |
SUBSTRING(arg,pos,len) | Substring arg from the position pos with length len. | 7.4 SP5 |
UPPER(arg) | Converts the string arg to upper case letters. | 7.51 |
Coalesce function
The coalesce function checks for null values.
Syntax:
COALESCE( arg1, arg2 )
It checks whether arg1contains a null value. If yes, then it returns the value of arg2. If no, then it returns the value of arg1. If both arg1and arg2are null, then the null value is returned.
Available since 7.4 SP08
Conversion functions
Type conversion functions
- Cover special data types that cannot be handled using a cast expression
- Docu
Function | Description | Release |
FLTP_TO_DEC( arg AS dtype ) | Converts arg of data type FLTP to a packed number. | 7.51 |
BINTOHEX( arg ) | Converts a byte string arg to a character string. | 7.5 |
HEXTOBIN( arg ) | Converts a character string arg to a byte string. | 7.5 |
Unit and currency conversion functions
Function | Description | Release |
UNIT_CONVERSION | Performs a unit conversion | 7.4 SP8 |
CURRENCY_CONVERSION | Performs a currency conversion | 7.4 SP8 |
GET_NUMERIC_VALIE | Returns the numeric value of a currency or quantity field without its currency or unit key. | |
CURR_TO_DECFLOAT_AMOUNT | Converts a currency field of data type CURR into a currency field of data type DECFLOAT34. |
Date and time conversion functions
- Perform operations with dates, times, and timestamps.
- Docu
Function | Description | Release |
DATN_DAYS_BETWEEN(date1,date2) | Calculates the difference between date1 and date2. | 7.54 7.77 1908 |
DATN_ADD_DAYS(date,numdays) | Adds numdays days to date. | 7.54 7.77 1908 |
DATN_ADD_MONTHS(date,nummonths) | Adds nummonths months to date. | 7.54 7.77 1908 |
DATS_IS_VALID(date) | Determines whether date contains a valid date. | 7.5 |
DATS_DAYS_BETWEEN(date1,date2) | Calculates the difference between date1 and date2. | 7.5 |
DATS_ADD_DAYS(date,numdays,on_error) | Adds numdays days to date. | 7.5 |
DATS_ADD_MONTHS(date,nummonths,on_error) | Adds nummonths months to date. | 7.5 |
TIMS_IS_VALID(time) | Determines whether time contains a valid time. | 7.5 |
UTCL_CURRENT() | Generates a UTC time stamp (data type UTCLONG). | 7.54 7.77 1908 |
UTCL_ADD_SECONDS(utcl,numseconds) | Adds numseconds seconds to the timestamp utcl. | 7.54 7.77 1908 |
UTCL_SECONDS_BETWEEN(utcl1,utcl2) | Calculates the difference between utcl1 and utcl2. | 7.54 7.77 1908 |
TSTMP_IS_VALID(tstmp) | Determines whether tstmp contains a valid time stamp. | 7.5 |
TSTMP_CURRENT_UTCTIMESTAMP() | Generates a UTC time stamp (data type DEC). | 7.5 |
TSTMP_SECONDS_BETWEEN(tstmp1,tstmp2,on_error) | Calculates the difference between tstmp1 and tstmp2. | 7.5 |
TSTMP_ADD_SECONDS(tstmp,numseconds,on_error) | Adds numseconds seconds to the timestamp tstmp. | 7.5 |
ABAP_SYSTEM_TIMEZONE(clnt,on_error) | Returns the current system time zone. | 7.51 |
ABAP_USER_TIMEZONE(user,clnt,on_error) | Returns the current user time zone. | 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. | 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. |
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. |
7.51 |
DATS_TIMS_TO_TSTMP(date,time,tzone,clnt,on_error) |
Constructs a time stamp from date and timein the time zone tzone. |
7.51 |
TSTMPL_TO_UTCL(tstmpl,on_error,on_initial) | Converts a time stamp from data type TIMESTAMPL to UTCLONG. | 7.54 7.77 1908 |
TSTMPL_FROM_UTCL(utcl,on_null) | Converts a time stamp from data type UTCLONG to TIMESTAMPL. | 7.54 7.77 1908 |
DATS_TO_DATN(dats,on_error,on_initial) |
Converts a date from data type DATS to data type DATN. |
7.54 7.77 1908 |
DATS_FROM_DATN(datn,on_null) | Converts a date from data type DATN to data type DATS. | 7.54 7.77 1908 |
TIMS_TO_TIMN(tims,on_error) | Converts a time from data type TIMS to data type TIMN. | 7.54 7.77 1908 |
TIMS_FROM_TIMN(timn,on_null) | Converts a time from data type TIMN to data type TIMS. | 7.54 7.77 1908 |
Expressions and built-in functions can be nested within each other. The expression matrix has been enhanced in the past releases.
Example:
- Nesting of case and cast
- Substring with cast, parameter, and arithmetic expression as operands
- Nesting of case with another case.
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
5. CDS system entities
- CDS system entities are CDS entities delivered with an ABAP Platform that implement basic functionality, similar to ABAP system classes.
- Can be used as data source in other CDS entities or in ABAP SQL.
- Available since 7.56 | 7.84 | 2105
- Docu
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. |
Example: Creating a series of dates using the CDS system entity SERIES_GENERATE_DATE:
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:
6. CDS tuning objects
- A CDS tuning object is a CDS object defined with CDS DDL in ADT that defines technical properties of a CDS entity.
- Currently, there is only one type of CDS tuning object available: the CDS entity buffer.
- A CDS entity buffer is defined using DEFINE ENTITY BUFFER ON.
- Available since 7.57 | 7.87 | 2202
- Docu
- Buffering CDS View Entities | SAP Blogs
7. CDS entity extensions
Statement | Can be used for | Available since |
---|---|---|
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 | 7.40, SP08 |
8. Development pipeline
What can you expect to see in future releases? The following features appeared in my crystal ball. But hey: no guarantee, no legal claims to be made:
- CDS simple types: Self-defined data types that might be simple or structured and can be used wherever a built-in type can be used. Similar to data elements or structures in ABAP Dictionary. Syntax: DEFINE TYPE.
- CDS scalar functions: Self-defined functions. Similar to ABAP-Managed Database Procedures (AMDP) but can be specified directly in a CDS view and can be used in different runtimes. Syntax: DEFINE SCALAR FUNCTION.
- CDS aspects: Reusable artifacts in CDS. CDS aspects allow decomposing entity definitions into parts with different lifecycles, in this way enabling separation of concerns. The approach is borrowed from disciplines like aspect-oriented programming.
ABAP CDS celebrates its 10th anniversary this year. In September 2012, the ABAP CDS workstream was set up, and that’s how it all started rolling. What is your experience with ABAP CDS? Has it made development easier? Are you missing any features? Do you need more rollout or support? Feel free to use the Comments section below to share your personal experiences with ABAP Core Data Services.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK