SAP BDL DETERMINATION ABEXA



Get Example source ABAP code based on a different SAP table
  



ABAP_RAP - Determination
This example demonstrates how determinations are defined, implemented, and consumed in a managed RAP BO.
Data model
The CDS data model consists of the root entity DEMO_SALES_CDS_SO_2 and its child entity DEMO_SALES_CDS_SO_I_2. The root entity represents a sales order and the child entity represents a sales order item.
Root entity:
DDLS DEMO_SALES_CDS_SO_2
Child entity:
DDLS DEMO_SALES_CDS_SO_I_2
Behavior definition
The RAP behavior definition DEMO_SALES_CDS_SO_2 is defined in RAP BDL as follows:
BDEF DEMO_SALES_CDS_SO_2
Definition of determinations
The following determinations are defined in the root entity:
setID is a determination on save that is triggered whenever a new instance of the root entity is created. It assigns values to the semantic key field SalesOrderId during the save sequence. The technical key field SoKey is populated by means of internal numbering using the statement numbering:managed.
setStatustoNew sets the status of a newly created sales order to O for open . It is triggered whenever a new sales order is created.
TotalPrice sums up the price of all items of a sales order. It is triggered whenever a new sales order is created.
The child entity defines one determination on modify:
TotalPrice_1 is the counterpart to TotalPrice. If a sales order is created without any items, then this determination ensures that the overall price of a sales order is calculated as soon as sales order items are added.
Behavior implementation
For the above RAP behavior definition, one ABAP behavior pool (ABP) is created. The global class of the behavior pool is BP_DEMO_SALES_CDS_SO_2. The actual implementation takes place in the BP_DEMO_SALES_CDS_SO_2========CCIMP and it works as follows:
setID generates a random value of type i for the field SalesOrderId of each BO instance.
setStatustoNew inserts the value O for Open into column Status for each newly created BO instance.
TotalPrice reads the fields GrossAmount and Quantity from the child entity via a read-by-association operation. It first calculates the total price per item and then sums up the prices of all items for each sales order to get the overall price.
TotalPrice_1 works exactly like TotalPrice, but it has different trigger conditions.

ABAP_SOURCE_CODE
DEMO CL_DEMO_CDS_DETERMINATION

ABAP_DESCRIPTION
Access with ABAP using EML
The above source code uses EML to access the RAP business object from an ABAP class:
Two BO instances are created with the statement MODIFY ENTITY . Two child entities are created for each root entity instance so both sales orders have two sales order items.
All three determinations of the root entity are triggered by the creation of new instances and they insert values into the fields ID , LIFECYCLE_STATUS, and AMOUNT_SUM .
The technical key field SO_KEY is filled by means of internal numbering.