Ansicht
Dokumentation

ABENBDL_FUNCTION - BDL FUNCTION

ABENBDL_FUNCTION - BDL FUNCTION

Addresses (Business Address Services)   PERFORM Short Reference  
This documentation is copyright by SAP AG.
SAP E-Book

- function

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


Effect

A RAP function is a self-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's 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.
  • 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 CDS 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.

Availability

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

Example

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.
This function uses a DDIC data element as output parameter. Please 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.

The program 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@@

The example above is explained in detail in the executable example CDS BDL - function.






BAL Application Log Documentation   rdisp/max_wprun_time - Maximum work process run time  
This documentation is copyright by SAP AG.

Length: 6870 Date: 20240424 Time: 202201     sap01-206 ( 70 ms )