sysLib.calculateChkDigitMod11
The system function sysLib.calculateChkDigitMod11 places a modulus-11 check digit in a character item that begins with a series of integers.
- input
- A character item that begins with a series of integers. The item must include an additional position for the check digit, which goes immediately to the right of the other integers.
- checkLength
- An item that contains the number of characters that you want to use from the input item, including the position used for the check digit. This item has 4 digits and is either of type SMALLINT or is of a type BIN, with no decimal places.
- result
- An item that receives one of two values:
- 0, if the check digit was created
- 1, if the check digit was not created
This item has 4 digits and is either of type SMALLINT or is of a type BIN, with no decimal places.
You can use sysLib.calculateChkDigitMod11 in a function-invocation statement.
Example
In the following example, myInput is an item of type CHAR and contains the value 56621869; myLength is an item of type SMALLINT and contains the value 8; and myResult is an item of type SMALLINT:
sysLib.verifyChkDigitMod (myInput, myLength, myResult);An algorithm is used to derive the modulus-11 check digit, and in all cases the number at the check-digit position is not considered. The algorithm is described in relation to the example values:
- Multiply the digit at the units position of the input number by 2, at the tens position by 3, at the hundreds position by 4, and so on, but let myLength – 1 be the largest number used as a multiplier; and if more digits are in the input number, begin the sequence again using 2 as a multiplier:
6 x 2 = 12 8 x 3 = 24 1 x 4 = 4 2 x 5 = 10 6 x 6 = 36 6 x 7 = 42 5 x 2 = 10- Add the products of the first step and divide the sum by 11:
(12 + 24 + 4 + 10 + 36 + 42 + 10) / 11 = 138 / 11 = 12 remainder 6- To get the check digit, subtract the remainder from 11 to get the self-checking digit:
11 - 6 = 5If the remainder is 0 or 1, the check digit is 0.
In this example, the original characters in myInput become these:
56621865