ERPClimb logoERPClimb
Behavior Definitions
RAP / CDS / ODataintermediate 10 min read

Behavior Definitions Part 3: Actions, Functions, Determinations and Validations

Preview · a free account unlocks the full lesson

Key takeaway

Declare business logic in the BDEF correctly: instance, static, factory and internal actions, actions with parameters, functions, determinations with the right triggers, validations, determine actions and side effects.

In this lessonShow sections

Visual overview

Behavior Definitions Part 3: Actions, Functions, Determinations and Validations — learning sheetIn one line: Declare business logic in the BDEF correctly: instance, static, factory and internal actions, actions with parameters, functions, determinations with the right triggers, validations, determine actions and side effects.ERPClimb.com / RAP / LESSON 3/5 / LEARNING SHEETBehavior Definitions Part 3: Actions, Functions,Determinations and Validations1 · IN ONE LINEDeclare business logic in the BDEF correctly: instance, static, factory and internalactions, actions with parameters, functions, determinations with the right triggers,validations, determine actions and side effects.2 · KEY IDEAS EXPLAINEDActions — Explicit Business StepsInstance action: "action approve result [1]$self;" — works on selected instances,returns them.Static action: "static actioncreateFromTemplate result [1] $self;" — noinstance needed.Functions — Read-Only Operations"function getApprovalPath result [0..*]ZD_ApprovalStep;" — returns calculated datawithout changing anything. Use a function when a…Determinations — Automatic DerivationsTrigger operations: create; update; delete;(delete only for determinations on modify of childentities).Trigger fields: field Quantity, Price;Validations — Checks That Block SaveSyntax: validation Name on save { create; fieldDescription; }3 · DO · AVOIDBest practice!Common mistakeClassify behavior: action, function,determination, validation, determine action…Keep determination and validation triggersspecific to the fields that matter.Use internal actions for reusable logic calledfrom other handlers.✕Implementing derivations as actions so theydepend on someone clicking.✕Using an action for a pure read (use afunction).✕Validations declared without trigger fields,so they run for every change or never.4 · IN A REAL PROJECTA team exposed a technical action "forceRecalculate" on the UI because users sometimes saw outdatedtotals after changing item quantities. The root cause was not missing logic: the total determination alreadyran on modify, but Fiori did not know that TotalAmount had changed, so it did not reload it. Replacing the…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

Part 2 covered operations and fields; this part covers the declarations that carry business logic, each of which becomes a method in the behavior pool, as shown in the Behavior Implementations series.

Actions represent explicit business steps. An instance action, written as "action approve result [1] $self;", works on selected instances and returns them. A static action, "static action createFromTemplate result [1] $self;", needs no instance.

A factory action, "factory action copyRequest [1];", creates new instances — for example a copy — and returns them via MAPPED, and a static factory action combines both with "static factory action createDefault [1];". An internal action, "internal action recalcTotal;", is only callable inside the BO.

Actions can take a parameter, as in "action reject parameter ZD_RejectReason result [1] $self;", where the parameter is an abstract CDS entity such as "define abstract entity ZD_RejectReason { Reason : abap.char(100); }", which Fiori renders as a dialog.

The result can be [1] $self for the same entity, [0..*] or [1] of another entity, or no result at all, and options like ( features : instance ), ( authorization : update ) and ( precheck ) refine the declaration further.

Functions are read-only operations. "function getApprovalPath result [0..*] ZD_ApprovalStep;" returns calculated data without changing anything, and is the right choice when a consumer needs computed information that shouldn't be a CDS field — for instance because it's expensive to calculate or depends on buffer state.

Free account

Create a free account to keep reading

You have read the opening of this lesson. A free ERPClimb account unlocks the rest of it, every other lesson and topic, and your learning history, so you can pick up exactly where you stopped. No card needed.

  • Full explanation
  • Code example
  • Real project scenario
  • Common mistakes
  • Best practices
  • Interview angle

One tap with Google works too. Every topic keeps its first lesson open to everyone.

Keep exploring

Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.