SAP CDS TYPING



Get Example source ABAP code based on a different SAP table
  



ABAP_CDS_DDL - typing

ABAP_SYNTAX
... dtype $| data_element $| simple_type ...

What does it do?
Types elements or parameters of CDS entities in CDS DDL. The following is typed:
Elements of CDS entities:
Elements of the element list element_list in a CDS table function.
Elements of the element list element_list in a CDS custom entity.
Elements of the element list element_list of a CDS abstract entity.
Typed literals in a CDS view entity or a CDS hierarchy.
CDS virtual elements in a CDS projection view.
Input parameters of CDS entities
Input parameters of the parameter list parameter_list in a CDS view entity
Input parameters of the parameter list parameter_list in a CDS analytical projection view
Input parameters of the parameter list parameter_list in a CDS table function.
Input parameters of the parameter list parameter_list in a CDS hierarchy.
Input parameters of the parameter list parameter_list in an CDS custom entity.
Input parameters of the parameter list parameter_list in an CDS abstract entity.
Input parameters of the parameter list parameter_list in a ABAP_CDS_V1_VIEW
Typing can be specified as follows:
Using a built-in data type in ABAP Dictionary dtype.
Using the name of a CDS simple type simple_type.
Using the name of a DDIC data element data_element.
The table below shows the possible options for dtype and their meanings. The last two columns indicate whether the typing is possible for elements or input parameters. dtypeBuilt-In Data Type in ABAP Dictionary ElementParameter
BEGIN_SECTION VERSION 5 OUT
abap.accp(6)ACCP (only in a table function)x-
END_SECTION VERSION 5 OUT
abap.char( len )CHAR with length lenxx
abap.clnt$[(3)$]CLNTx x
abap.cuky$[(5)$]CUKY x x
abap.curr(len,dec)CURR with length len and with dec decimal placesxx
abap.d16n$[(16)$]DECFLOAT16 xx
abap.d34n$[(34)$]DECFLOAT34 xx
abap.datn$[(8)$]DATNx x
abap.dats$[(8)$]DATSx x
abap.dec(len,dec)DEC with length len and with dec decimal placesxx
abap.fltp$[(16,16)$]FLTP xx
abap.geom_ewkbGEOM_EWKB x-
abap.int1$[(3)$]INT1x x
abap.int2$[(5)$]INT2x x
abap.int4$[(10)$]INT4x x
abap.int8$[(19)$]INT8x x
abap.lang$[(1)$]LANG x x
abap.numc( len )NUMC with length lenxx
abap.quan(len,dec)QUAN with length len and with dec decimal placesxx
abap.raw(len)RAW with length lenxx
abap.rawstringRAWSTRING x-
abap.sstring(len)SSTRING with length lenxx
abap.stringSTRING x-
abap.timn$[(6)$]TIMN x x
abap.tims$[(6)$]TIMS x x
abap.unit$[(2$|3)$]UNIT with length 2 or 3 (standard length)xx
abap.utcl$[(27)$]UTCLONG xx
len and dec must be used to specify values for the length and decimal places of the respective generic types. The values specified here in parentheses must be within the value ranges allowed by ABAP Dictionary. For data types with fixed lengths and decimal places, it is possible, but not mandatory to specify the predefined value for length and decimal places. The exception in this regard is abap.accp: this type has the predefined length of 6, which must always be specified in parentheses. For data_element, every ABAP Dictionary data element whose built-in type is listed in the table above can be specified.



Latest notes:

Currently, only elementary data types are supported and no structured or tabular parameters.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
The following CDS view entity has two input parameters. p_date is typed with the simple type DEMO_BT_DATE and p_num is typed with the built-in data type DEC with a specified length and number of decimal places.
DDLS DEMO_CDS_PARAMETER_TYPE_VE
The class CL_DEMO_CDS_PARAMETER_TYPE accesses the view using the following SELECT statement: SELECT id, col_date, col_num
FROM demo_cds_parameter_type_ve( p_date = @sy-datlo,
p_num = '1.234' )
INTO TABLE @DATA(result).
ABAP_EXAMPLE_END