What does it do? Defines a CDS simple type> in the CDS TDL>. A CDS simple type defines an elementary data type> natively in ABAP CDS>. A CDS simple type can be enriched with CDS annotations> type_annot>>. All annotations are optional and a simple type can also be created without any annotations. If specified, the type annotations must be defined in front of the statement DEFINE TYPE >. The name simple_type> of the CDS simple type is defined after the DEFINE TYPE> statement. It is in the namespace of all global types> of an AS ABAP. The general rules for CDS object names described in topic ABAP CDS - General Syntax Rules> apply. The name of the CDS simple type must be the same as the name of the TDL source code.
Typing A simple type can be typed as follows:
Using a built-in ABAP Dictionary data type dtype >>. All possible types and rules are described in the topic CDS Simple Type, dtype>>.
Using a DDIC data element> data_element>>. The rules, including inheritance rules, are described in topic CDS Simple Type, data_element>>.
Using another CDS simple type simple_type > >. The rules are described in topic CDS Simple Type, simple_type>>.
ABAP_USE CDS simple types can be used in the following places:
To type another CDS simple type. ABAP_NOTE The maximum nesting depth is five. This means that a stack of simple types can have a maximum of five layers, from base to top-most.
In cast expressions in CDS view entities >.
In cast expressions in CDS projection views>. ABAP_NOTE Remember that casting in CDS projection views is only possible with the addition PRESERVING TYPE>. Example>: cast(ProjField as MySimpleType preserving type) as NewProjField>
For typing> of elements in CDS custom entities> and in CDS abstract entities>.
For typing> of parameters in ABAP_CDS_V2_VIEWS >, CDS analytical projection views>, CDS custom entities, CDS abstract entities, and CDS hierarchies>.
For typing of CDS virtual elements > in CDS projection views>.
For typing> the input parameters or the return parameter of SQL-based scalar functions>.
In ABAP for typing data objects with the statement TYPE>.
ABAP_RESTRICTIONS
CDS simple types cannot be used in ABAP_CDS_V1_VIEWS >.
CDS simple types cannot be used for typing in DDIC objects such as DDIC data types>, DDIC views>, and DDIC extensions>.
Unlike DDIC data elements, there is no search help assignment> available for CDS simple types.
CDS simple types cannot be used in CDS table functions>. ABAP_RESTR_END
Latest notes: If a ABAP_CDS_V1_VIEWS selects from a view entity that is typed with a simple type, then the simple type information is available in the metadata of the CDS entity, but not in the metadata of the CDS-managed DDIC view>. NON_V5_HINTS ABAP_HINT_END
ABAP_EXAMPLE_VX5 - Evaluation of Annotations of a Simple Type The following CDS simple type is based on a DDIC data element. DRTY DEMO_SIMPLE_TYPE_DE The semantic information of the data element is inherited to the simple type and translated into annotations. These annotations and their values can be seen in the Active Annotations> view in ADT: IMAGE st_active_anno.jpg 756 202 The class CL_DEMO_CDS_SIMPLE_TYPE> > demonstrates the following:
The data type and length of a CDS simple type can be evaluated using RTTI> methods.
The annotations of the CDS simple type can be evaluated> using the class CL_DD_DDL_ANNOTATION_SERVICE>>. ABAP_EXAMPLE_END
ABAP_EXAMPLE_VX5 - Using Simple Types for Typing in a CDS View Entity The following CDS view entity uses a CDS simple type for typing of parameters p1> and p2>. It casts element cast_bt> into a simple type. DDLS DEMO_CDS_SIMPLE_TYPE_USAGE The following code snippet demonstrates how the metadata of the CDS view entity can be evaluated using the class CL_DD_CDS_READ_API_FACTORY>>. The tables that are generated as output have columns that indicate whether a field or parameter is typed with reference to a simple type. ABEXA 01752 ABAP_EXAMPLE_END