How the Number Range Buffer Works
Use
The number range buffer is part of the SAP kernel. On each application server the number range buffer creates a shared memory that all work processes can access.
Prerequisites
The system can assign a number from the buffer, provided the following conditions are satisfied:
-
You want to assign one number to one object using the function module NUMBER_GET_NEXT.
-
Parameter IGNORE_BUFFER of function module is not set.
-
The main memory buffer is activated for the number range object.
Process
The number range buffer proceeds as follows:
It checks whether it already has an area in the buffer for the number range interval required and whether this area is not yet full. If both conditions are satisfied, the current number level in the buffer is increased by the required number and the caller notified of the assigned numbers. Immediately afterwards a new process can assign a number from the same interval. If there is a rollback, the numbers are lost -they are not returned to the buffer.
If the number range interval you want is not in the buffer or the number stock is exhausted, the number range buffer must fetch new numbers from table NRIV in the database. The mechanism used is called number range server. For technical reasons a second work process ( WP2) is required for this. This usually runs on the same server as the process that is wanting to assign a number ( WP1).
WP1 instructs a second process ( WP2) to fetch from table NRIV in the database as many numbers as are configured in the number range object maintenance ( SNRO) under No. of Numbers in Buffer. During this time span WP1 has the statusden Zustand On Hold in the Work Process Overview ( SM50) with the reason for stopping NUM. With WP2 you can view Detailed Information about which number range interval it wants to assign numbers to on the database.
Before WP2 issues numbers to the WP1 work process, the assigned numbers are immediately written to the database ( COMMIT). This has the disadvantage that all the buffered numbers from the interval are lost if the server shuts down. This may lead to large gaps in the area assigned to the assigned document numbers (in the order of total number of numbers in the buffer for each active server).
The graphic below shows the process flow and the components involved.
Access Protection
Like all memory areas that several processes can access, there must be a mechanism to prevent more than one process accessing the memory at the same time. A two-level mechanism is in place here to prevent simultaneous access:
-
If you want to assign a number to a buffer entry, this entry is blocked by an internal lock. This lock ensures that only one user can ever assign a number at any one time. The lock is released as soon as the number is assigned. Usually the number assignment does not take longer than 50 microseconds.
The lock is also held if the numbers for this entry have all been assigned and new ones have to be assigned in the database through the number range server. The lock remains in place for the duration of the database activity. When this lock is set, you can identify it in transaction SM56 in the overview of the buffer entries.
-
If entries are added to or deleted from the buffer, a global semaphore is set (semaphore 8). If this semaphore remains locked for a long time (>1 minute) in the process overview, this indicates a problem with the buffer. This may mean the affected server or even the entire system has to be shut down.
If the number range buffer is configured so that it only contains one number, the procedure is different. For more information see One Number in the Buffer.