Lesson 3 of 5
Behavior implementation: validations, determinations and actions
10 min
Listen to this lesson
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.
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.
- Read: READ ENTITIES OF the BO IN LOCAL MODE for the keys, fields ValidFrom and ValidTo.
- Check: for each agreement where ValidTo is not after ValidFrom, collect the key.
- Fail: append the key to failed-agreement.
- Report: append a message to reported-agreement, marking ValidTo as the field in error.
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.
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.
- InteractionCreate agreementsetInitialStatus (on modify) sets Status = OPEN in the buffer
- InteractionAdd itemsItems enter the buffer through the composition
- Save sequenceDeterminations on savecalcTotalDeposit recalculates TotalDeposit
- Save sequenceValidationsvalidateDates, validateCustomer, validateDeposit check the buffer
- Save sequencePersist or rejectAll consistent → written to ZCMC_CORE_AGR and ZCMC_CORE_AGI; any failure → whole buffer rejected
| Test condition | Expected result |
|---|---|
| Create agreement without Status | Status becomes OPEN |
| ValidTo equal to ValidFrom | Save rejected; message on ValidTo |
| Item for CMC-ALT-100 with deposit 0 | Save rejected; message on the item’s deposit |
| Two items with deposits 40.00 and 25.00 USD | TotalDeposit 65.00 USD after save |
| closeAgreement on an open agreement | Status CLOSED; result returned to the UI |
| closeAgreement on a closed agreement | Rejected 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?
- 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. Which two response parameters does a failing validation fill?
2. Why does a BO’s own implementation read with IN LOCAL MODE?
3. Which handler should set Status to OPEN when an agreement is created?
4. What should a determination be safe against?