ERPClimb logoERPClimb
RAP Basics
Architect / Cross-trackintermediate 31 min read

RAP Build-Along Part 4: Behavior Implementation — Validations, Determinations and Actions

Preview · a free account unlocks the full lesson

Key takeaway

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 sections

Visual overview

RAP Build-Along Part 4: Behavior Implementation — Validations, Determinations and Actions — learning sheetIn one line: 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.ERPClimb.com / ARCH / LESSON 4/9 / LEARNING SHEETRAP Build-Along Part 4: Behavior Implementation —Validations, Determinations and Actions1 · IN ONE LINEPart 4 of the RAP Bootcamp implements the business rules declared in Part 3: initial statusand total-price determinations, date and child validations, Accept/Reject actions,FAILED/REPORTED with %tky, %msg and %element, instance feature control and authorization —…2 · KEY IDEAS EXPLAINED1The complete behavior pool `ZBP_I_RAP_TRAVEL` withlocal handler classes `lhc_Travel` and`lhc_Booking`:2| Method | Kind | Rule | |---|---|---| |`setInitialStatus` | Determination on modify | NewTravel gets status `O` (open) | |`calculateTravelID` | Determination on save |Assign readable `TravelID` | | `recalcTotalPrice`/ `calcTotalOnBooking` | Determinations |…3The RAP runtime calls your methods with tables ofkeys, never single rows. One OData `$batch` or oneEML statement can touch 1,000 Travels; your codemust read them in one statement, process inmemory, and write back in one statement.41. `IN LOCAL MODE` — EML inside the BO's ownhandlers bypasses feature control andauthorization checks (the BO is changing itself,not a consumer). 2. `%tky` (transactional key) —the key plus `%is_draft`. Always use `%tky`, not`%key`, in a draft BO; otherwise you mix draft and…3 · DO · AVOIDBest practice!Common mistakeAlways bulk: one read, in-memory processing,one modify per handler.Use `%tky` everywhere in draft BOs.Keep determinations idempotent; validationsside-effect-free.✕Looping over `keys` with one EML call per keyinstead of bulk reads/modifies.✕Using `%key` instead of `%tky` in a draft BO —reads return nothing or the wrong instance.✕Modifying data in a validation; validationsonly report.4 · IN A REAL PROJECTA mass-upload job created 5,000 bookings through EML and ran for 40 minutes. The determination looped over`keys` and executed one `READ ENTITIES` and one `MODIFY ENTITIES` per key, and it also called `COMMIT WORK`"to be safe", which caused partially saved drafts. Rewriting it to one bulk read-by-association…Original ERPClimb learning sheet • Verify against your SAP release and edition

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.

Flow diagram comparing RAP determinations, validations and actions with FAILED and REPORTED responses.
RAP behavior rules: determinations update values, validations reject invalid save requests, and actions express business commands.View full-size
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.