Beyond ABAPdesigned by@Tejoram97
Beyond ABAP / RAP / Behaviour Definition & Behaviour Pool

Behaviour Definition & Behaviour Pool

RAP · ABAP Development ·

Open the interactive lesson →
  1. Why a behavior definition, and which requirements it carries
  2. The BDEF header and the entity header
  3. The entity body: operations, field characteristics, mapping
  4. The full annotated BDEF of the Sales Order
  5. Projection BDEF: the processor app and the approver app (R11)
  6. Augment and the interface BDEF
  7. The behavior pool ZBP_R_SalesOrder
  8. Method signatures, response parameters and several pools
  9. Interview questions

This page writes the rule book of the Sales Order business object: the behavior definition (BDEF) ZR_SalesOrder with every line tied to a requirement (R1, R4, R5, R6, R7, R8), the projection BDEFs for the processor and the approver app (R11) including augment and the released interface BDEF, and the behavior pool ZBP_R_SalesOrder with its handler and saver classes and the method signature for each BDEF element.

Part 1 – Why a behavior definition, and which requirements it carries

R-ID

Requirement

Where on this page

R1

Reps create an order with several items, edit and delete it

Part 3 (operations, create by association), Part 4 (full BDEF)

R4

A new order starts with status N

Part 4: determination setInitialStatus (logic → page 05)

R5

Net amount = sum of item net values, refreshed at once

Part 4: calculateTotal, recalcTotal, side effects (logic → 05, UI refresh → 07)

R6

Customer valid, quantity > 0, bad input rejected early

Part 4: validations, precheck, checkOrder (logic → 05)

R7

Manager approves or rejects

Part 4: approve, reject with instance features (rules → 06)

R8

Copy an existing order

Part 4: factory action copyOrder (logic → 05)

R11

Approver uses a separate, simpler app

Part 5 (approver projection BDEF), Part 6 (augment)

The CDS views (→ see 02 · Data Model & CDS) describe what the data looks like. The behavior definition (BDEF, written in BDL, the Behavior Definition Language) describes what you may do with it: create, change, delete, approve, copy, which fields are locked, what is calculated automatically and what is checked before saving. It is the rule book of the business object. The behavior pool (Part 7) is the ABAP class where the rules that need code are implemented.

Every requirement of the Sales Order Approval app that is about behavior becomes one or two BDEF lines. The picture shows the mapping that this page builds up step by step:

Requirements R1, R4, R5, R6, R7, R8 and R11 each mapped to their BDEF line (operations, determinations, validations, precheck, actions, factory action, approver projection) and to the handler method or framework that implements them
BDEF anatomy: header once per BO (managed, class, strict, draft), entity header once per entity (tables, lock, authorization, ETag) and entity body (operations, fields, actions, determinations, validations, draft actions, side effects, mapping)
  • ADT: right-click the root view entity ZR_SalesOrder → New Behavior Definition, implementation type *Managed*. The BDEF gets the same name as the root entity and covers the whole composition tree.
  • One define behavior for block per entity: here ZR_SalesOrder (alias SalesOrder) and ZR_SalesOrderItem (alias Item). The alias is the short name you use in EML and in handler signatures (FOR SalesOrder~approve).

Part 2 – The BDEF header and the entity header

2.1 The header: implementation type, behavior pool, strict mode, draft

managed implementation in class zbp_r_salesorder unique;   " who does CRUD + where the code lives
strict ( 2 );                                               " strict checks (always for new BOs)
with draft;                                                 " draft-enabled BO (R10, page 07)

Header line

Meaning

managed

The framework implements create, update, delete, read, lock and the save. You add only business logic (implementation types → see 01 · RAP Foundations).

unmanaged

You implement every operation yourself, usually around existing code (→ see 09 · Unmanaged Scenario & Save Variants).

implementation in class zbp_r_salesorder unique

The behavior pool. unique = each behavior is implemented in exactly one class. It can also be given per entity (Part 8).

strict ( 2 )

Strict mode, version 2: additional syntax checks that forbid outdated syntax and demand explicit declarations (for example authorization for every entity and the draft actions). The exact rule list is in the keyword documentation of your release.

with draft

Draft-enabled: every entity needs a draft table, the root a total etag, and the draft actions are listed in the body (→ see 07 · Locking, Draft & Side Effects).

with additional save / with unmanaged save

Managed BO with own save code (R14, R13 → page 09).

