calculateChkDigitMod10()

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

Syntax

  sysLib.calculateChkDigitMod10(
    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 goes 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

program CheckDigit10 type BasicProgram
	acctNo CHAR(10) = "1734289";   
	len SMALLINT = 7;
	result SMALLINT = 0;   
  
	function main()
		sysLib.calculateChkDigitMod10 (acctNo, len, result);
		if (result != 0)
			sysLib.writeStdout("Check digit not created");
		end
		sysLib.writeStdout(acctNo);
    // acctNo is now 1734284
	end // main
		
end // program
An algorithm is used to derive the modulus-10 check digit, and 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 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
  2. Add the digits of the products (1,6,8,1,4) to the input-number digits (1,3,2) that were not multiplied by 2:
      1 + 6 + 8 + 1 + 4 + 1 + 3 + 2 = 26   
  3. To get the check digit, subtract the sum from the next-highest number ending in 0:
      30 - 26 = 4

    If the subtraction yields 10, the check digit is 0.

In this example, the function changes the original characters in acctNo to the following characters:
  1734284

Compatibility considerations

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

Feedback