This page keeps the sales order app open for change and safe from regressions: a customer project adds the field "Delivery priority" with its own check through RAP extensibility, without modifying the app (R19), and ABAP Unit tests with test doubles protect validateCustomer, calculateTotal and approve (R20).
Part 1 – Extensibility: why, who and the key terms
R-ID | Requirement | Where on this page |
|---|---|---|
R19 | A customer project needs an extra field "Delivery priority" without modifying the app | Parts 1–4 |
R20 | Logic is protected by automated tests | Parts 5–8 |
Why first: the sales order app is finished and running. Then a customer project asks for one more field, R19 – "Delivery priority" (H/M/L) with a check – and the app must not be modified, so that the next version of the app (or an SAP upgrade) doesn't overwrite or break the change.
Extensibility lets someone else add fields, checks or even new child nodes to a business object without changing its source code. Think of a house with wall sockets: the owner decides where the sockets are, and anybody can plug a lamp in later without opening the wall. In RAP the owner of a BO (SAP or your own team) opens these sockets explicitly, and the extension is a separate set of objects that survives every upgrade of the original.

1.1 Key terms
Term | Meaning | Sales order example |
|---|---|---|
Field extension | New field in table, CDS views and UI through the extension include |
|
Behavior extension | Extra validations, determinations, actions, side effects in an extension BDEF with its own behavior pool |
|
Node extension | New child entity added to the BO tree (composition in a CDS extension, |
|
Projection extension | Exposes new behavior in a service: |
|
Key user extensibility | Browser apps *Custom Fields* and *Custom Logic*; no ADT needed | A business expert adds a field to SAP's sales document |
Developer extensibility | ADT + ABAP Cloud; extends objects released for extension (contract C0) or own BOs that are marked extensible | Extension of |
Extension include (view) | Include structure in the tables + a key-only CDS view on top: the stable anchor that extensions append to |
|

Part 2 – Owner side: make the sales order BO extensible
Four steps, all in the original package, done once by the team that owns the app. Extensibility needs strict mode in the BDEF.
- Step 1 – extension include structure in the active and the draft table. Its enhancement category and field suffix tell the extender what kind of fields may be appended and how they must be named.
|
- Step 2 – extension include view: a key-only view on the table. Extensions add their fields here, so the base view itself never has to change.
|
- Step 3 – open the base, interface and projection views: an
_Extensionassociation fromZR_SalesOrderto the include view, and the same extensibility annotations – data source_Extensionin the R_ view, the source alias inZI_SalesOrderTPandZC_SalesOrder.
|
- Step 4 – open the BDEF: the
extensibleblock in the header lists exactly which kinds of behavior an extension may add; every entity that accepts extensions getsextensibletoo. MakePrepareextensible so added validations also run when the user clicks Save in the draft app, and mark the mapping extensible (only possible withcorresponding).
|
The projection BDEF gets a plain extensible; in its header (no block) and extensible per entity. An interface BDEF such as ZI_SalesOrderTP takes extensible; only in its header and covers all its entities. SAP's Flight reference scenario (/DMO/R_AgencyTP, /DMO/I_AgencyTP) shows this pattern.
Part 3 – Extender side: add "Delivery priority" and a check (R19)
The extension lives in another package (often another software component) and never touches the original objects. R19 needs one field and one validation.
3.1 The field through all layers
|
- The element name
ZZDlvPrioZSOequals the column namezzdlvpriozsoapart from upper/lower case. That is deliberate:mapping ... corresponding extensiblemaps extension fields by name, so no mapping line is needed and none could be added from outside. - Prefix
ZZ(orYY) and the suffixZSOfrom the include keep extension names apart from anything the owner adds later.
3.2 The check: a behavior extension
A separate BDEF of type extension with its own behavior pool. With using interface the extension works through the BO interface ZI_SalesOrderTP (that is why step 3 extended it); for an own BO without an interface the addition is left out.
|
|
A projection extension is needed only when the extension adds something the service must call, such as an action or a determine action:
|
An extension can … | Where | Note |
|---|---|---|
Add fields | Append + | Only through the extension include view |
Add validations, determinations, additional save | extend behavior for | Only the kinds listed in the original |
Add actions, determine actions, field characteristics | extend behavior for | On every entity marked |
Add side effects | Extension BDEF | Projection-level support depends on the release – check your release |
Add a child node | CDS extension (composition) + | The to-parent association is in the new node's view |
Change or remove existing behavior | – | Not possible – that would be a modification |
Common mistakes
- Extending a BO that is not marked
extensible, or adding a kind of logic theextensible { }block does not list – the extension BDEF won't activate. - Forgetting the draft table: the extension include must be in
zsales_hdr_das well, otherwise the new field is lost while editing. - A validation added in an extension but not added to
Prepare– it runs on activate, but the draft app shows the message only at the very end. - Different names for the column and the element –
correspondingthen can't map the field and the value is never saved.
Part 4 – Extending SAP's released BOs and node extensions
- SAP's transactional BOs (for example
I_SalesOrderTP) open the same sockets. Whether an object may be extended is its release contract C0 – in ADT see *Properties → API State*. - Field extensions go through the extension include views SAP ships for that BO; behavior extensions use
extension using interface I_…TP. Your extension elements carry your namespace prefix (ZZ/YY) so an SAP upgrade never clashes with them. - Try key user extensibility first (Custom Fields app): one field appears in table, CDS, API and UI in one go, without code. Use developer extensibility for logic or cases the app can't cover.
- Extensions of extensions (layering) exist since ABAP 7.58 – check your release.
4.1 Node extensions in brief
A new child entity, for example order notes: a view entity ZZ_R_OrderNote with association to parent ZR_SalesOrder as _SalesOrder, a CDS extension of the parent that adds composition [0..*] of ZZ_R_OrderNote as _ZZNote, and in the BDEF extension extend behavior for SalesOrder { association _ZZNote { create; } } plus define behavior for ZZ_R_OrderNote alias ZZNote …. The original BO must be enabled for node extensions – check your release.
Interview tip
Say it in one line: "The original BO decides what can be extended; the extension is a separate object with its own behavior pool, built on released (C0) anchors, so upgrades don't break it."
Part 5 – Testing RAP: what is real, what is a test double (R20)
Why: R20 – the logic must be protected by automated tests, so that the next change (or the R19 extension) can't silently break validateCustomer, calculateTotal or approve. A RAP BO is tested like any ABAP code: with ABAP Unit. The trick is to decide what is real and what is replaced. When you test the BO itself, the RAP runtime and your handlers are real and only the tables are replaced; when you test a class that only uses the BO, the whole BO is replaced. Like a crash test: the car is real, the passenger is a dummy.