2.2 The entity header: tables, locks, authorization, ETag

define behavior for ZR_SalesOrder alias SalesOrder
persistent table zsales_hdr                       " active data
draft table zsales_hdr_d                          " draft data (quick fix creates it)
etag master LocalLastChangedAt                    " optimistic check per instance
lock master total etag LastChangedAt              " root locks the whole order; total ETag for draft
authorization master ( global, instance )         " root checks authorization (R3, R7 → page 06)
  • Master vs dependent: the root is lock master and authorization master; the item says lock dependent by _SalesOrder and authorization dependent by _SalesOrder – locking or checking an item goes through its order. That matches R1: an item never lives on its own.
  • Which field for which ETag: etag master LocalLastChangedAt changes with every change of this instance; total etag LastChangedAt changes only when the active order is saved. How locks and ETags work (R10) → see 07 · Locking, Draft & Side Effects.
  • Common mistake: a draft BDEF without total etag on the root – the syntax check rejects it.

Part 3 – The entity body: operations, field characteristics, mapping

3.1 Operations and create by association (R1)

{
create;                                         " R1: the root may be created directly
update ( features : instance );                 " dynamic: get_instance_features decides per order
delete ( features : instance );
association _Item { create ( features : instance ); with draft; }   " R1: items through the order
}
  • association _Item { create; } = create by association: the Fiori Create button above the Items table, EML CREATE BY \_Item. The item entity itself has no create; – an item cannot exist without its order.
  • with draft; inside the association is required in a draft BO, so draft items stay linked to the draft order. The child repeats it: association _SalesOrder { with draft; }.
  • ( features : instance ) only declares that code decides per order whether Edit, Delete or Create item is allowed (e.g. not for approved orders). The method get_instance_features → see 06 · Feature Control, Authorization & Numbering.
  • Newer releases add non-standard association operations (link, unlink, BTP 2502) and editable hierarchies – check your release before using them.

3.2 Field characteristics – static field control

Field characteristics are rules that are the same for every instance. They make the UI show a field as read-only or required and protect the field from changes by consumers.

Matrix of field characteristics: editable, readonly, mandatory, mandatory:create with readonly:update, readonly:update, numbering:managed and features:instance, with the behavior on create and update and a Sales Order field for each
field ( numbering : managed, readonly ) OrderUUID;               " UUID drawn by the framework
field ( readonly ) SalesOrderID, Status, NetAmount, CreatedBy, CreatedAt,
LocalLastChangedBy, LocalLastChangedAt, LastChangedAt;
field ( mandatory ) CustomerID, Currency;                        " asterisk in the UI
field ( mandatory : create, readonly : update ) ItemNo;          " Item: typed once, then frozen
  • readonly stops consumers (UI, EML from outside the BO). Your own code still changes the field with EML IN LOCAL MODE – that is how the determinations set Status (R4) and NetAmount (R5).
  • Common mistake: relying on mandatory alone. It marks the field in the UI, but the RAP runtime does not check it – an empty CustomerID still reaches the save. That is why R6 needs the validation validateCustomer. mandatory : create is different: a CREATE without the field is rejected at runtime.
  • Admin fields (CreatedBy, LocalLastChangedAt, ...) are filled by the managed framework because of their @Semantics annotations in the CDS view; mark them readonly.
  • Rules that depend on the data of one order (CustomerID read-only once approved) are dynamic field control: field ( features : instance ) → page 06.

3.3 Mapping

mapping for zsales_hdr corresponding              " same names map automatically
{
OrderUUID    = order_uuid;                      " list the names that differ
SalesOrderID = sales_order_id;
...
}
  • Mapping connects CDS element names (CamelCase) with table field names (snake_case). The managed framework needs it to read and write the persistent and draft tables.
  • corresponding maps elements with the same name automatically (check your release). In the Sales Order BO every CDS name differs from its column, so the full BDEF in Part 4 lists all fields.

Part 4 – The full annotated BDEF of the Sales Order

This is the complete base BDEF ZR_SalesOrder that the following pages implement. The comments name the requirement each line serves and the page where its code or rules are explained.

managed implementation in class zbp_r_salesorder unique;
strict ( 2 );
with draft;                                                    " R10 → page 07

