Now accepting guest editorial from SAP, Oracle, Workday and ServiceNow practitioners.Pitch a guide
The Sign-Off Table

Lesson 3 of 5

Behavior implementation: validations, determinations and actions

10 min

Listen to this lesson

0:00 / 6:51

When you activate a BDEF that declares validations, determinations or actions, ADT can create the behavior pool for you with empty handler methods. The pool is a global class whose real content lives in its Local Types: local handler classes (SAP's naming guide uses the prefix LHC_) for operations and behavior, and, where needed, a local saver class (LSC_) for the save sequence. Each method's signature tells you what kind of handler it is.

ZBP_R_CMC_COREAGREEMENTGlobal behavior pool class; Local Types hold the handlers
lhc_agreementFOR VALIDATE ON SAVE validateDates, validateCustomer; FOR DETERMINE ON MODIFY setInitialStatus; FOR MODIFY closeAgreement; FOR INSTANCE AUTHORIZATION
lhc_itemFOR VALIDATE ON SAVE validateDeposit; FOR DETERMINE ON SAVE calcTotalDeposit
Local test classesABAP Unit tests for each handler, in the same pool
Structure of Contoso’s behavior pool.
The Sign-Off Table · thesignofftable.com/academy/sap-abp-202

Validations

A validation method receives the keys of the instances to check. The usual pattern: read the instances with EML READ ENTITIES OF ... IN LOCAL MODE, check each one, and for each failure add an entry to failed (so the framework knows the instance is inconsistent) and to reported (a message for the user, ideally bound to the field). IN LOCAL MODE is used inside the BO's own implementation and skips feature and authorization control, which apply to external consumers.

  1. Read: READ ENTITIES OF the BO IN LOCAL MODE for the keys, fields ValidFrom and ValidTo.
  2. Check: for each agreement where ValidTo is not after ValidFrom, collect the key.
  3. Fail: append the key to failed-agreement.
  4. Report: append a message to reported-agreement, marking ValidTo as the field in error.
A validation reads the instances in local mode and, for each bad one, returns both a failed key and a reported message bound to the field.
The Sign-Off Table · thesignofftable.com/academy/sap-abp-202

Contoso's validateCustomer checks that the customer exists by reading the released customer view rather than a table, which keeps the code inside ABAP Cloud rules. Its validateDeposit on the item rejects a deposit of zero or less for any product that has a core.

Determinations

A determination method also receives keys, reads what it needs and changes data with EML MODIFY ENTITIES ... IN LOCAL MODE. setInitialStatus runs on modify when an agreement is created and sets Status to OPEN if it is empty. calcTotalDeposit runs on save and recalculates the agreement's total from its items. Write determinations so they can run more than once without harm, because trigger conditions can fire repeatedly in one transaction.

A safe determination recalculates from the source data every time, so running it twice gives the same result instead of doubling the total.
The Sign-Off Table · thesignofftable.com/academy/sap-abp-202

Actions

An action method receives the keys of the instances it is called on and, where declared, parameters. closeAgreement sets Status to CLOSED and returns the changed instance as its result, so the UI refreshes. Business rules about when an action is allowed, such as only open agreements can be closed, belong in feature control, covered in the advanced RAP course; for now the action itself rejects a closed agreement with a message.

  1. InteractionCreate agreementsetInitialStatus (on modify) sets Status = OPEN in the buffer
  2. InteractionAdd itemsItems enter the buffer through the composition
  3. Save sequenceDeterminations on savecalcTotalDeposit recalculates TotalDeposit
  4. Save sequenceValidationsvalidateDates, validateCustomer, validateDeposit check the buffer
  5. Save sequencePersist or rejectAll consistent → written to ZCMC_CORE_AGR and ZCMC_CORE_AGI; any failure → whole buffer rejected
When each of Contoso’s handlers runs during one save.
The Sign-Off Table · thesignofftable.com/academy/sap-abp-202
Test conditionExpected result
Create agreement without StatusStatus becomes OPEN
ValidTo equal to ValidFromSave rejected; message on ValidTo
Item for CMC-ALT-100 with deposit 0Save rejected; message on the item’s deposit
Two items with deposits 40.00 and 25.00 USDTotalDeposit 65.00 USD after save
closeAgreement on an open agreementStatus CLOSED; result returned to the UI
closeAgreement on a closed agreementRejected with a message

Test conditions derived from the behavior implementation (values illustrative).

What would you do?

In CMQ, Maria creates an agreement for Great Lakes Fleet Services with ValidTo before ValidFrom. The save fails, but the message only says "Agreement could not be saved". What should Priya's team log, and against whom?

Key points
  • The behavior pool holds local handler classes (LHC_) and, if needed, a saver class (LSC_).
  • Validations read with EML IN LOCAL MODE and fill failed and reported.
  • Determinations change data with MODIFY ENTITIES IN LOCAL MODE; make them safe to rerun.
  • Actions implement requested operations and can return a result.
  • Clear, field-bound messages are part of correct behavior.

Check your understanding · not graded

Lesson check

  1. 1. Which two response parameters does a failing validation fill?

  2. 2. Why does a BO’s own implementation read with IN LOCAL MODE?

  3. 3. Which handler should set Status to OPEN when an agreement is created?

  4. 4. What should a determination be safe against?