sapui5tutors SAPUI5 • Fiori • SAP BTP Step-by-step tutorials Real project examples Interview Q&A
Practical SAPUI5 • Fiori • SAP BTP tutorials and interview prep

RAP Validations and Determinations: Business Logic Placement

Business logic needs an address

Every RAP object accumulates business logic: totals to calculate, statuses to derive, consistency to check. The question isn't whether to implement it — it's where. RAP gives you two homes, and mixing them up causes real bugs.

Determinations derive values. Validations check consistency. Different jobs, different timing, different rules.


Determinations: derive, don't judge

A determination calculates something from existing data — a status from line items, a total from quantities and prices, a default value at creation. It modifies the object, and the framework runs it at defined trigger points.

determination setStatus on modify { field Status; }
determination calcTotals on modify { field NetAmount; }

The on modify timing means: run this when the listed fields change, while the user is still editing. The UI reflects derived values immediately — the status flips the moment the last line item is entered.

Determinations should be pure derivations: same input, same output, no side effects. If your determination calls an external service or raises errors, it's in the wrong place.


Validations: judge, don't modify

A validation checks consistency and reports problems — it never changes data. The classic timing is on save:

validation checkTotals on save { field NetAmount; }
validation checkCustomer on save { field CustomerID; }

on save means the check runs at activation time — when a draft becomes live data. This is the key insight: users can keep inconsistent drafts (a half-filled order saved for later), they just can't activate bad data.

That's not a quirk, it's the design. Draft exists precisely so users can work incrementally. Validating too early destroys that.


The placement rules

  • Deriving a value? Determination, on modify, triggered by the fields it reads.
  • Checking consistency? Validation, on save, so drafts stay workable.
  • Checking something cheap and input-level? (format of a field, mandatory entry) — validation on modify is fine; immediate feedback helps.
  • Cross-entity checks? (does this customer exist, is the material blocked) — validation on save; they need stable data to check against.

How they report problems

Both report through the same pattern — never exceptions:

METHOD checkTotals.
  READ ENTITIES OF zi_salesorder_tp IN LOCAL MODE
    ENTITY SalesOrder
      FIELDS ( NetAmount ) WITH CORRESPONDING #( keys )
    RESULT DATA(orders).

  LOOP AT orders INTO DATA(order).
    IF order-NetAmount <= 0.
      APPEND VALUE #( %tky = order-%tky ) TO failed-salesorder.
      APPEND VALUE #( %tky = order-%tky
                      %msg = NEW zcx_salesorder( textid = zcx_salesorder=>amount_invalid )
                      %element-NetAmount = if_abap_behv_message=>severity-error )
        TO reported-salesorder.
    ENDIF.
  ENDLOOP.
ENDMETHOD.

The pattern: mark failures in failed, attach messages in reported. The framework turns this into proper Fiori messages on the right fields. Raise an exception instead and you'll break the draft flow — the user gets a dump instead of a helpful message.

Never raise exceptions from validations or determinations. Report via failed and reported. Exceptions are for "the system is broken," not "the data is wrong."

Get the placement right and your business logic reads like a spec: derivations happen live, checks happen at activation, users are never blocked mid-thought.

Ever validated too early and annoyed your users? Confess in the comments.