This is a test message to test the length of the message box.
Login
|
ABAP RAP Numbering
Created by Software-Heroes

RAP - Numbering

8030

In this article we will take a look at automatic number assignment and how we can assign numbers ourselves in the case of the partner app.

Advertising


When we worked with the previous app, we always had to assign a number to new data sets ourselves. Here, however, the RAP object should assign the number itself and leave us, the user, alone.

 

Scenarios

There are three different scenarios for assigning numbers in RAP, which are also intended for different purposes:

  • Early numbering (external) - This variant was already used by us in the old app, the user is responsible for assigning the primary key himself. The validation only checks for duplicate keys and whether the key has been filled.
  • Early numbering (internal) - In this variant, the key field usually consists of a UUID and the unique ID is assigned via the RAP framework. A uniqueness check is no longer necessary since the UUID is always unique.
  • Late numbering - The late number assignment only occurs in the storage sequence of the framework, just before the data is written to the database. At this point you can assign a number by number range or assign the key in another way.

 

The assignment of the number can be particularly important when it comes to complete receipts or numbering. A document that does not leave the draft status or is deleted again would create a gap in the document numbers, which is not possible from a business point of view.

 

Early numbering (internal)

There are two forms of this form of number assignment, one variant via the automatic assignment of a UUID and the second variant with the manual assignment of a number. In the first variant, the "numbering" attribute is defined in the corresponding field. This tells RAP that an automatic UIUD should be assigned here.

field ( numbering : managed ) FieldName;

 

For internal assignment by method, the addition "early numbering" must be used in the behavior definition of the object. The "FOR NUMBERING" method must then be implemented. There you have the possibility to implement a number assignment with coding. This variation is similar to the late number assignment example below.

 

Late numbering

To implement late numbering, the behavior definition for the object must include the addition "late numbering". At the same time, the key field should be set to read-only, as the user will no longer be able to enter any data there. Here is an excerpt from the behavior definition:

managed implementation in class zbp_bs_demo_rappartner unique;
strict;

define behavior for ZBS_I_RAPPartner alias Partner
persistent table zbs_dmo_partner
lock master
authorization master ( instance )
late numbering
{
  create;
  update;
  delete;

  field ( readonly ) PartnerNumber;

  mapping for zbs_dmo_partner
  {
    PartnerNumber = partner;
    PartnerName = name;
    Street = street;
    City = city;
    Country = country;
    PaymentCurrency = payment_currency;
  }
}

 

The compiler then tells us that we still have to generate the implementation, which is done automatically with CTRL + 1. The empty implementation is created in the memory sequence and not in the behavior implementation as before. The "ADJUST_NUMBERS" method can now be filled:

CLASS lsc_zbs_i_rappartner DEFINITION INHERITING FROM cl_abap_behavior_saver.
  PROTECTED SECTION.
    METHODS adjust_numbers REDEFINITION.
ENDCLASS.


CLASS lsc_zbs_i_rappartner IMPLEMENTATION.
  METHOD adjust_numbers.
  ENDMETHOD.
ENDCLASS.

 

We use a very simple logic for the number assignment, in which we determine the maximum number and then increase it for all new data records:

SELECT FROM zbs_dmo_partner
  FIELDS MAX( partner )
  INTO @DATA(ld_max_partner).

LOOP AT mapped-partner REFERENCE INTO DATA(lr_partner).
  ld_max_partner += 1.
  lr_partner->PartnerNumber = ld_max_partner.
ENDLOOP.

 

Test

Before we can start testing, we need to comment out the implementation of the validateKeyIsFilled method. The key is no longer assigned externally, but only in the storage sequence. Because validation is called before the sequence, validation would hinder the save operation. Let's take a look at the largest partner number:

 

With "Create" we create an empty data record and also see that the partner number is blocked, manual entry as before is not possible.

 

After the fields have been filled, we can click on the "Save" button, the fields will be locked and the new record will be presented. The number has been assigned and can be seen in the detail image.

 

Conclusion

As you can see, the implementation of the automatic number assignment is not rocket science and only requires a few small steps. When designing the RAP business objects, you should think about what type of keys you want to use. No matter whether UUID or number range, the automatic assignment takes a lot of work.


Included topics:
RAPBTPNumberingREX1
Comments (7)



And further ...

Are you satisfied with the content of the article? We post new content in the ABAP area every Tuesday and Friday and irregularly in all other areas. Take a look at our tools and apps, we provide them free of charge.


057: Fix my RAP Application with AI

Category - YouTube

How can AI actually help us find and correct errors in our RAP application? Let's look at the new features in the MCP Server and configure the IDE to find the error.

11/16/2026

BTP - Connect Email via OAuth 2.0

Category - ABAP

Email integration via Basic Auth no longer works. What alternative options are available for connecting Office 365 to the ABAP environment and how can you configure them?

10/13/2026

RAP - Sales App Learnings

Category - ABAP

The tutorial for the Sales App has come to an end, and this time a wide range of topics and areas were covered. In this article, we'll review what we learned and highlight some key points.

09/08/2026

052: 10 Minutes from Start to Launchpad

Category - YouTube

In this episode, we'll look at how we can create a RAP application within 10 minutes, generate and deploy it, and finally launch it in the Launchpad.

09/07/2026

RAP - Navigation (App to App)

Category - ABAP

How can you navigate to another application within your Fiori application without the user having to manually switch apps? Let's take a look at navigation between Fiori apps.

09/01/2026