SAP Number Range Shenanigans
The shenanigans of alphanumeric SAP Number Ranges are a surprise even to seasoned experts.
You’re likely well aquatinted with the mundane task of maintaining numeric number ranges for most business objects. The behavior is easily understood because the SAP system straightforwardly considers them as, well … numbers. Adding alpha characters to the mix is less common, and the resultant behavior is significantly less intuitive.
Let’s have a detailed look at the behavior of alpha characters in external number ranges, the published rules, and some technical details behind system behavior, perhaps with an eye towards breaking the strictest of rules once they’re understood.
As an example, I’ll use number ranges commonly configured for ERP Vendors that support SAP Retail Site Masters. The use case exposes interesting number range behaviors.
In SAP Retail, the Best Practice for Site Numbers is that the 4-character Site number, Site Business Partner number, Site ERP Customer number, and Site ERP Vendor number are all the same number. For this reason, 4-character number ranges are typically reserved for all those related objects for Site Masters. To that end, Site ERP Vendors may have external number ranges defined like this example:
While this number range configuration may be common, and necessary, it probably doesn’t have the exactly intended result! In the case of A to ZZZZ, the number range doesn’t satisfy the intention of reserving only 4-character numbers.
To illustrate the system behavior, let’s consider a real-world example: adding another external number range for 5-character numbers:
The Z3 number range VN000 to VN999 can’t be added because it overlaps.
To understand why, let’s begin with a quick look at the F1 help available when maintaining a number range.
The strict declared dependency is: “External intervals can only contain either letters or numbers, as sorting can differ between platforms (Code page).”
If we are to believe this admonition, then a number range such as VN000 to VN999 cannot be created simply because any mixture of letters and numbers is verboten, never mind any overlap error. Fortunately, the system is a bit more flexible than suggested by the Help screen.
But before breaking any rules, let’s understand how the system stores and evaluates number ranges that include letters.
Let’s use Vendor Number (LIFNR) to illustrate the example of storing numbers, with and without letters.
The system evaluates number range entries while number ranges are being maintained, and it separately evaluates number-range-relevant numbers – in the context of defined number ranges – when entered in a transaction, such as the entry of a Business Partner number during creation of a Business Partner.
The evaluation of the number is a comparison. For example, is the Business Partner number entry greater than the From Number of the number range, and is the Business Partner number entry less than the To Number of the number range. For example:
SAP ABAP Keyword Documentation explains that when the comparison type is one of the character-like data types, the content is compared from left to right. Based on the internal binary representation in the code page used, the first differing character from the left determines which operand is greater.
Data Element LIFNR, for example, is defined as 10 characters, and all 10 characters are evaluated, beginning from left to right, until a differing character is determined.
The number range A to ZZZZ is evaluated as “A “ (1 character and 9 trailing spaces) to “ZZZZ “ (4 characters and 6 trailing spaces).
The number range A to ZZZZ isn’t a 4-character number range after all; it won’t constrain entries to 4 characters!
Numbers are “smaller” than letters.
This is demonstrated as A to 1 results in an error:
This is also demonstrated as 1 to A is a valid range:
Only external ranges permit non-numeric characters.
This is demonstrated as A to ZZZZ for an internal number range results in an error:
Alpha ranges include numbers.
These number ranges are typically maintained for Sites.
Z1 permits numeric only Site Vendor numbers from 1 to 9999.
But consider example Range Z2: A to ZZZZ.
Because numbers are “smaller” than letters, Range Z2 (A to ZZZZ) achieves the following scenario:
- Must begin with a letter (From Number is A, thus a number is not permitted as the first character).
- Numbers are allowed following the first character (To Number is ZZZZ, and R123 is permitted because 123 is “smaller” than ZZZ).
To illustrate, let’s create a Vendor:
And Vendor number R123 is a permitted value:
Because numbers are “smaller” than letters, Range Z2 (A to ZZZZ) permits numbers following the first character.
Because numbers are “smaller” than letters, it is not possible to define a strictly alpha range that spans multiple characters (e.g. 2 or more alpha characters).
Alpha ranges include spaces.
If you have a number range like Range Z2 (A to ZZZZ), you can still create master data with a number such as R123456789.
If you have a number range like Range Z2 (A to ZZZZ), you probably did not mean to permit R123456789. But you did!
The reason for this is simply technical: This interval (A – ZZZZ) is understood by the system like this:
[A ] – [ZZZZ ]
(note the spaces after the characters).
SAP stores number ranges in ten characters and if you don’t use all ten characters, then SAP thinks there are spaces there (which is technically true) and unexpected things could happen.
00000P1000 – 00000P9999
P000001000 – P000009999