define behavior for ZR_SalesOrder alias SalesOrder
persistent table zsales_hdr
draft table zsales_hdr_d
etag master LocalLastChangedAt                                 " R10
lock master total etag LastChangedAt                           " R10
authorization master ( global, instance )                      " R3, R7 → page 06
{
create;                                                      " R1
update ( features : instance );                              " R1; no edit after approval → page 06
delete ( features : instance );
association _Item { create ( features : instance ); with draft; }   " R1

field ( numbering : managed, readonly ) OrderUUID;
field ( readonly ) SalesOrderID, Status, NetAmount, CreatedBy, CreatedAt,
LocalLastChangedBy, LocalLastChangedAt, LastChangedAt;
field ( mandatory ) CustomerID, Currency;

action ( features : instance ) approve result [1] $self;     " R7 → logic 05, rules 06
action ( features : instance ) reject  result [1] $self;     " R7
factory action copyOrder [1];                                " R8
internal action recalcTotal;                                 " R5: only for the BO's own code

determination setInitialStatus on modify { create; }         " R4
determination setSalesOrderId  on save   { create; }         " R9: order number → page 06
validation validateCustomer on save { create; field CustomerID; }   " R6

determine action checkOrder                                  " R6: checks on demand
{
validation validateCustomer;
validation Item~validateQuantity;
}

side effects                                                 " R6 → page 07
{
determine action checkOrder executed on field CustomerID affects messages;
}

draft action ( features : instance ) Edit;                   " R10 → page 07
draft action Activate optimized;
draft action Discard;
draft action Resume;
draft determine action Prepare                               " R6: checks when the user clicks Save
{
validation validateCustomer;
validation Item~validateQuantity;
}

mapping for zsales_hdr
{
OrderUUID          = order_uuid;
SalesOrderID       = sales_order_id;
CustomerID         = customer_id;
SalesOrganization  = sales_org;
OrderDate          = order_date;
Status             = status;
NetAmount          = net_amount;
Currency           = currency;
CreatedBy          = created_by;
CreatedAt          = created_at;
LocalLastChangedBy = local_last_changed_by;
LocalLastChangedAt = local_last_changed_at;
LastChangedAt      = last_changed_at;
}
}

define behavior for ZR_SalesOrderItem alias Item
persistent table zsales_itm
draft table zsales_itm_d
etag master LocalLastChangedAt
lock dependent by _SalesOrder                                  " R1: locked through the order
authorization dependent by _SalesOrder
{
update ( precheck );                                         " R6: reject a negative quantity early
delete;
association _SalesOrder { with draft; }

field ( numbering : managed, readonly ) ItemUUID;
field ( readonly ) ParentUUID;
field ( mandatory : create, readonly : update ) ItemNo;
field ( mandatory ) MaterialID;

determination calculateTotal on modify { create; field Quantity, NetPrice; }   " R5
validation validateQuantity on save { create; field Quantity; }               " R6

side effects                                                 " R5: refresh the header → page 07
{
field Quantity affects field _SalesOrder.NetAmount;
field NetPrice affects field _SalesOrder.NetAmount;
}

mapping for zsales_itm
{
ItemUUID           = item_uuid;
ParentUUID         = parent_uuid;
ItemNo             = item_no;
MaterialID         = material_id;
Quantity           = quantity;
Unit               = unit;
NetPrice           = net_price;
Currency           = currency;
LocalLastChangedAt = local_last_changed_at;
}
}
  • After activating, ADT shows warnings with quick fixes (Ctrl+1): create the draft tables zsales_hdr_d / zsales_itm_d and the behavior pool with all method stubs.
  • Draft actions, Prepare, total etag and both side effects blocks are explained on 07 · Locking, Draft & Side Effects; numbering (setSalesOrderId, R9) on 06. All other lines are implemented on 05 · Business Logic & Messages.
  • internal action recalcTotal – no button and no projection; only the BO's own code calls it (from calculateTotal, page 05). determine action checkOrder needs no handler method: it only runs the listed validations.

4.1 What each line does in the app

Each BDEF line next to its effect in the Fiori app: draft buttons, Create/Edit/Delete, Create on the Items table, read-only and mandatory fields, Approve button enabled or disabled, Copy, automatic status, validation message, side effect refresh

4.2 Keyword reference

Keyword

Meaning

managed / unmanaged

Who implements CRUD + save: framework or you

strict ( 2 )

Strict mode – additional syntax checks (always use it for new BOs)

with draft

Draft-enabled BO; needs draft table per entity and draft actions (page 07)

persistent table / draft table

Where active / draft data is stored (managed only)

