calculateChkDigitMod11()

The sysLib.calculateChkDigitMod11() system function places a modulus-11 check digit in a NUM variable or a character variable that begins with a series of numeric characters.

Syntax

  sysLib.calculateChkDigitMod11(
    text CHAR | NUM inOut,
    checkLength INT in,
    result SMALLINT inOut)
text
A NUM variable or a CHAR variable that begins with a series of numeric characters. The variable must include an additional position for the check digit, which is placed immediately to the right of the other characters. The initial characters (up to checkLength - 1) must be digits, or EGL throws a RuntimeException.
checkLength
An INT variable that contains the number of characters that you want to verify from the text parameter, including the position used for the check digit. For NUM variables passed as the text parameter, leading zeros count, so in most cases, checkLength will be equal to the length of the NUM variable.
result
A SMALLINT variable that receives one of two values:
  • 0, if the check digit was created
  • 1, if the check digit was not created

Example

The following example uses sysLib.calculateChkDigitMod11 to verify that an account number was transmitted accurately.

program CheckDigit11 type BasicProgram
  acctNo CHAR(10) = "56621869";   
  len SMALLINT = 8;
  result SMALLINT = 0;   
  
  function main()
    sysLib.calculateChkDigitMod11 (acctNo, len, result);
    if (result != 0)
      sysLib.writeStdout("Check digit not created");
    end
    sysLib.writeStdout(acctNo);
    // acctNo is 56621865
  end // main

end // program
EGL uses an algorithm to derive the modulus-11 check digit. In every case the number at the check-digit position is not considered. 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, with 7 as the largest number used as a multiplier. If there are more than 7 digits in the input number, begin the sequence again by 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 final acctNo contains the following characters:
  56621865

Compatibility considerations

Table 1. Compatibility considerations
Platform Issue
JavaScript generation The function sysLib.calculateChkDigitMod11() is not supported.

Feedback