Start of Content Area

Background documentation How the Number Range Buffer Works  Locate the document in its SAP Library structure

The number range buffer is part of the SAP kernel. It creates shared memory on each application server, which all work processes can access. 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

·        The main memory buffer is activated for the number range object.

·        The parameter IGNORE_BUFFER is not set.

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.

Caution

If there is a rollback, it creates a gap in the document numbers. Applications that do not want any gaps (or not allowed gaps for legal reasons) should not use the number range 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).

Note

If you want, you can specify a different server in the profile parameter nobuf/server.

The graphic below shows the process flow and the components involved.

This graphic is explained in the accompanying text

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. For this time period WP1 is assigned status stop in the Work Process Overview (SM50) with reason for stopping, NUM. Under detail info for WP2 you can see which number range interval the work process wants to assign numbers to.

Before WP2 issues numbers to the first 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).

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 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.

Note

Up to Release 4.6 this semaphore had always been set if a number was assigned from one of the intervals entered.

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.

Example

In this example the buffer is empty (Status is Buffer to No.) ; the buffer has to be filled through the number range server.

When the number range server is accessed a red entry appears for a very short time in SM56 (see Administration of the Number Range Buffer. The number range buffer cannot distribute a number to a work process, because another process is accessing the number range server at the same time.

 

This graphic is explained in the accompanying text

 

End of Content Area