lock master / lock dependent by _SalesOrder

Root locks the whole BO; children are locked via the root

etag master <field> / etag dependent by … / total etag <field>

Optimistic concurrency per instance / via the parent / for the whole BO in draft (page 07)

authorization master ( global, instance ) / dependent by

Where authorization is checked (page 06)

create; update; delete;

Standard operations; ( features : instance ) makes them dynamic

association _Item { create; with draft; }

Create by association; navigation in draft

field ( readonly | mandatory | readonly : update | mandatory : create )

Static field control

field ( numbering : managed )

Framework assigns a UUID key (other numbering: page 06)

field ( features : instance ), action ( features : instance )

Dynamic feature control per instance (page 06)

determination … on modify | on save { create; update; delete; field X; }

Sets values automatically when the trigger fires (page 05)

validation … on save { create; update; field X; }

Checks before save; FAILED rejects the save (page 05)

action / factory action / static action / internal action

Custom operation / creates new instances (copy) / not bound to an instance / callable only inside the BO (page 05)

action … parameter ZD_… result [1] $self

Input via an abstract entity; result = changed instance

function … result [1] …

Read-only operation returning data (page 05)

determine action X { validation …; determination …; }

Runs listed on-save logic on demand (page 05)

( precheck ) on create, update, delete, actions

Reject a request before it reaches the buffer (page 05)

draft action Edit | Activate optimized | Discard | Resume; draft determine action Prepare

Draft actions (page 07)

early numbering / late numbering

Own key assignment (page 06)

with additional save / with unmanaged save

Own save logic in a managed BO (page 09)

side effects { … }

Tell the UI what to reload (page 07)

mapping for <table> [corresponding]

Maps CDS element names to table field names

event … [parameter …]

Business event raised in the save (page 10)

  • Common mistake: adding a determination or action to the BDEF and activating without creating the method – the behavior pool no longer compiles. Use Ctrl+1 on the warning to generate the stub.

Part 5 – Projection BDEF: the processor app and the approver app (R11)

The base BDEF holds everything the BO can do. A Fiori app or an API should see only what it needs. The projection BDEF is the shop window for one service: it contains no logic and only reuses (use) behavior from the base BO. That is how R11 is solved – one BO, two apps with different buttons.

Three BDEF layers: base BDEF ZR_SalesOrder with all logic, optional interface BDEF ZI_SalesOrderTP as stable released API, projection BDEF ZC_SalesOrder per service; table of which elements reach each layer

5.1 The processor projection ZC_SalesOrder

ADT: right-click the projection view ZC_SalesOrder (provider contract transactional_query, → see 03 · Projection, UI, Access Control & Service) → New Behavior Definition; the type *Projection* is proposed.

projection;
strict ( 2 );
use draft;
use side effects;

define behavior for ZC_SalesOrder alias SalesOrder
use etag
{
use create;                                     " R1
use update;
use delete;

use action approve;                             " R7
use action reject;
use action copyOrder;                           " R8
use action checkOrder;                          " R6: needed by the side effect
use action Edit;
use action Activate;
use action Discard;
use action Resume;
use action Prepare;

use association _Item { create; with draft; }
}

define behavior for ZC_SalesOrderItem alias Item
use etag
{
use update;
use delete;

use association _SalesOrder { with draft; }
}

Projection keyword

What it does

projection;

Marks a projection BDEF (no implementation type – the base BO implements everything)

use draft;

The service works with draft; needed when the base BO has with draft

use side effects;

Passes the base BO's side effects to the UI (otherwise the UI never reloads)

use etag

Passes the ETag check through to the OData service (HTTP If-Match)

use create; use update; use delete;

Exposes the standard operations

use action approve;

Exposes an action (also draft, factory and determine actions)

use association _Item { create; with draft; }

