SAP CDS SCALAR FUNCTIONS



Get Example source ABAP code based on a different SAP table
  


VERSION 5 IN

ABAP_CDS - Scalar Functions
A CDS scalar function is defined in the FDL source code of a CDS function definition in the ABAP Development Tools using the statement DEFINE SCALAR FUNCTION. A CDS scalar function is a user-defined CDS function that returns a scalar (that means elementary) return value.
A distinction is drawn between analytical scalar functions and SQL-based scalar functions.
Analytical scalar functions
Evaluated by an analytical runtime environment, such as the ABAP Analytical Engine.
The scalar function implementation reference has the suffix _ANA.
Can be used in CDS analytical projection views like built-in functions in operand positions that expect scalar values.
Analytical scalar functions can only be defined internally at SAP. They are available for internal and external use in CDS analytical queries.
For a list of analytical scalar functions delivered by SAP, see TITLE .
SQL-based scalar functions
Evaluated by an SQL environment.
The scalar function implementation reference has the suffix _SQL.
Can be used in CDS view entities in operand positions that expect scalar values, similar to built-in functions.
An SQL-based scalar function consists of three development objects:
- A scalar function definition defined using DEFINE SCALAR FUNCTION in a CDS function definition .
- 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.
- An AMDP function implementation where it is implemented using SQLScript in a special AMDP method.
CDS scalar functions can be released as stable APIs under the C1 release contract for system internal use .

ABAP_FURTHER_INFO
Development Guide Developing and Consuming ABAP Data Models, section Scalar Functions.



Latest notes:

When creating a CDS scalar function, first the CDS scalar function definition must be activated, then the scalar function implementation reference must be activated, and finally the associated AMDP function implementation is created.
When a CDS scalar function is transported, first the CDS scalar function definition is transported at the same time as the dictionary transport objects, and then the AMDP function implementation is transported as part of the ABAP transport objects. Depending on the size of the transport, there may be a significant delay between these two phases during which the CDS scalar function is not in a usable state.
CDS table functions and CDS scalar functions are both implemented in an AMDP method as an AMDP function implementation. The differences between CDS table functions and CDS scalar functions are as follows:
CDS scalar functions return an elementary value, while CDS table functions return a tabular result type.
Different use cases:
- CDS table functions are used as a data sources in other CDS entities or in AB_SQL read statements.
- CDS scalar functions can be used in the same way as built-in functions, i.e. in operand positions that expect scalar values. Before the introduction of CDS scalar functions, users could define AMDP scalar functions, but they were not available in CDS entities. CDS scalar functions make scalar functions defined in AMDP known to ABAP Dictionary and available in ABAP CDS.
NON_V5_HINTS
ABAP_HINT_END
BEGIN_SECTION SAP_INTERNAL_HINT
The TADIR key for a CDS scalar function is <(>R3TR DSFD<)>. DSFD is an abbreviation for CDS Scalar Function Definition.
The TADIR key for a CDS scalar function implementation reference is <(>R3TR DSFI<)>. DSFI is an abbreviation for CDS Scalar Function Implementation.
END_SECTION SAP_INTERNAL_HINT