You want to test … | Tool | Replaces |
|---|---|---|
Validations, determinations, actions of your BO (through EML) | ABAP Unit + | Tables and CDS views read with ABAP SQL (zsales_hdr, zsales_itm, I_Customer) |
Logic inside a CDS view entity (calculations, joins) | cl_cds_test_environment | The data sources of that CDS entity |
A class that calls your BO with EML (it should not care how the BO works) | cl_botd_txbufdbl_bo_test_env | The whole BO: an in-memory transactional buffer |
The same, but you want to fix exact responses and count calls | cl_botd_mockemlapi_bo_test_env | Every EML call: configured input → output, then verify |
One handler method in isolation (rare) | Local test class, | Nothing – you call the method yourself |
5.1 Global vs local test classes – SAP's recommendation
Where a test class lives follows from what it tests. SAP's RAP test guide separates unit tests of the behavior implementation (one handler or saver method, called directly) from integration tests that use the BO from outside through EML – and the two end up in different places.
Test type | Class | Where | Why / tools |
|---|---|---|---|
Unit test of one handler / saver method (validateCustomer, finalize …) | Local: ltc_… DEFINITION FINAL FOR TESTING | Test Classes tab (test include) of the behavior pool ZBP_R_SalesOrder | lhc_ / lsc_ classes are local to the pool and their methods private: DEFINITION DEFERRED FOR TESTING + FRIENDS, CREATE OBJECT … FOR TESTING (Part 8). SQL / CDS test doubles; legacy function modules → function module test doubles (8.1) |
Integration test of the BO through EML (Part 6) | Global: zcl_test_salesorder … PUBLIC … FOR TESTING | Its own class, linked with "! @testing BDEF:ZR_SalesOrder | Runs the whole BO like a consumer (determinations, validations, feature control, COMMIT ENTITIES); cl_osql_test_environment / cl_cds_test_environment. SAP does this in RAP100 exercise 8 and in /DMO/TC_TRAVEL_M |
Unit test of a class that only consumes the BO (ZCL_SO_UPLOAD, Part 7) | Local: ltc_… in that class | Test Classes tab of ZCL_SO_UPLOAD | The BO is a dependency: cl_botd_txbufdbl_bo_test_env or cl_botd_mockemlapi_bo_test_env |
- Clean ABAP: put unit tests into the local test include of the class under test – people find them when they refactor the class and run them with one key press (Ctrl+Shift+F10 in ADT).
- Clean ABAP: component and integration tests don't belong to one class – put them into a separate global class marked FOR TESTING and ABSTRACT (so production code can't reference it), with the tests in its local test classes, and document the tested objects with test relations. SAP's RAP samples put the test methods directly into a global FOR TESTING class instead – both work; the test relation is what links the test to the BO.
- Name local test classes by purpose: ltc_<method under test> or ltc_<common given>, not ltc_test or the class name again. Help methods shared by several test classes go into a help class (lth_…) used by inheritance or delegation.
- Test relation "! @testing BDEF:ZR_SalesOrder: the tests can be shown and run from the BDEF in ADT (Ctrl+Shift+F12 also runs tests maintained as test relations). A global test class always names its code under test this way; local test classes in the pool may carry it too (SAP's /DMO/BP_TRAVEL_U does). The kind BDEF: is listed in the current keyword documentation – check your release.
" Local: Test Classes tab of ZBP_R_SalesOrder - one handler method (Part 8)
" (Local Types: CLASS ltc_validatecustomer DEFINITION DEFERRED FOR TESTING.
" and lhc_salesorder ... FRIENDS ltc_validatecustomer)
"! @testing BDEF:ZR_SalesOrder
CLASS ltc_validatecustomer DEFINITION FINAL FOR TESTING
RISK LEVEL HARMLESS DURATION SHORT.
PRIVATE SECTION.
DATA cut TYPE REF TO lhc_salesorder. " CREATE OBJECT cut FOR TESTING
METHODS unknown_customer_fails FOR TESTING RAISING cx_static_check.
ENDCLASS.
" Global: own class pool - the whole BO through EML (Part 6)
"! @testing BDEF:ZR_SalesOrder
CLASS zcl_test_salesorder DEFINITION PUBLIC FINAL CREATE PUBLIC
FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
PRIVATE SECTION.
METHODS approve_sets_status_a FOR TESTING RAISING cx_static_check.
ENDCLASS.Part 6 – Testing the BO through EML: validateCustomer, calculateTotal, approve
SAP's approach (RAP100 exercise 8): a test class linked to the BDEF with the ABAP Doc comment "! @testing BDEF:ZR_SalesOrder, SQL test doubles for the data, then EML and assertions on FAILED / REPORTED or on the read result. COMMIT ENTITIES runs the real save sequence – against the doubles. The three tests of R20 each protect one requirement:


