ERPClimb logoERPClimb
Unmanaged RAP
RAP / CDS / ODataadvanced 15 min read

Unmanaged RAP Part 4: Save Sequence, Transaction Safety and Legacy APIs

Preview · a free account unlocks the full lesson

Key takeaway

Implement the saver class that hands the transactional buffer to the legacy API: finalize, check before save, adjust numbers, save and cleanup — and learn the rules that keep legacy BAPIs and function modules from breaking RAP's all-or-nothing transaction.

In this lessonShow sections

Explanation

The save sequence runs in a fixed order: finalize, then check_before_save, then adjust_numbers, then save, then cleanup. Everything that can possibly fail has to fail before save runs. Legacy posting APIs should be called IN UPDATE TASK from inside save. And one rule overrides everything else: never call COMMIT WORK or BAPI_TRANSACTION_COMMIT in RAP code.

After Part 3, all changes sit in lcl_buffer, with nothing yet in the database. This part writes the saver — the only piece of code that actually calls the legacy API to persist data. Getting this right is what decides whether your RAP app is transactionally safe.

When the consumer commits — Save in Fiori, or COMMIT ENTITIES in EML — RAP calls the saver methods in a fixed order. finalize runs last derivations before any checks: assigning semantic numbers, recalculating totals, setting derived fields, and it can still report errors at this point. check_before_save runs the final consistency check, typically by calling the legacy API in a check or test-run mode, reporting anything that fails in FAILED and REPORTED.

If either finalize or check_before_save reported a failure, RAP stops right there — it calls cleanup_finalize, nothing gets saved, the buffer is kept intact, and the user can correct the data. adjust_numbers, used only with late numbering, maps preliminary IDs (%pid) to the final keys the legacy API returns. save is the point of no return — every buffered change gets handed to the legacy API's save routine, and errors are no longer allowed at this stage.

The framework then performs the commit itself — never your own code — and cleanup clears the buffer so the next transaction starts clean.

The golden rule here is that everything that can fail must fail in finalize or check_before_save — the save method itself must only write. If save hits an error, RAP has no good way to report it, and the transaction ends up in an undefined state, which typically results in a short dump.

In practice, this means using the legacy API's test-run or check mode inside check_before_save — many BAPIs have a TESTRUN parameter, and custom APIs often have a dedicated CHECK method — and calling the actual posting routine inside save only for data that already passed those checks.

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

Referenced SAP objects

Reviewed reference pages for the objects this page mentions.

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.