SAP CDS SCALAR TYPING



Get Example source ABAP code based on a different SAP table
  


VERSION 5 IN
• TYPE OF ABAP_CDS_SCALAR

ABAP_CDS_FDL - typing

ABAP_SYNTAX

dtype $[ WITH REFERENCE TYPE$]
$| simple_type $[ WITH REFERENCE TYPE$]
$| data_element $[ WITH REFERENCE TYPE$]
$| generic_type $[ WITH REFERENCE TYPE$]
$| TYPE OF ParameterReference $[WITH REFERENCE TYPE$]

ABAP Addition
... WITH REFERENCE TYPE

What does it do?
The input parameters of SQL-based scalar functions can be typed as follows:
Using a built-in ABAP Dictionary data type .
Using a CDS simple type defined using DEFINE TYPE.
Using a DDIC data element.
Using the generic data type numeric . ABAP_NOTE The generic type any is only available for analytical scalar functions.
Referencing another input parameter using the syntax statement TYPE OF ParameterReference. ParameterReference can be any input parameter from the parameter list of the current scalar function that is typed with a built-in data type, a simple type, a data element, or a generic type. ABAP_NOTE You cannot reference the return parameter. ABAP_NOTE You cannot reference an input parameter that itself references an input parameter.
The return parameter of an SQL-based scalar function can be typed as follows:
Using a built-in ABAP Dictionary data type.
Using a CDS simple type defined using DEFINE TYPE.
Using a DDIC data element.
Referencing another input parameter using the syntax statement TYPE OF ParameterReference. ParameterReference can be any of the input parameters from the parameter list of the current scalar function that is typed with a built-in data type, a simple type, a data element, or a generic type. ABAP_NOTE You cannot reference an input parameter that itself references an input parameter.

ABAP_EXAMPLE_VX5
The following example demonstrates the definition, implementation, and use of an SQL-based scalar function with input parameters.
CDS scalar function definition
The following CDS scalar function DEMO_CDS_SCALAR_RATIO defines two input parameters:
portion: Typed with the generic type numeric. Accepts all available reference types.
total: Typed with reference to the input parameter portion .
The return parameter is typed with a built-in data type.
DSFD DEMO_CDS_SCALAR_RATIO
CDS scalar function implementation reference
The scalar function implementation reference DEMO_CDS_SCALAR_RATIO_SQL binds the scalar function to the SQL Engine and defines the method EXECUTE of the class CL_DEMO_CDS_SCALAR_RATIO as AMDP function implementation.
AMDP function implementation
The following listing shows the AMDP function implementation. The input parameter portion is divided by the input parameter total and multiplied by 100 to get the percentage of portion in relation to total.
METH CL_DEMO_CDS_SCALAR_RATIO=>EXECUTE
Use in a CDS view entity
The following CDS view entity uses the scalar function DEMO_CDS_SCALAR_RATIO as an element in the SELECT list to calculate the occupancy of a flight.
DDLS DEMO_CDS_SCALAR_USE_RATIO
Access Using AB-SQL
The following code snippet demonstrates how the CDS view entity can be accessed. The value of the column OccupationRatio is calculated by the AMDP function implementation.
ABEXA 01766
ABAP_EXAMPLE_END

ABAP Addition

What does it do?
Specifies a reference type. Reference types allow the handling of CDS amount fields and CDS quantity fields. The addition is described in topic TITLE .