The business wants readable order numbers from a number range object. You can draw the number in early numbering, keep a UUID key and set the number in an on-save determination, or use late numbering. Which do you choose, and why?
Say your answer out loud first.
Practise another way
I start from two questions: must the number be the key, and does a gap matter? If a UUID key is fine, I keep it and treat the readable number as a semantic field.
If the number must be the key and draft is not needed, early numbering with cl_numberrange_runtime in the FOR NUMBERING handler is simplest. If gaps must be avoided, I use late numbering in adjust_numbers.
Option 1: early numbering. The final key is assigned during create, in the interaction phase.
define behavior for ZR_Order alias Order
early numbering
{ field ( readonly ) OrderID; ... }
METHOD earlynumbering_create.
cl_numberrange_runtime=>number_get(
EXPORTING nr_range_nr = '01' object = 'ZORDER'
quantity = CONV #( lines( entities ) )
IMPORTING number = DATA(last) returned_quantity = DATA(qty) ).
DATA(next) = last - qty.
LOOP AT entities INTO DATA(e).
next += 1.
APPEND VALUE #( %cid = e-%cid OrderID = next ) TO mapped-order.
ENDLOOP.
ENDMETHOD.
SAP's /DMO/BP_TRAVEL_M adds the error handling: on cx_number_ranges it fills failed and reported. If too few numbers are left, it reports %fail-cause conflict. Trade-off: every discarded draft or failed save burns a number.
Option 2: UUID key plus a semantic number. Keep field ( numbering : managed, readonly ) OrderUUID;. An on save determination sets OrderID once, as SAP's draft sample /DMO/R_TRAVEL_D does with setTravelNumber.
The draft works on the UUID from the first click, and the number exists only for saved orders. The sample derives the number with SELECT MAX, which is simple.
Two parallel saves could then get the same value, so draw it from a number range object instead.
Option 3: late numbering. Declare late numbering and implement adjust_numbers, which runs after the point of no return. Instances carry a preliminary %pid (or a temporary key in %tmp) until then.
Only instances that really reach the database consume a number. SAP's reuse-services sample draws a number range there and raises a short dump if the number range fails.
With the default saver class, an error after the point of no return cannot stop the save. Only CL_ABAP_BEHAVIOR_SAVER_FAILED lets adjust_numbers return FAILED, as a documented exception. Draft tables for late numbering need an extra DRAFTUUID key field.
How to decide
| Need | Choice |
|---|---|
| Number may be a field, draft wanted | UUID key + on-save number |
| Number is the key, few drafts, small gaps OK | Early numbering |
| Number is the key and gaps matter | Late numbering |
Release note. All three work on SAP BTP ABAP environment (now SAP Business AI Platform, ABAP environment) and ABAP Platform 2022 or later. cl_numberrange_runtime is released for ABAP Cloud.
Separates key from semantic number, shows the FOR NUMBERING handler with cl_numberrange_runtime and MAPPED, and explains gaps, draft impact and the late-phase limits of adjust_numbers.
Picks one option by habit, or derives the next number with SELECT MAX in a determination without discussing parallel saves.
Assuming early numbering is gap-free. Each discarded draft or rejected save consumes a number that is never used.
- What do you return in MAPPED from earlynumbering_create, and why?
- What happens when the number range fails in adjust_numbers, and what does CL_ABAP_BEHAVIOR_SAVER_FAILED change?
- How does a child entity get its parent's late number?
6 official pages and 2 prep guides. Confidence: high. Checked 3 Dec 2026.
- Prep guide Gives the question.
- Prep guide Gives the question.
- Official page Backs the answer.
- Official page Backs the answer.
- Official page Backs the answer.
- Official page Backs the answer.
- Official page Backs the answer.
- Official page Backs the answer.