verifyChkDigitMod11()

The system function SysLib.verifyChkDigitMod11 verifies a modulus-11 check digit in a character item that begins with a series of integers.

  SysLib.verifyChkDigitMod11(
    text anyChar in,
    checkLength SMALLINT in,
    result SMALLINT inOut)
text
A character item that begins with a series of integers. The item include an additional position for the check digit, which is immediately to the right of the other integers.
checkLength
An item that contains the number of characters that you want to use from the text 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 calculated check digit matches the value in text
  • 1, if the calculated check digit does not match that value

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.verifyChkDigitMod11 in a function-invocation statement; or as an item validator in a text form.

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.verifyChkDigitMod11 (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; but when the algorithm is complete, the calculated value is compared with the number at the check-digit position. The algorithm is described in relation to the example values:
  1. 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  
  2. 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 
  3. To get the check digit, subtract the remainder from 11 to get the self-checking digit:
      11 - 6 = 5

    If the remainder is 0 or 1, the check digit is 0.

In this example, the calculated check digit matches the value in the check-digit position, and the value of myResult is 0.

Feedback
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.