sysLib.calculateChkDigitMod10
The system function sysLib.calculateChkDigitMod10 places a modulus-10 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.calculateChkDigitMod10 in a function-invocation statement.
Example
In the following example, myInput is an item of type CHAR and contains the value 1734289; myLength is an item of type SMALLINT and contains the value 7; and myResult is an item of type SMALLINT:
sysLib.verifyChkDigitMod10 (myInput, myLength, myResult);An algorithm is used to derive the modulus-10 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 units position of the input number by 2 and multiply every alternate position, moving right to left, by 2:
8 x 2 = 16 4 x 2 = 8 7 x 2 = 14- Add the digits of the products (16814) to the input-number digits (132) that were not multiplied by 2:
1 + 6 + 8 + 1 + 4 + 1 + 3 + 2 = 26- To get the check digit, subtract the sum from the next-highest number ending in 0:
30 - 26 = 4If the subtraction yields 10, the check digit is 0.
In this example, the original characters in myInput become these:
1734284