SAP BDL FUNCTION



Get Example source ABAP code based on a different SAP table
  


• FUNCTION ABAP_BDL_BODY
• EXTERNAL ABAP_BDL_BODY , function

ABAP_RAP - function

ABAP_SYNTAX
$[internal$] $[static$] $[repeatable $] function FunctionName
$[external 'ExternalName'$]
$[InputParameter $]
OutputParameter

What does it do?
A RAP function is a user-implemented operation that returns information without any side effects. A function can perform calculations or read operations on business objects without issuing locks or modifying data. An implementation in the RAP handler method FOR READ in the ABAP behavior pool is required.
If you try to modify data in the function implementation in the ABAP behavior pool, there is no error message, but a runtime error occurs when a RAP BO consumer tries to access the function in question.
Optional additions:
static: a function per default relates to a RAP BO entity instance and changes the state of the instance. Static functions are not bound to any instance of a RAP BO entity but relate to the complete entity.
repeatable: per default, a function must not be executed multiple times on the same RAP BO entity instance within the same ABAP EML or OData request. Any attempt to do so leads to a contract check violation if the respective contract checks are switched on. The optional addition repeatable enables multiple executions of the same function on the same RAP BO entity instance within the same ABAP EML or OData request. For further details, see topic TITLE .
external: can be used to provide an alias name for the function for external usage. This external name is exposed in the OData metadata, but it is not known by ABAP. It can be much longer than the actual action name.
The following RAP BDL operation additions are possible:
internal: an internal function is accessible only from within the business object implementation.
An input parameter InputParameter can optionally be added to the function signature.
An output parameter OutputParameter is mandatory.

ABAP_AVAILABILITY
Managed RAP BOs
Unmanaged RAP BOs
In a projection BO, functions from the base BDEF can be reused. For details on reuse, see topic TITLE . It is also possible to specify new functions as described in topic RAP BDL - actions and functions, projection BDEF.
ABAP_AVAILABILITY_END

ABAP_FURTHER_INFO
Development guide for the ABAP RESTful Application Programming Model, section about Functions.

ABAP_EXAMPLE_VX5
The following example shows a managed BDEF based on the CDS root view entity DEMO_CDS_FUNCTION_1. The business object represents a purchase order. Three functions are defined:
getDetails is an instance function that reads the values of the fields PurchaseDocument, Price, and Status for the specified entity instances and returns them in the result structure.
calculateTotal is a static function that sums up the prices of all entity instances with status 'O' and returns the total in its result structure. ABAP_NOTE This function uses a DDIC data element as output parameter. Note that the recommended procedure is to use only CDS abstract entities as BDEF parameters.
calculateDiscount has an input parameter for the discount percentage. It subtracts the discount from the initial price and returns a reduced price in its result structure.
BDEF DEMO_CDS_FUNCTION_1
The class CL_DEMO_CDS_FUNCTION accesses the business object using EML, executes all three functions, and displays the content of their result structures. No modify operations are carried out, the functions merely deliver information in their result structure without changing database entries.
IMAGE ABDOC_FUNCTION.png 598 365
ABAP_EXAMPLE_END

ABAP_EXAMPLE_ABEXA
The example above is explained in detail in the executable example RAP BDL - function.
ABAP_EXAMPLE_END