If there is reprint please indicate the source: http://blog.csdn.net/donkey2004112103/archive/2009/04/13/4070996.aspx
1. SAP numbe range used in standard programs
I have never understood how sap serial numbers are continuous. I thought it was a simple global variable. Although the form is similar, sap has a dedicated tcode and method, it can ensure that the number is not repeated and only within a certain range. Even the number is re-numbered every year, such as the number of Accounting creden。. A reminder is sent when the number reaches a certain level.
2. How to create your own
Tcode: snro. You can create one by yourself.
Short text and long textSpecifies the number range object. Enter any description.
Sub-Object Data ElementWe do not fill in here. The so-called sub-objects refer to an organizational structure, such as company code, sales organization, and factory. In this way, the numbers are numbered separately under each organization, the most typical example is financial creden. The financial creden。 under each company code are numbered independently (the corresponding data table bkpf must also use the company code as a key field ). The scheduling order corresponds to the sales order, and the sales order is not numbered separately according to the organization level. Therefore, the corresponding scheduling order is not required.
Expiration year markIndicates that the number is set to zero by year. When a new year starts, the corresponding number also needs to start from the beginning. For example, both the financial creden and material creden( are like this (for example, table bkpf and mkpf, the year is used as a key field), and the scheduling order does not need to correspond to the year, so it is not checked here.
Number length fieldFill in the created domain, but be sure to activate it first. Specify the length of the zdiaodudan object in the serial number range. We define the length of the field as 10. Therefore, the serial number generated by the serial number range object is also 10 characters.
No tumble IntervalIndicates whether to automatically start from the beginning if the number reaches the maximum. If it is checked, an error is prompted when the number is obtained. We should check it here.
Number range ProcessingIs a translation problem. It is actually a transaction code within the serial number range. If this transaction code is specified, you do not need to maintain the serial number range through the snum or snro Main Screen and enter the name of the serial number range object. Instead, you can enter the transaction code to directly enter the serial number range maintenance screen.
Warning PercentageIf the serial number is used in a certain proportion, a system warning is issued, prompting the Administrator to increase the range or archive historical data to avoid affecting normal business after the serial number is used up. Here we enter 95, the prompt is displayed at 95%.
Primary memory bufferThis means that the system extracts numbers in advance on the application server to improve the performance. When the program uses the numbers, it directly obtains them from the application server without reading the database. In general, this method can be used if the number continuity requirements are not high, and if the financial creden and other requirements require continuous numbers, the primary memory buffer should be disabled, you can choose "edit-set cache-no cache" from the menu ".
Then you can
Specify the number range in the interval.
3. How to Use
In the program, we can also use number range. Use three functions. The following is a description.
Call function'Number_range_enqueue'
Exporting
Object = 'zsddnr'
Exceptions
Foreign_lock = 1
Object_not_found = 2
System_failure = 3
Others = 4.
* ** If the number range exists
If sy-subrc EQ 0.
* *** Get a number,
Call function'Number_get_next'
Exporting
Nr_range_nr = '01'
Object = 'zsddnr'
Importing
Number = l_seqno
* Quantity = quant
* Returncode = Code
Exceptions
Interval_not_found = 1
Number_range_not_intern = 2
Object_not_found = 3
Quantity_is_0 = 4
Quantity_is_not_1 = 5
Interval_overflow = 6
Buffer_overflow = 7
Others = 8.
* *** Accumulate the number
Call function'Number_range_dequeue'
Exporting
Object = 'zsddnr'
Exceptions
Object_not_found = 1
Others = 2.
Else.
Raise num_range_error.
Endif.
It is easy to understand. First, determine whether this number range exists. If so, obtain the next sequence number. The last function I estimate means to release the memory of this global variable. 'Zsddnr' is the number range we created. In this way, the serial number can be automatically generated every time like the accounting credential number! The serial number can be used as the primary key in the self-built table, and its generation depends on the above function.