Exposes create by association and draft navigation

  • What you leave out does not exist for this service: no use delete → no Delete button and no DELETE request accepted.
  • Logic is never "used" – determinations, validations, feature control, authorization and locks run in the base BO for every request, whichever projection it comes through.
  • Internal actions (recalcTotal) cannot be exposed – they are for the BO's own code only.
  • Common mistake: adding a new action to the base BDEF and forgetting use action in the projection – the button never appears (the #FOR_ACTION UI annotation is the other half → page 03).

5.2 The approver projection ZC_SalesOrderApv

R11 – the manager's app shows the orders and offers only Approve and Reject. The approver projection views ZC_SalesOrderApv / ZC_SalesOrderItemApv, their metadata extension, the service ZUI_SalesOrderApv and the business role are built on page 03; here is the behavior side:

projection;
strict ( 2 );
use draft;

define behavior for ZC_SalesOrderApv alias SalesOrder
use etag
{
use action approve;                             " R7 – no create, update or delete
use action reject;

use association _Item { with draft; }           " items: display only
}

define behavior for ZC_SalesOrderItemApv alias Item
use etag
{
use association _SalesOrder { with draft; }
}
  • Approve and Reject run on the active order. Without use action Edit the manager can never open an edit draft, so all fields stay read-only. Whether the approver service needs draft at all is a design choice – check the processor/approver projections in SAP's flight reference scenario of your release.
  • Both apps run the same approve method, feature control and authorization: "only status N" and "only managers" (R7) are enforced in the base BO (page 06), so they also hold for EML callers (R12) and the Web API. The projection only hides buttons.

Part 6 – Augment and the interface BDEF

6.1 Projection-specific logic: augment

Sometimes one app needs a little extra behavior that does not belong in the base BO, for example a default that only the processor app proposes. A projection can then get its own behavior pool:

projection implementation in class zbp_c_salesorder unique;
strict ( 2 );
use draft;
use side effects;

define behavior for ZC_SalesOrder alias SalesOrder
use etag
{
use create ( augment );                         " enrich the incoming create request
use update;
...
}
CLASS lhc_SalesOrder DEFINITION INHERITING FROM cl_abap_behavior_handler.
PRIVATE SECTION.
METHODS augment_create FOR MODIFY
IMPORTING entities FOR CREATE SalesOrder.
ENDCLASS.
  • Augmentation runs in the projection before the request is handed to the base BO. It adds to the request with MODIFY AUGMENTING ENTITY … [RELATING TO … BY …] (not with a normal MODIFY – the data is not in the buffer yet) and has no response parameters. Read-only fields cannot be set this way. Check the exact statement and the generated stub in your release.
  • A projection can also define its own actions and functions, implemented in the projection behavior pool – check your release.
  • Rule of thumb: if the logic is true for every app (status N, total, checks), it belongs in the base BO; augment only for real app-specific needs.

6.2 The interface BDEF – a stable contract

If other developers (the nightly job of R12, another BO, an extension of R19) call your BO, they should not depend on ZR_SalesOrder directly – you could never again rename a field. The interface layer is a projection that you release (C1 contract, use in cloud development) and keep stable.

@EndUserText.label: 'Sales order – BO interface'
@AccessControl.authorizationCheck: #CHECK
define root view entity ZI_SalesOrderTP
provider contract transactional_interface
as projection on ZR_SalesOrder
{
key OrderUUID,
SalesOrderID,
CustomerID,
OrderDate,
Status,
NetAmount,
Currency,
LocalLastChangedAt,
LastChangedAt,
_Item : redirected to composition child ZI_SalesOrderItemTP
}
interface;
strict ( 2 );
use draft;

define behavior for ZI_SalesOrderTP alias SalesOrder
use etag
{
use create;
use update;
use delete;

use action approve;
use action reject;
use action copyOrder;
use action Edit;
use action Activate;
use action Discard;
use action Resume;
use action Prepare;

use association _Item { create; with draft; }
}

define behavior for ZI_SalesOrderItemTP alias Item
use etag
{
use update;
use delete;

use association _SalesOrder { with draft; }
}
  • Consumers then call MODIFY ENTITIES OF zi_salesordertp … (→ see 08 · EML), and a UI projection may be built on the interface instead of the base: define root view entity ZC_SalesOrder provider contract transactional_query as projection on ZI_SalesOrderTP (check your release).
  • Why SAP releases BOs this way: SAP's own BOs follow exactly this pattern. I_SalesOrderTP is the released interface; the R_ view and the base BDEF behind it are internal and may change with any release. Your code uses only the released I_…TP object (R18 → page 11; clean core → page 13).

Base BDEF

Interface BDEF

Projection BDEF

First line

managed … / unmanaged …

interface;

projection;

CDS provider contract

– (R_ view)

transactional_interface

transactional_query

Contains logic

Yes – all of it

No

No (except augment / own actions)

Used by

Only the layers above

Other BOs, EML consumers, extensions, projections

One OData service (UI or Web API)

Stable?

Internal, may change

Yes – released (C1)

Belongs to its app

Part 7 – The behavior pool ZBP_R_SalesOrder

The BDEF lists the rules; the behavior pool is the ABAP class where the rules that need code live. It is a special global class with local classes inside – like a building (the global class) with one office per entity (handler classes) and one back office that files everything at the end (the saver class).

Numbered BDEF lines next to the generated handler methods in lhc_SalesOrder, lhc_Item and lsc_ZR_SalesOrder; managed CRUD and draft actions need no method

7.1 The global class

CLASS zbp_r_salesorder DEFINITION PUBLIC ABSTRACT FINAL FOR BEHAVIOR OF zr_salesorder.
ENDCLASS.

CLASS zbp_r_salesorder IMPLEMENTATION.
ENDCLASS.
  • FOR BEHAVIOR OF zr_salesorder links the class to the BDEF. ABSTRACT FINAL – nobody instantiates or inherits from it; the RAP runtime calls the local classes directly.
  • The global class is usually empty. All code goes into the Local Types tab (CCIMP include).
  • ADT generates everything: cursor on the class name in the BDEF header → Ctrl+1 → *Create behavior implementation*. After adding a new action later, Ctrl+1 on the warning adds the missing method.

7.2 Handler classes and the saver class

Handler class lhc_<entity>

Saver class lsc_<bo>

Inherits from

cl_abap_behavior_handler

cl_abap_behavior_saver

Here

lhc_SalesOrder, lhc_Item

lsc_ZR_SalesOrder

Runs in

Interaction phase – on every request

Save sequence – once per COMMIT ENTITIES

Works on

The transactional buffer (via EML IN LOCAL MODE)

The database (save) and final keys

Methods

One per BDEF element that needs code

finalize, check_before_save, adjust_numbers, save / save_modified, cleanup, cleanup_finalize (REDEFINITION)

Needed in a managed BO?

Yes, as soon as there is any logic

Only for additional / unmanaged save or late numbering (pages 06, 09)

  • Interaction phase, buffer and save sequence → see 01 · RAP Foundations. In a managed BO the framework already runs finalize, check_before_save and save; your on-save determinations and validations are called from there.
  • Never COMMIT WORK, ROLLBACK WORK or direct database writes in a handler – the framework controls the transaction. Strict mode turns many of these into errors.

7.3 The handler class definitions for the Sales Order

CLASS lhc_SalesOrder DEFINITION INHERITING FROM cl_abap_behavior_handler.
PRIVATE SECTION.
CONSTANTS:
BEGIN OF so_status,
new      TYPE zde_so_status VALUE 'N',
approved TYPE zde_so_status VALUE 'A',
rejected TYPE zde_so_status VALUE 'R',
END OF so_status.

METHODS get_global_authorizations FOR GLOBAL AUTHORIZATION          " R3, R7 → page 06
IMPORTING REQUEST requested_authorizations FOR SalesOrder RESULT result.
METHODS get_instance_authorizations FOR INSTANCE AUTHORIZATION
IMPORTING keys REQUEST requested_authorizations FOR SalesOrder RESULT result.
METHODS get_instance_features FOR INSTANCE FEATURES                 " R7 → page 06
IMPORTING keys REQUEST requested_features FOR SalesOrder RESULT result.
METHODS setInitialStatus FOR DETERMINE ON MODIFY                    " R4
IMPORTING keys FOR SalesOrder~setInitialStatus.
METHODS setSalesOrderId FOR DETERMINE ON SAVE                       " R9 → page 06
IMPORTING keys FOR SalesOrder~setSalesOrderId.
METHODS validateCustomer FOR VALIDATE ON SAVE                       " R6
IMPORTING keys FOR SalesOrder~validateCustomer.
METHODS approve FOR MODIFY                                          " R7
IMPORTING keys FOR ACTION SalesOrder~approve RESULT result.
METHODS reject FOR MODIFY
IMPORTING keys FOR ACTION SalesOrder~reject RESULT result.
METHODS copyOrder FOR MODIFY                                        " R8
IMPORTING keys FOR ACTION SalesOrder~copyOrder.
METHODS recalcTotal FOR MODIFY                                      " R5
IMPORTING keys FOR ACTION SalesOrder~recalcTotal.
ENDCLASS.

CLASS lhc_Item DEFINITION INHERITING FROM cl_abap_behavior_handler.
PRIVATE SECTION.
METHODS calculateTotal FOR DETERMINE ON MODIFY                      " R5
IMPORTING keys FOR Item~calculateTotal.
METHODS validateQuantity FOR VALIDATE ON SAVE                       " R6
IMPORTING keys FOR Item~validateQuantity.
METHODS precheck_update FOR PRECHECK                                " R6
IMPORTING entities FOR UPDATE Item.
ENDCLASS.

The implementations follow on 05 · Business Logic & Messages (and authorization and features on 06). Local class names are not case-sensitive; ADT generates them as shown. Method names are free – the FOR … addition is what links a method to its BDEF element.

Part 8 – Method signatures, response parameters and several pools

8.1 Method signatures for each BDEF element

BDEF element

Handler method declaration

determination on modify

METHODS x FOR DETERMINE ON MODIFY IMPORTING keys FOR SalesOrder~x.

determination on save

METHODS x FOR DETERMINE ON SAVE IMPORTING keys FOR SalesOrder~x.

validation

METHODS x FOR VALIDATE ON SAVE IMPORTING keys FOR SalesOrder~x.

action with result

METHODS x FOR MODIFY IMPORTING keys FOR ACTION SalesOrder~x RESULT result.

factory / internal action

METHODS x FOR MODIFY IMPORTING keys FOR ACTION SalesOrder~x. (no RESULT; the factory returns new keys in mapped)

function

METHODS x FOR READ IMPORTING keys FOR FUNCTION SalesOrder~x RESULT result.

features : instance

METHODS get_instance_features FOR INSTANCE FEATURES IMPORTING keys REQUEST requested_features FOR SalesOrder RESULT result.

authorization ( instance )

METHODS get_instance_authorizations FOR INSTANCE AUTHORIZATION IMPORTING keys REQUEST requested_authorizations FOR SalesOrder RESULT result.

authorization ( global )

METHODS get_global_authorizations FOR GLOBAL AUTHORIZATION IMPORTING REQUEST requested_authorizations FOR SalesOrder RESULT result.

precheck on update

METHODS precheck_update FOR PRECHECK IMPORTING entities FOR UPDATE Item.

early numbering

METHODS earlynumbering_create FOR NUMBERING IMPORTING entities FOR CREATE SalesOrder.

augment (projection pool)

METHODS augment_create FOR MODIFY IMPORTING entities FOR CREATE SalesOrder.

  • Determine actions and draft actions need no method in a managed BO. For precheck and augment, compare with the stub that Ctrl+1 generates in your release.

Unmanaged BO only (→ see 09 · Unmanaged Scenario & Save Variants) – the standard operations need methods too:

Operation

Handler method declaration

create

METHODS create FOR MODIFY IMPORTING entities FOR CREATE SalesOrder.

update

METHODS update FOR MODIFY IMPORTING entities FOR UPDATE SalesOrder.

delete

METHODS delete FOR MODIFY IMPORTING keys FOR DELETE SalesOrder.

read

METHODS read FOR READ IMPORTING keys FOR READ SalesOrder RESULT result.

lock

METHODS lock FOR LOCK IMPORTING keys FOR LOCK SalesOrder.

create by association

METHODS cba_Item FOR MODIFY IMPORTING entities_cba FOR CREATE SalesOrder\_Item.

read by association

METHODS rba_Item FOR READ IMPORTING keys_rba FOR READ SalesOrder\_Item FULL result_requested RESULT result LINK association_links.

8.2 Implicit parameters every handler gets

  • Every handler method has implicit response parameters: failed and reported, plus mapped in modify methods that create instances. How to fill them → see 05 · Business Logic & Messages.
  • The importing parameters are tables: one call handles many instances (mass-enabled). Always loop or use FOR … IN keys, never keys[ 1 ].
  • Common mistake: using keys-%key instead of %tky – with draft the same key exists twice (draft and active), and only %tky (key + %is_draft) tells them apart. CORRESPONDING #( keys ) keeps %tky.
  • IN LOCAL MODE – inside the pool, EML skips feature control and authorization checks, because the BO is changing itself (e.g. setting the read-only Status). EML itself → see 08 · EML.

8.3 Several behavior pools and helper classes

define behavior for ZR_SalesOrderItem alias Item
implementation in class zbp_r_salesorderitem unique   " item logic in its own pool
persistent table zsales_itm
...
  • Large BOs split the code: one pool per entity (as above), or the root's pool for everything. Each behavior is still implemented in exactly one class (unique).
  • Newer releases add auxiliary classes (auxiliary class …, BTP 2408) – helper classes that may use IN LOCAL MODE and PRIVILEGED like the pool – and BDEF friends (with friends, BTP 2402), which may call internal operations of another BO. Check your release.

Part 9 – Interview questions

Q1. What is in a behavior definition?

The header (implementation type and behavior pool, strict mode, draft), then per entity the transactional characteristics (persistent and draft table, lock master or dependent, authorization, ETag) and the body: operations, association operations, field control, actions, functions, determinations, validations, draft actions, side effects and the mapping.

Q2. What does strict ( 2 ) do?

Strict mode makes the BDEF syntax check stricter: it forbids outdated syntax and demands explicit declarations such as authorization and the draft actions. Version 2 adds further checks. New BDEFs should always use the latest strict mode; RAP extensibility even requires it.

Q3. Why can an item not be created directly, and what does with draft in the association do?

The item is a composition child: it exists only with its order. So the item has no create; – it is created by association (association _Item { create; } on the root, EML CREATE BY \_Item). In a draft BO, with draft on both association directions keeps draft items linked to the draft order.

Q4. mandatory vs mandatory : create?

mandatory only marks the field in the UI; the runtime does not reject an empty value, so you need a validation. mandatory : create is enforced: a CREATE without the field is rejected. Combined with readonly : update it gives a field that is typed once and then frozen, such as the item number.

Q5. Why release a BO through an interface BDEF?

An interface BDEF (interface; on a view with provider contract transactional_interface) is a stable facade over the BO. Consumers and extensions use the interface, so the implementation underneath can change without breaking them. SAP releases its own BOs this way, e.g. I_SalesOrderTP for EML and extension.

Q6. Approvers must approve, reps may only create and edit. How do you design it?

One base BO with all behavior and two projections with their own projection BDEFs: ZC_SalesOrder with create, update, delete and copy, ZC_SalesOrderApv with only use action approve; use action reject;, each with its own service and app. Security still lives in the base BO: instance feature control allows Approve only for status N and instance authorization checks the manager's authorization, so the rules also hold for EML and Web API callers.

Q7. What is augmentation?

In a projection BDEF an operation can be declared with augment (use create ( augment );). The projection behavior pool then enriches the incoming request with MODIFY AUGMENTING ENTITY before it reaches the base BO, for example to fill a default that only this app knows. It has no response parameters of its own and cannot set read-only fields.

Q8. Handler class vs saver class?

Handler classes (lhc_, inherit from cl_abap_behavior_handler) implement the interaction phase: actions, determinations, validations, prechecks, feature control, authorization (and all operations in an unmanaged BO). The saver class (lsc_, inherits from cl_abap_behavior_saver) implements the save sequence methods finalize, check_before_save, adjust_numbers, save / save_modified and cleanup; a managed BO needs it only for additional or unmanaged save and late numbering.

Q9. Users see "instance not found" only in the draft app. What do you check?

Whether the handlers use %key instead of %tky. In a draft BO the same key exists as draft and active, so READ, MODIFY, FAILED and REPORTED must use %tky (or CORRESPONDING #( keys ), which keeps %is_draft). I would confirm it in the debugger by looking at %is_draft in keys.

Q10. You added an action to the base BDEF but the button does not appear. Why?

Typical causes: the projection BDEF lacks use action, the projection view or metadata extension lacks the @UI.lineItem / @UI.identification entry of type #FOR_ACTION, or instance feature control disables it for that order. If the pool does not compile, the method stub is missing – Ctrl+1 creates it.

🏠 Start Here · ◀ 03 · Projection & Service · 05 · Logic & Messages ▶ · Sections: CORE ABAP | OOPS ABAP | ABAP on HANA | Clean Core | RAP | ABAP Points | SAP Fiori | SAPUI5 | Mobile Development (MDK) | BTP Foundations | BTP Development | CAP | SAP Build | ABAP on BTP | Integration Suite | SAP Business AI | SAP BASIS | Security | SAP SDLC

Functional: FICO ABAP | TRM ABAP | VIM | SAP BIS | SD ABAP | MM ABAP | PP ABAP | QM ABAP | PM ABAP | PS ABAP | EWM | TM ABAP | EHS ABAP | HR ABAP | BW | SAP MDG | SAP Analytics Cloud | SAP Ariba | SAP CX | SAP IBP