SAP CDS SQL SCALAR FUNCTION



Get Example source ABAP code based on a different SAP table
  


VERSION 5 IN

ABAP_CDS - SQL-Based Scalar Functions
SQL-based scalar functions are scalar functions that are evaluated by an SQL environment. They can be used in CDS view entities in operand positions that expect scalar values, similar to built-in functions.
While analytical scalar functions are defined and implemented by SAP, SQL-based scalar functions can also be defined and implemented by customers and partners. SQL-based scalar functions make user-defined AMDP scalar functions known to the ABAP Dictionary and available in ABAP CDS.
An SQL-based scalar function consists of three development objects:
A scalar function definition defined using DEFINE SCALAR FUNCTION in a CDS function definition . It is located in the namespace of all global types of an AS ABAP.
A scalar function implementation reference that binds the scalar function to the SQL environment and to an AMDP function implementation . The scalar function implementation reference is defined in a form-based editor in the ABAP Development Tools. It must refer to an existing CDS scalar function. It is a standalone repository object that is transported and has its own editor in ADT.
An AMDP function that implements the CDS scalar function using SQLScript in a special AMDP method. The implementation is managed as an AMDP scalar function by the AMDP in the database system. The AMDP method must be declared as a special AMDP function implementation for exactly one CDS scalar function using the addition FOR SCALAR FUNCTION . The parameter interface of the AMDP scalar function is defined by the input parameters and the scalar result type of the CDS scalar function.
Client handling has not yet been implemented for CDS scalar functions, so only client-independent scalar functions are supported. The AMDP method that implements a scalar function can only access client-independent objects. However, when it is used, client dependency is ignored. A CDS scalar function can be used in both client-dependent and client-independent CDS entities.
The following topics describe the syntax for defining SQL-based scalar functions.