RAP Build-Along Part 4: Behavior Implementation — Validations, Determinations and Actions
Preview · a free account unlocks the full lesson
Part 4 of the RAP Bootcamp implements the business rules declared in Part 3: initial status and total-price determinations, date and child validations, Accept/Reject actions, FAILED/REPORTED with %tky, %msg and %element, instance feature control and authorization — all with bulk-safe EML IN LOCAL MODE and no COMMIT WORK.
In this lessonShow sectionsHide sections
Visual overview
Explanation
This part builds the complete behavior pool ZBP_I_RAP_TRAVEL, with local handler classes lhc_Travel and lhc_Booking covering: setInitialStatus, a determination on modify giving a new Travel status 'O' (open); calculateTravelID, a determination on save that assigns the readable TravelID; recalcTotalPrice and calcTotalOnBooking, determinations that keep TotalPrice equal to BookingFee plus the sum of FlightPrice; validateDates, a validation ensuring Begin is on or before End and Begin isn't in the past; validateCustomer, a validation ensuring Customer is filled; validateFlightPrice, a child validation ensuring price is greater than 0 with currency set; acceptTravel and rejectTravel, actions that change status and return a result; get_instance_features, feature control that disables actions or fields by status; and get_instance_authorizations/get_global_authorizations, which check an authorization object.
This assumes Part 3 is complete, with an active BDEF declaring these determinations, validations, actions, features : instance, and authorization master ( instance, global ), plus generated behavior pool stubs.
The RAP runtime calls your methods with tables of keys, never single rows — one OData $batch or one EML statement can touch a thousand Travels, so your code has to read them in one statement, process in memory, and write back in one statement.
Three rules show up in every method: IN LOCAL MODE, used because EML inside the BO's own handlers bypasses feature control and authorization checks, since the BO is changing itself rather than acting as a consumer; %tky, the transactional key (the key plus %is_draft), which should always be used instead of %key in a draft BO, or draft and active instances get mixed up; and no COMMIT WORK, no ROLLBACK WORK, and no direct UPDATE on BO tables, since the RAP runtime owns the transaction — handlers run in the interaction phase, saving happens later in the save sequence, and committing inside a handler breaks draft, locking, and the all-or-nothing save.
The response parameters you work with are failed, which lists which instances failed (%tky plus an optional %fail-cause); reported, which carries messages for the consumer (%tky, %msg, %element, %state_area); mapped, which maps a %cid to its final key for created instances; and result, which carries an action's result or a feature/authorization result per instance.
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
More lessons in this topic
- RAP Basics Part 1: RAP Architecture — Layers, Artifacts and When RAP Fits
- RAP Basics Part 10: EML — Entity Manipulation Language
- RAP Basics Part 11: Draft, Locking and Authorization
- RAP Basics Part 2: Data Model Design — Tables, Keys, Administrative Fields and Interface Views
- RAP Basics Part 3: Projection Layer and Metadata Extensions
- RAP Basics Part 4: Implementation Types — Managed, Unmanaged, Additional Save and Unmanaged Save
- RAP Basics Part 5: Root Entity, Child Entity and Composition
- RAP Basics Part 6: Behavior Definition — CRUD, Field Control and Features
Interview questions on this topic
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.