What is Numbering characteristic in ABAP RAP?
1. Early Numbering:
➯ When it occurs: Early numbering happens before the data is persisted in the database. It is triggered as soon as the business object is created.
➯ How it works: The unique number for the object is generated during the creation phase, even before the commit operation takes place. This means that the number is available immediately after the object is created and can be used in subsequent processing steps.
➯ Use case: Early numbering is useful when you want to assign a unique identifier to an object as soon as it is created, so that the number can be used right away, without waiting for the persistence step.
2. Late Numbering:
➯ When it occurs: Late numbering happens after the data is persisted to the database, typically during the commit phase or just before the object is actually saved.
➯ How it works: The number is only generated and assigned once the object is successfully stored in the database. This ensures that the object already exists before it gets a unique number.
➯ Use case: Late numbering is suitable when you want to make sure that the object is fully created and saved before the number is assigned, or when you need to ensure that the object is correctly validated before the number is generated.

Let’s understand the signature of Numbering
➯ IMPORTING parameter entities – includes all entities for which keys must be assigned
➯ Implicit CHANGING parameters ( return parameters ):
➔ mapped – used to provide the consumer with ID mapping information
➔ failed – used for identifying the data set where an error occurred
➔ reported – used to return messages in case of failure.

DATA: entity TYPE STRUCTURE FOR CREATE zr_raptech_travel,
travel_id_max TYPE /dmo/travel_id.
"***********you can write your on set of logic**********
LOOP AT entities INTO entity WHERE travelid is NOT INITIAL.
APPEND CORRESPONDING #( entity ) to mapped-travel.
ENDLOOP.
DATA(entities_wo_travelid) = entities.
" only consider entity whose travelid is missing
DELETE entities_wo_travelid WHERE TravelID IS NOT INITIAL.

" find last number used
SELECT SINGLE
FROM zraptech_travel " travel table
FIELDS MAX( travel_id ) AS travelID
INTO @travel_id_max.
IF sy-subrc = 0.
ENDIF.
"Get max travel ID from draft table
SELECT SINGLE
FROM zrptech_travel_d " draft table
FIELDS MAX( travelid )
INTO @DATA(max_travelid_draft).
IF sy-subrc = 0.
ENDIF.
IF max_travelid_draft > travel_id_max.
travel_id_max = max_travelid_draft.
ENDIF.
" Assigning travel id to entity whose travelid is still pending to create
LOOP AT entities_wo_travelid INTO entity.
travel_id_max += 1.
entity-TravelID = travel_id_max.
APPEND VALUE #( %cid = entity-%cid
%key = entity-%key
%is_draft = entity-%is_draft
) TO mapped-travel.
ENDLOOP.