6.1 The test class and its set-up
|
6.2 validateCustomer (R6) – assert FAILED of COMMIT ENTITIES
|
- Add the positive twin (customer
0010100001→commit_failedinitial). IfvalidateCustomeralso rejects blocked customers, insert a second customer with the block flag insetupand test it too. - A successful COMMIT also runs
setSalesOrderId, which draws a real number from the number range (→ 06 · Feature Control, Authorization & Numbering). Keep the number range call in a small class you can replace in tests, or accept used numbers in the development system.
6.3 calculateTotal (R5) – read the field back, no commit needed
|
6.4 approve (R7) – status, feature control and authorization
|
- Authorization checks run for the user who executes the test.
approveneedsZAO_SOand a creator other than the current user (→ 06 · Feature Control, Authorization & Numbering) – that is whyinsert_ordersetscreated_by = 'OTHER_USER'. Test such rules on purpose, not by accident. - To test the "only managers" part, restrict the test user's authorizations with the ABAP Unit authority-check controller (
cl_aunit_authority_check=>get_controller( )->restrict_authorizations_to( ... ), reset it inteardown) and expectif_abap_behv=>cause-unauthorized– cheat sheet *14_ABAP_Unit_Tests*; check your release.
You test … | Assert on |
|---|---|
A validation | FAILED (and REPORTED) of |
A determination on modify / an action | READ ENTITIES afterwards and check the field |
A determination on save | COMMIT ENTITIES first – it only runs in |
Feature control / authorization |
|
Common mistakes
- No test doubles: COMMIT ENTITIES then really writes to
zsales_hdr. - No
ROLLBACK ENTITIESinteardown– the next test starts with leftovers in the buffer. - Asserting REPORTED only: a message alone does not stop the save – FAILED does.
- Testing an
on savedetermination without COMMIT ENTITIES – it never ran.
Part 7 – BO test doubles for classes that use the BO
The nightly job of R12 uses a class ZCL_SO_UPLOAD that reads a CSV file and creates orders with EML. Its test should not depend on the BO's validations or tables, so the EML calls are redirected to a double (cheat sheet *14_ABAP_Unit_Tests*).
|
|
- Use the buffer double when you care about the result ("two orders exist afterwards"), the mock EML API when you care about the call ("exactly one CREATE with these fields"). For MODIFY use
for_modify( )andset_instances_for_create( )in the same way.
Part 8 – Testing one handler method directly
SAP's RAP test guide treats this as the unit-test level: each handler or saver method (validation, determination, action, saver step) is tested on its own in the Test Classes tab of the behavior pool – the EML tests of Part 6 are the integration level on top. Handler classes are local classes of the behavior pool and have no public constructor. The local test class is declared first with DEFINITION DEFERRED FOR TESTING, the handler names it as a FRIENDS, and the test creates the handler with CREATE OBJECT … FOR TESTING.
|
Because the methods still read the buffer (READ ENTITIES … IN LOCAL MODE), the test first fills a transactional buffer double of the own BO. Use both levels: unit tests per handler / saver method for the logic, plus EML integration tests (Part 6) that run the whole BO like a consumer.
- Contract checks: the RAP runtime checks that handlers answer correctly (for example no FAILED entry for a key that was never requested). Since 2311 such violations make unit tests fail; the contract check
BEHAVIOR_BAD_HANDLER_RESPONSEexists since 2502 – check your release.
Interview tip
Name both sides: "For the BO itself I unit-test each handler and saver method in the behavior pool's test classes and add EML integration tests with SQL test doubles; for consumers of a BO I use the RAP BO test doubles – the transactional buffer double or the mock EML API."
8.1 Testing an unmanaged BO
In an unmanaged BO (→ 09 · Unmanaged Scenario & Save Variants) the handler and saver methods are the whole BO, and they mostly call legacy code. SAP's unmanaged reference BO /DMO/I_TRAVEL_U shows the approach: local test classes in the behavior pool call every handler and saver method directly, and the legacy function modules are replaced by function module test doubles.
- Two local classes in the Test Classes tab of /DMO/BP_TRAVEL_U: ltcl_handler (FRIENDS of lhc_travel) and ltcl_saver (FRIENDS of lsc_I_TRAVEL_U), both with "! @testing BDEF:/DMO/I_Travel_U and CREATE OBJECT … FOR TESTING. For us: friends of lhc_SalesOrder and lsc_ZR_SalesOrder.
- Legacy calls: cl_function_test_environment=>create( ) with the list of function modules in class_setup – every CALL FUNCTION of these modules then goes to the double. Per test: get_double( ), an input configuration (set_importing_parameter), an output configuration (set_exporting_parameter) and configure_call( )->when( … )->then_set_output( … ); ignore_all_parameters( ) accepts any input. clear_doubles( ) in teardown.
- One success and one failure test per method (read_success / read_fail, rba_success / rba_fail …): for the failure the double returns error messages, and the test asserts FAILED (and REPORTED). Handler parameters are typed with the derived types, e.g. TABLE FOR READ IMPORT zr_salesorder\\salesorder and RESPONSE FOR FAILED EARLY zr_salesorder.
- lcl_buffer=>orders is static: clear it in setup, otherwise a test sees the rows of the previous one.
- Classes that only consume the unmanaged BO are tested exactly as in Part 7: the RAP BO test double framework replaces the provider implementation – SAP names "(un)managed read/modify operations" as the dependencies it isolates.
" Test Classes tab of ZBP_R_SalesOrder (unmanaged, Parts 2-4 of page 09)
" Local Types: CLASS ltc_read DEFINITION DEFERRED FOR TESTING.
" lhc_SalesOrder ... FRIENDS ltc_read
"! @testing BDEF:ZR_SalesOrder
CLASS ltc_read DEFINITION FINAL FOR TESTING RISK LEVEL HARMLESS DURATION SHORT.
PRIVATE SECTION.
CLASS-DATA fm_env TYPE REF TO if_function_test_environment.
DATA cut TYPE REF TO lhc_SalesOrder.
CLASS-METHODS class_setup.
METHODS setup.
METHODS teardown.
METHODS legacy_order_is_returned FOR TESTING RAISING cx_static_check.
ENDCLASS.
CLASS ltc_read IMPLEMENTATION.
METHOD class_setup. " every CALL FUNCTION 'Z_SO_READ' hits the double
fm_env = cl_function_test_environment=>create(
function_modules = VALUE #( ( 'Z_SO_READ' ) ) ).
ENDMETHOD.
METHOD setup.
CREATE OBJECT cut FOR TESTING.
CLEAR lcl_buffer=>orders. " static buffer: every test starts empty
ENDMETHOD.
METHOD teardown.
fm_env->clear_doubles( ).
ENDMETHOD.
METHOD legacy_order_is_returned.
DATA keys TYPE TABLE FOR READ IMPORT zr_salesorder\\salesorder.
DATA result TYPE TABLE FOR READ RESULT zr_salesorder\\salesorder.
DATA failed TYPE RESPONSE FOR FAILED EARLY zr_salesorder.
DATA reported TYPE RESPONSE FOR REPORTED EARLY zr_salesorder.
DATA(uuid) = cl_system_uuid=>create_uuid_x16_static( ).
DATA(order) = VALUE zsales_hdr( order_uuid = uuid customer_id = '0010100001' ).
" given: the buffer is empty and the legacy read knows the order
DATA(fm_read) = fm_env->get_double( 'Z_SO_READ' ).
DATA(input) = fm_read->create_input_configuration(
)->set_importing_parameter( name = 'IV_ORDER_UUID' value = uuid ).
DATA(output) = fm_read->create_output_configuration(
)->set_exporting_parameter( name = 'ES_HEADER' value = order ).
fm_read->configure_call( )->when( input )->then_set_output( output ).
" when
keys = VALUE #( ( OrderUUID = uuid ) ).
cut->read( EXPORTING keys = keys
CHANGING result = result
failed = failed
reported = reported ).
" then
cl_abap_unit_assert=>assert_initial( failed ).
cl_abap_unit_assert=>assert_equals( exp = order-customer_id
act = result[ 1 ]-CustomerID ).
ENDMETHOD.
ENDCLASS.Part 9 – Interview questions
Q1. What must the owner of a BO do before anyone can extend it?
Open sockets in every layer: an extension include structure in the active and draft table, a key-only extension include view, an _Extension association and @AbapCatalog.extensibility on the R_, I_ and C_ views, and in the BDEF (strict mode) an extensible { ... } block listing what may be added, extensible on each entity, Prepare extensible and mapping ... corresponding extensible. Nothing the owner didn't open can be extended.
Q2. How do you add a field like "Delivery priority" to your own RAP app without modifying it?
In a separate package: extend type on the extension include (the column appears in the active and draft table), extend view entity on the include view, the base view (through _Extension), the interface and the projection with the UI annotations. A check goes into an extension BDEF (extension using interface ..., extend behavior for) with its own behavior pool, and into extend draft determine action Prepare.
Q3. How do you extend a released SAP BO?
If the key user app Custom Fields is enough, use it – no code. Otherwise developer extensibility in ADT: fields through the extension include views SAP ships, logic through a BDEF extension (extension using interface I_…TP) with its own behavior pool. Only objects released for extension (C0) and only what the original marked extensible can be extended.
Q4. Scenario: the business wants a "Priority" field on SAP's standard sales order in S/4HANA Cloud.
First the key user app Custom Fields: add the field to the sales document business context and enable it for UI and APIs. If logic is needed (e.g. priority H only for big orders), a developer extension: field through the extension include view, a validation in a BDEF extension of the released interface. Never a modification – that is not possible in the public cloud anyway.
Q5. Why does an extended validation have to be added to Prepare?
In a draft app the user clicks Save, which calls the determine action Prepare before Activate. Only the validations listed in Prepare run at that moment and show their messages on the draft. An extension adds its validation with extend draft determine action Prepare, which works only if the owner declared Prepare extensible.
Q6. How do you test a RAP BO?
With ABAP Unit: a test class linked to the BDEF ("! @testing BDEF:...), SQL or CDS test doubles for the data, and EML calls. For validations I assert FAILED and REPORTED of COMMIT ENTITIES; for determinations on modify and actions I read the field back; for feature control and authorization I check %fail-cause or GET PERMISSIONS. teardown runs ROLLBACK ENTITIES.
Q7. Transactional buffer double or mock EML API?
Both replace a whole BO for a class that only consumes it. The transactional buffer double (cl_botd_txbufdbl_bo_test_env) behaves like a simple in-memory BO, so I assert on the result. The mock EML API (cl_botd_mockemlapi_bo_test_env) returns configured outputs for a given input and lets me verify how often a call was made, so I assert on the call.
Q8. Why can a test of the approve action fail although the code is correct?
Because the runtime checks feature control and authorization for the test user: approve is disabled for orders that are not in status N, needs the authorization object, and the four-eyes rule rejects orders the same user created. A good test sets up the data on purpose (status N, another creator) and tests the rejections explicitly, e.g. with the ABAP Unit authority-check controller.
🏠 Start Here · ◀ 11 · Files & Integration · 13 · Quality & Clean Core ▶ · Sections: CORE ABAP | OOPS ABAP | ABAP on HANA | Clean Core | RAP | ABAP Points | SAP Fiori | SAPUI5 | Mobile Development (MDK) | BTP Foundations | BTP Development | CAP | SAP Build | ABAP on BTP | Integration Suite | SAP Business AI | SAP BASIS | Security | SAP SDLC
Functional: FICO ABAP | TRM ABAP | VIM | SAP BIS | SD ABAP | MM ABAP | PP ABAP | QM ABAP | PM ABAP | PS ABAP | EWM | TM ABAP | GTM ABAP | EHS ABAP | HR ABAP | BW | SAP Datasphere | SAP Business Data Cloud | SAP MDG | SAP Analytics Cloud | SAP Ariba | SAP CX | SAP IBP