Ansicht
Dokumentation

ABENBDL_FUNCTION_ABEXA - BDL FUNCTION ABEXA

ABENBDL_FUNCTION_ABEXA - BDL FUNCTION ABEXA

rdisp/max_wprun_time - Maximum work process run time   ABAP Short Reference  
This documentation is copyright by SAP AG.
SAP E-Book

- function

This example demonstrates how a function is defined, implemented, and consumed in a managed RAP BO.

Data model

The CDS data model consists of the root entity DEMO_CDS_FUNCTION_1, which represents a purchase order.

Root entity:

Behavior definition

The CDS behavior definition DEMO_CDS_FUNCTION_1 is defined in CDS BDL as follows:

Function definition

Three functions are defined:

  • getDetails: 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: 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: function with an input parameter for a discount percentage. It subtracts the discount in percent from the initial price of an entity instance and returns the reduced price in its result structure.

All three functions merely deliver information in their result structure. No modify operation is carried out and no data is changed on the database.

Behavior implementation

For the above CDS behavior definition, one ABAP behavior pool (ABP) is created. It can be accessed under BP_DEMO_CDS_FUNCTION_1========CCIMP.

Source Code

Execute

Description

Access with ABAP using EML

The above source code uses EML to access the RAP business object from an ABAP program and executes all three functions:

  • First, the persistent database table demo_purch_doc is filled with values in the method fill_table using ABAP SQL. This way, BO instances already exist and don't have to be created using EML.
  • The function getDetails is executed for two entity instances. These entity instances are determined via the values of their key fields. The function reads the values of the fields PurchaseDocument, Price, and Status for the specified entity instances and returns them in its result structure. The values from the result structure are appended to the internal structure instance_function and a screen output is generated.
  • The function calculateTotal is a static function and thus applies to the complete BO, not to any specific entity instance. The function first filters all entity instances that have the status 'O' (in this example, all entity instances have the status 'O). Then, it sums up the values of the field Price of all entity instances with status 'O'. The values from the result structure are appended to the internal structure static_function and a screen output is generated.
  • The function calculateDiscount is an instance function with an input parameter. To execute the function, it is required to specify an entity instance and also a value for the input parameter. In this example, the input parameter represents a discount percentage and the function subtracts the discount from the value of the field Price of an entity instance. It returns the reduced price in its result structure. The values from the result structure are appended to the internal structure function_input_param and a screen output is generated.





RFUMSV00 - Advance Return for Tax on Sales/Purchases   SUBST_MERGE_LIST - merge external lists to one complete list with #if... logic for R3up  
This documentation is copyright by SAP AG.

Length: 5620 Date: 20240426 Time: 133659     sap01-206 ( 91 ms )