ERPClimb logoERPClimb
Behavior Implementations
RAP / CDS / ODataadvanced 11 min read

Behavior Implementations Part 5: Performance, Unit Testing and Debugging

Preview · a free account unlocks the full lesson

Key takeaway

Keep behavior implementations fast, tested and diagnosable: set-based handler design, EML-based ABAP Unit tests with isolation, and the tools to debug RAP requests coming from Fiori or APIs.

In this lessonShow sections

Visual overview

Behavior Implementations Part 5: Performance, Unit Testing and Debugging — learning sheetFlow: Add a test class with tests for one validation, one action and one bulk case (code example) → Run with Ctrl+Shift+F10 in ADT; add to ATC/CI → Record an ABAP Cross Trace for a Fiori save and read which methods ran. Key ideas: PERFORMANCE — DESIGN FOR SETS; UNIT TESTING WITH EML; DEBUGGING RAP REQUESTS; CODE REVIEW CHECKLIST. Watch out: Always include a bulk test (hundreds of instances).ERPClimb.com / RAP / LESSON 5/5 / LEARNING SHEETBehavior Implementations Part 5: Performance, Unit Testingand Debugging1 · HOW IT FLOWS1Add a test class withtests for one validation,one action and one bulk…2Run with Ctrl+Shift+F10in ADT; add to ATC/CI3Record an ABAP CrossTrace for a Fiori saveand read which methods…2 · KEY IDEAS EXPLAINEDPerformance — Design For SetsOne READ ENTITIES for all keys, with only thefields needed.One MODIFY ENTITIES with a table, never one perkey.Unit Testing With EMLTest class in the behavior pool (Test Classes tab)or a separate test class, "FOR TESTING".Arrange with %cid; Act with MODIFY ENTITIES (andCOMMIT ENTITIES RESPONSE when the save sequencematters); Assert on failed, reported and read-back…Debugging RAP RequestsBreakpoints in handler methods work for EML testsand console classes directly.Requests from Fiori or APIs run under anotheruser/session: set external (user) breakpoints inADT for the calling user, or for all requests of…Code Review ChecklistAll methods process all keys; no keys[ 1 ].%tky everywhere; IN LOCAL MODE inside the BO.3 · REMEMBER · WATCH OUTRememberHandlers are set-based: one READ, one MODIFY.Test with EML + COMMIT ENTITIES; isolate with test doubles.Debug Fiori calls with external breakpoints and ABAP Cross Trace.!Watch outAlways include a bulk test (hundredsof instances).4 · IN A REAL PROJECTA mass-approval feature passed all tests with five orders and timed out in production with 800. An ABAP CrossTrace and an SQL trace showed that the approve action called a helper that selected the approver's cost-centerdata with SELECT SINGLE per key, and that the item total determination had a trigger on all fields, causing…Original ERPClimb learning sheet • Verify against your SAP release and edition

Explanation

Handlers should always be set-based — one READ, one MODIFY, never one per instance. Testing relies on EML combined with COMMIT ENTITIES, with test doubles used to keep tests isolated. Debugging Fiori calls relies on external breakpoints and ABAP Cross Trace. And a bulk test, covering hundreds of instances, should always be part of the test suite.

Parts 1 through 4 covered how to write behavior code; this part covers how to make it fast, prove it works, and find problems quickly when it doesn't.

Performance comes down to designing for sets. Handlers receive tables of keys, since one mass action or API batch can send hundreds at once.

The rules that follow from this: one READ ENTITIES for all keys, requesting only the fields actually needed; one MODIFY ENTITIES using a table, never one call per key; external data — master data, customizing — read once for all keys, via a join or FOR ALL ENTRIES after an emptiness check, never SELECT SINGLE inside a loop; keeping determination triggers narrow, since a determination that changes fields which themselves trigger other determinations can cascade unexpectedly; avoiding reading children when only root fields are actually needed; and measuring with production-like volumes, using an SQL trace (ST05) for database statements and the ABAP profiler (SAT or ADT profiling) for ABAP runtime.

Unit testing with EML means testing the behavior exactly the way consumers use it.

A test class can live in the behavior pool's Test Classes tab, or as a separate class marked "FOR TESTING." The pattern is to arrange with %cid, act with MODIFY ENTITIES (and COMMIT ENTITIES RESPONSE when the save sequence itself matters), assert on failed, reported and read-back data, and use ROLLBACK ENTITIES in teardown.

Each rule deserves its own test: every validation, both passing and failing; every determination, including a check for idempotency by running it twice; every action, in both valid and invalid states; feature control results, checked via READ ENTITIES … RESULT with GET PERMISSIONS or by simply attempting the operation; and bulk behavior, such as 200 keys at once.

Since tests that commit actually write to the database, isolation matters — the ABAP SQL test double framework (cl_osql_test_environment) handles tables and CDS views, and, on releases that provide them, RAP BO test doubles handle other business objects your code calls.

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.