ERPClimb logoERPClimb
RAP Basics
Architect / Cross-trackadvanced 10 min read

RAP Basics Part 9: Behavior Implementation — Handler and Saver Classes

Preview · a free account unlocks the full lesson

Key takeaway

Implement RAP business logic in the behavior pool: the ZBP global class, local handler classes (cl abap behavior handler) with FOR VALIDATE, FOR DETERMINE, FOR MODIFY and FOR INSTANCE FEATURES methods, the saver class (cl abap behavior saver), derived types, %tky, failed and reported, and IN LOCAL MODE.

In this lessonShow sections

Visual overview

RAP Basics Part 9: Behavior Implementation — Handler and Saver Classes — learning sheetFlow: Generate the behavior pool from the BDEF → Use quick fix to create all declared methods → Implement validateCustomer: read, check with SELECT on customer, fill failed/reported → Implement setInitialStatus with MODIFY ENTITIES IN LOCAL MODE. Key ideas: THE BEHAVIOR POOL; HANDLER METHOD KINDS; DERIVED TYPES AND %-COMPONENTS; FAILED AND REPORTED. Watch out: Always use IN LOCAL MODE inside the BO — otherwise your own logic is blocked by feature control and authorization meant for consumers.ERPClimb.com / ARCH / LESSON 9/11 / LEARNING SHEETRAP Basics Part 9: Behavior Implementation — Handler andSaver Classes1 · HOW IT FLOWS1Generate thebehavior poolfrom the BDEF2Use quick fix tocreate alldeclared methods3ImplementvalidateCustomerread, check with SELECTon customer, fill…4ImplementsetInitialStatuswith MODIFY…2 · KEY IDEAS EXPLAINEDThe Behavior PoolCreated from the BDEF quick fix; global class hasno code.Local Types: one handler class per entity, onesaver class for the BO.Handler Method KindsFOR VALIDATE ON SAVE: validation; fill failed andreported.FOR DETERMINE ON MODIFY / ON SAVE: determination;MODIFY ENTITIES IN LOCAL MODE.Derived Types And %-ComponentsTABLE FOR READ RESULT zi_travel\travel, TABLE FORUPDATE …%tky: transactional key; %key: key only; %control:which fields are set; %msg: message; %element:field for message highlighting.Failed And Reportedfailed-travel: append %tky → the instance failed.reported-travel: append %tky, %msg (new_message ormessage class), %element-CustomerID =if_abap_behv=>mk-on.3 · REMEMBER · WATCH OUTRememberThe behavior pool is a global class (ZBP_I_TRAVEL) that is empty byitself; the logic is in local classes in the "Local Types"…Handler class (lhc_travel, inherits cl_abap_behavior_handler) holdsvalidations, determinations, actions, features and authorization…Saver class (lsc_zi_travel, inherits cl_abap_behavior_saver) holds thesave sequence methods: finalize, check_before_save…!Watch outAlways use IN LOCAL MODE inside theBO — otherwise your own logic isblocked by feature control andauthorization meant for consumers.4 · IN A REAL PROJECTIn a travel-expense BO, the team implemented acceptTravel without IN LOCAL MODE. The action worked in unittests with a developer user but failed for approvers in quality: the status field was readonly for consumersand the approver lacked the edit authorization, so the framework rejected the action's own UPDATE. Adding IN…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

Part 7 declared validations, determinations, and actions; now we implement them. The behavior pool is a global class, such as ZBP_I_TRAVEL, created from the BDEF's quick fix — it's empty by itself, with the actual logic living in local classes under the "Local Types" tab.

One handler class per entity (lhc_travel, inheriting from cl_abap_behavior_handler) holds the validations, determinations, actions, features, and authorization methods, while a single saver class for the business object (lsc_zi_travel, inheriting from cl_abap_behavior_saver) holds the save sequence methods: finalize, check_before_save, save or save_modified, and cleanup. The method signatures here are generated, not typed by hand.

Handler methods come in a few kinds: FOR VALIDATE ON SAVE for validations, which fill failed and reported; FOR DETERMINE ON MODIFY or ON SAVE for determinations, which call MODIFY ENTITIES IN LOCAL MODE; FOR MODIFY ... FOR ACTION for actions, which return a result; and FOR INSTANCE FEATURES or FOR INSTANCE AUTHORIZATION for feature control and authorization checks.

Inside the business object you should always call MODIFY ENTITIES IN LOCAL MODE — without LOCAL MODE, your own internal logic gets subjected to the same feature control and authorization checks that are meant for external consumers, which blocks it.

These methods work with derived types and a set of standard %-components: TABLE FOR READ RESULT zi_travel\travel and TABLE FOR UPDATE are typical derived types, while %tky is the transactional key (including %is_draft), %key is the key alone, %control marks which fields are set, %msg carries a message, and %element identifies which field a message should highlight.

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.