CDS simple types provide a modern way to create user-defined elementary data types directly in ABAP CDS. Other than classical DDIC data elements, CDS simple types allow the creation of type hierarchies and attaching domain-specific semantics via CDS annotations. Read this blog post for more details.
2302 SAP BTP ABAP Environment
ABAP Release 7.58
SAP S/4HANA 2023
Comparison: Data elements and simple types
Here are the differences between DDIC data elements and CDS simple types:
DDIC data elements
CDS simple types
For typing in DDIC, CDS, and ABAP
For typing in CDS and in ABAP.
Reusable data types for typing in ABAP and in ABAP CDS.
Reusable data types for typing in ABAP and CDS that can be nested with each other.
Technical settings in SE11.
CDS annotations for domain-specific metadata
Form-based editor and DDIC DDL. Design time.
Syntax-based definition in ADT. Desgin time.
Supported by technologies such as WebDynpro and SAP GUI.
Supported by frameworks such as RAP and the ABAP Analytical Engine.
Defining a CDS simple type
Defining a CDS simple type is really easy.
In ADT, a simple type is created as a repository object of type Type.
You can specify some annotations and then all you have to do is give it a name and a type after the statement DEFINE TYPE.
DEFINE TYPE simple_type : typing
Here's an example:
@EndUserText.label: ‘This is a CDS simple type’
DEFINE TYPE myType : abap.int4;
Typing of a CDS simple type
A CDS simple type can be typed using a DDIC data element, a built-in data type, or using another simple type.
Typing with a DDIC data element
When a CDS simple type is typed with a DDIC data element, the technical and semantic properties of the data element are inherited by the CDS simple type and translated into annotation values. The following table shows the mapping of DDIC properties to simple types:
CDS simple type annotation
Flag for change document
Field label, Heading
Field label, Medium
Here's an example of inheritance from a data element to a CDS simple type. The simple type DEMO_SIMPLE_TYPE_INHERITANCE is typed using a DDIC data element.
define type demo_simple_type_inheritance: demo_bt_inheritance;
The Active Annotations View in ADT shows that all annotations derived from the underlying data element and from the DDIC domain are translated into annotation values:
Active Annotations View
2. Typing using a built-in data type
A CDS simple type can be typed using a built-in data type. Almost all built-in data types from ABAP Dictionary are possible. Here's an example:
Second simple type that is based on the first simple type:
define type DEMO_SIMPLE_TYPE_2 : DEMO_SIMPLE_TYPE;
Using a CDS simple type
A CDS simple type can be used in ABAP CDS for typing of elements and parameters and for casting. In ABAP, CDS simple types can be used for type declarations after the TYPE statement. Here are some examples:
Using a CDS simple type in a CDS view entity
The following CDS view entity uses a CDS simple type in a cast expression and for typing the input parameter p1.
@EndUserText.label: 'CDS view entity, simple types'
define view entity DEMO_CDS_SIMPLE_TYPE_USAGE
p1 : demo_simple_type
as select from demo_expressions
key id as Id,
num1 as Num1,
$parameters.p1 as Parameter1,
cast( char2 as demo_simple_type_de ) as cast_bt
2. Using a CDS simple type in an ABAP program
Simple types can be used for typing in ABAP programs after the TYPES statement in the same way as DDIC data elements. Here's an example:
DATA MyType TYPE demo_simple_type.
MyType = 1.
ABAP Cloud is a new development model that aims at modernizing and simplifying the ABAP programming language. It takes place entirely in ADT and relies on ABAP CDS for the data modeling layer. Therefore, there is a lot of investment in ABAP CDS features to provide maximum ease of use.
CDS simple types are another step in the modernization of the ABAP language. ABAP Dictionary is receding into the background, while users are encouraged to use ABAP CDS.
Another CDS-native data type will be made available soon: The CDS enumerated type to define globally available enumerated types. Be prepared!