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.
Release info:
Here are the differences between DDIC data elements and CDS simple types:
Property | DDIC data elements | CDS simple types |
Availability | For typing in DDIC, CDS, and ABAP | For typing in CDS and in ABAP. |
Reuse capabilities | 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. |
Metadata | Technical settings in SE11. | CDS annotations for domain-specific metadata |
Definition | Form-based editor and DDIC DDL. Design time. | Syntax-based definition in ADT. Desgin time. |
Framework support | 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 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.
[@type_annot1]
[@type_annot2]
...
DEFINE TYPE simple_type : typing
Here's an example:
@EndUserText.label: ‘This is a CDS simple type’
DEFINE TYPE myType : abap.int4;
A CDS simple type can be typed using a DDIC data element, a built-in data type, or using another simple type.
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:
DDIC property | CDS simple type annotation |
Conversion routing | @AbapCatalog.typeSpec.conversionExit |
Lowercase letters | @ObjectModel.upperCase |
Flag for change document | @AbapCatalog.typeSpec.changeDocumentRelevant |
Field label, Heading | @EndUserText.heading |
Field label, Medium | @EndUserText.label |
Short Text | @EndUserText.quickInfo |
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
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:
@EndUserText.heading: 'abc'
@EndUserText.label: 'myLabel'
@EndUserText.quickInfo: 'lala'
define type demo_simple_type : abap.int4;
A CDS simple type can be typed with another simple type. Annotations are inherited, but it is also possible to overwrite the inherited annotation values.
Here's an example:
First layer simple type:
@EndUserText.heading: 'abc'
@EndUserText.label: 'myLabel'
@EndUserText.quickInfo: 'lala'
define type demo_simple_type : abap.int4;
Second simple type that is based on the first simple type:
define type DEMO_SIMPLE_TYPE_2 : DEMO_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:
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
with parameters
p1 : demo_simple_type
as select from demo_expressions
{
key id as Id,
num1 as Num1,
char1,
$parameters.p1 as Parameter1,
cast( char2 as demo_simple_type_de ) as cast_bt
}
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
8 | |
6 | |
5 | |
4 | |
4 | |
4 | |
4 | |
4 | |
3 | |
2 |