RAP Basics
Architect / Cross-trackAdvanced

Behavior Implementation and Behavior Pool

Understand where custom RAP logic is implemented in behavior pools.

Explanation

Behavior implementation classes contain custom logic for validations, determinations, actions, authorization checks and unmanaged save handling. These classes are generated or created as behavior pools. In managed RAP, you often implement only custom hooks such as validation or action logic. In unmanaged RAP, you must implement more lifecycle methods and save logic. Good behavior implementation should be clean, modular and message-driven. Avoid writing huge logic directly inside one method. Delegate complex business rules to helper or domain service classes.

Code example

ABAP Code
METHOD validateAmount.  * Read changed entities using RAP runtime context READ ENTITIES OF ZI_Expense IN LOCAL MODE ENTITY Expense FIELDS ( Amount Currency ) WITH CORRESPONDING #( keys ) RESULT DATA(lt_expense).  LOOP AT lt_expense INTO DATA(ls_expense).  IF ls_expense-Amount > 100000. * Add failed key so RAP knows which instance failed APPEND VALUE #( %tky = ls_expense-%tky ) TO failed-expense.  * Add meaningful message for UI/user APPEND VALUE #( %tky = ls_expense-%tky %msg = new_message_with_text( severity = if_abap_behv_message=>severity-error text = 'Amount exceeds approval limit' ) ) TO reported-expense. ENDIF.  ENDLOOP. ENDMETHOD. * Purpose:* Behavior implementation checks business rule and reports RAP messages.* failed and reported structures are important for user feedback.

Real project scenario

An approval action in RAP called a service class to check approval authority, update status and return messages. The behavior method remained short and easy to test.

Common mistakes

- Not filling failed structure for validation errors. - Returning unclear messages. - Writing large business logic directly in behavior method. - Not using READ ENTITIES correctly.

Best practices

- Keep behavior methods focused. - Use helper classes for complex rules. - Return failed and reported correctly. - Test validation and action messages in Fiori.

Interview angle

Senior candidates should explain behavior pool methods, failed/reported messages and LOCAL MODE reads.