How To Generate A Check Digit
This document explains how to generate a Check Digit
using Collect!'s report writer. Collect! uses the LUHN
code algorithm when generating the check digit.
Familiarity with Collect!'s report writer and with using
loops in report is required. The database field you are
using must contain only numeric data for this to work.
When your bank supplies you with a bill payer code,
debtors can make payments at post offices, bank
branches, through the Internet or through phone banking
outlets. The bank requires that you provide them with a
unique " client reference number" with a "Check Digit"
to ensure accuracy and integrity of client data.
This Check Digit can be generated in Collect! with the
simple addition of a formatting code to any field containing
strictly numeric data.
Please make sure the field that you are using
to generate the check digit has valid information in it.
Check Digit Report Code
To generate a check digit add <cd>
to the number field you are using. This tells the report
system to append a space and the Check Digit.
To output the Check Digit only, <cdc>
to the number field you are using.
Example 1:
This will create a Check Digit using the client account
number, 18-77564.
@de.ac<cd>
Output: 18-77564 0
Example 2:
This will output the Check Digit only using the client
account number, 18-77564.
@de.ac<cdc>
Ouptut: 0
Example 3:
This loop prints the file number and the account number
with a space and the Check Digit, regardless of input.
@de max=10
@de.fi @de.ac<cd>
@de
The function will not process garbage account
numbers. Any non-numeric character in the account number
will cause a zero to be output as the Check Digit, regardless
of input. So make sure your account numbers are valid and
strictly numeric.
Check Digit No Space
To generate a Check Digit without a space
add <cdn> to the number field
you are using. This tells the report system append the
Check Digit without a space.
Example:
This will create a Check Digit using the client account
number, as above, but without appending a space first.
@de.ac<cdn>
Output: 18-775640
The function will not process garbage account
numbers. Any non-numeric character in the account number
will cause a zero to be output as the Check Digitt, regardless
of input. So make sure your account numbers are valid and
strictly numeric.
Check Digit 97
The Australian Post Office Modulus 97 Check Digit can be
obtained by using <cd97>
or <cd97c>.
Examples:
@de.ac<cd97>
@de.ac<cd97c>
<cd97> produces the input string,
a space and the Check Digit.
Ex: 18-77564 80
<cd97c> produces the Check Digit only.
Ex: 80
We use the following weights to support up to 19 digit numbers:
3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71
Check Digit 2097
The Australian Post Office Modulus 97 - 20 weight Check Digit
can be obtained by using <cd2097>
or <cd2097c>.
We use the following weights to support up to 20 digit numbers:
20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1
Examples:
@de.ac<cd2097>
@de.ac<cd2097c>
<cd2097> produces the input string,
a space and the Check Digit.
Ex: 18-77564 65
<cd2097c> produces the Check Digit only.
Ex: 65
If the check digit is less than 10, it will be zero padded.
Examples:
@de.fi<cd2097> for File 1400 outputs 1400 01
@de.fi<cd2097c> for File 1400 outputs 01
Strip Check Digit
The following commands output the same formats as
above, but the incoming data is stripped of non-numerics
before the check digit calculations are performed. This
actually results in a different check digit being generated.
Example 1:
This will create a Check Digit using the client account
number, 18-77564, automatically stripped to 1877564
before calculating the check digit.
@de.ac<cds>
Output: 1877564 3
Example 2:
This will output the Check Digit only using the client
account number, 18-77564, automatically stripped
to 1877564 before calculating the check digit.
@de.ac<cdcs>
Ouptut: 3
Example 3:
This will generate a Check Digit without a space
using the client account number, 18-77564,
automatically stripped to 1877564 before calculating
the check digit.
@de.ac<cdns>
Output: 18775643
Creating Reports Using Check Digit
Using the loop structure as shown above, in Example 2, you
can create your own reports, looping through which ever records
you need, to access the field you will be using to generate the
check digit.
For example:
Report Name: My Report
Start On: Anywhere
@de max=10
@de.fi @de.ac<cdn>
@de
Printing Check Digit To Spreadsheet
When printed to a spreadsheet, the second example above
results in the file number in one column and the account
number plus its check digit in the second column.
Assigning Check Digit To A Variable
You can also assign a check digit formatted printable
information field to a variable. This works for any
printable information field that prints as a check digit.
Any of the check digit operators may be used.
Example:
@varStr* = @de.ac<cdns>
If the client account number is 18-77564, then @varStr
now holds '18775643'.
Check Digit Algorithm
This is how Collect! generates the check digit, using the LUHN
formula algorithm.
Initialization:
1. Set weighting factor to 1.
2. Set cumulative sum to 0.
3. Verify the input data is all numeric, return 0 if alpha
found.
4. Reverse the input string.
Processing:
Start with first digit in the string (that's the least significant digit.)
For each digit:
1. Multiply the digit by the weighting
factor + 1 (i.e. the least significant digit has a weighting factor
of 2.)
2. If the result of the previous multiplication is greater than 9
then subtract 9 from the result.
3. Add the result from step 2 to the cumulative sum.
4. Exclusive Or the weighting factor (i.e. if it is 1, make it 0,
and if it is 0 make it 1.)
5. Select the next more significant digit in the input string.
6. Go to Processing Step 1 unless there are no digits left to
process.
Summary Calculation:
The cumulative total now contains the sum of all digits
multiplied by the appropriate weighting factor based on
the digit position with respect to the least significant digit.
1. Take the remainder of the cumulative
total divided by 10 (i.e. total modulo 10 - this number
therefore ranges between 0 and 9.)
2. Subtract the result of step 1 from 10.
3. If the result is 10, then make the result 0.
Completion:
Return the result.
Summary
This is an efficient and easy way to use the report writer
to generate a unique reference number.
See Also
- Report Sample to view all the sample reports and letters
- Report Topics Index to view a list of all report topics
|
Was this page helpful? Do you have any comments on this document? Can we make it better? If so how may we improve this page.
Please click this link to send us your comments: helpinfo@collect.org