What is Numbering characteristic in ABAP RAP?

It’s important to understand how numbering plays a crucial role in the ABAP RAP (RESTful Application Programming Model). Numbering helps in managing unique identifiers for business objects, ensuring consistency and enabling smooth transaction processing. Depending on your business requirements, you may need the number to be assigned at different points in the lifecycle of the object—either right when the object is created or only after it has been persisted. Let’s explore the two types of numbering: early numbering and late numbering
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 dive into learning how to implement early numbering in ABAP RAP (RESTful Application Programming model) in a more detailed way. We will explore the necessary steps, concepts, and techniques required to properly manage and generate early numbering in an ABAP-based RAP application. Your Attractive Heading
We need to use keyword early numbering while writing in behavior definition(ZR_RAPTECH_TRAVEL) as shown in the below image, its important to note that all primary key should be part of read only field. This make sure the key will not get updated
Press CRLT + SHIFT + 1 → for Quick fix, double click on add method will automatically add earlynumbering_create method in your implementing class.
The above image is showing importing and changing parameter for this method.
Let’s understand the signature of Numbering
Signature of the FOR NUMBERING method for managed BOs:
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.
You can implement your own logic for early numbering. Below, I’ll demonstrate how to automatically set the Travel ID when creating new records. Please refer to the code below to get a better understanding of early numbering.
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.
For entity data whose travelid is still initial, we have to assign some travedid based on own set of logic. Before this, we have to exclude list of data whose travelid is already present by simply stamping it back to mapped-travel
  " 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.
We are currently checking travel table and finding what was the last number which was consumed for as part of Travel Id and simply inserting with next Travel ID. It’s important to append new record in mapped-travel. Save and Activate you code and run you fiori application.
Output :
Click on Create Button
Travel Id 11 automatically generated and its not editable
“Hooray! We have successfully learned numbering characteristic in ABAP RAP and implemented early numbering.”

Leave a Comment

Your email address will not be published. Required fields are marked *