Mod10 Formula for Crystal Reports


Modulo 10 algorithm is used to calculate check digit on a number of data types, such as UPC-A, EAN-13, SCC-14/GTIN, SSCC-18, EAN-8, BLN and etc. Users can use the free online utility UPC/EAN/SSCC/ISBN check digit calculator to get the check digit. The source code for many programming languages can be found at KB10011.

Unfortunately, this function is not included in the Crystal Reports UFL for linear barcode fonts package. When using Crystal Reports to create GS1-128 barcodes, such as SSCC-18, users may require such a function to get the correct human readable, because the text provided by the font does not comply to the GS1 requirement.

Mod10 Function

To add the function into your report so that you can call in in your formula field, first select Formula Workshop from Report. In Formula Workshop, right click on the node Report Custom Functions and select New. Give a name mod10 and press Use Editor button.

In the Custom Function Editor, make sure that Crystal Syntax is selected for the grammar, and paste the content below:

Function (StringVar input_number)

input_number := replace(input_number, " ", "");

numbervar i := length(input_number);
numbervar sum_val := 0;

stringvar position := "odd";

do (
    if position = "odd" then (
        sum_val := sum_val + 3*tonumber(input_number[i]);
        position := "even" )
    else (
        sum_val := sum_val + tonumber(input_number[i]);
        position := "odd" )

    i := i-1
)  while i > 0;

numbervar remainder_val := Remainder(sum_val, 10);

numbervar check_digit := if remainder_val = 0 then 0 else (10-remainder_val) ;

input_number + ToText(check_digit, 0)

Save the function and close the editor. The function is ready to use.

Use mod10 function in the report

After the function is defined, you can use it in your formula field. In our case, we created a field called sscc18. We like the human readable text to divide into 5 parts: GS1 AI 00, extension digit, company prefix, serial number and check digit. We use the code as below. Note that GS1 company prefix has a variable length, and your prefix assigned may be longer than 7 digits shown in this example.

StringVar sscc_number := mod10("00718908562723189");

// use Mid function to get substring
"(00)" + " " + Mid(sscc_number, 1, 1) + " " + Mid(sscc_number, 2, 7) + " " +
Mid(sscc_number, 9, 9) + " " + Mid(sscc_number, 18, 1)

Drag the field to the report, and format it with appropriate font, and we get the human readable text shown up:


To create the SSCC-18 barcode, you need Code128 Fonts and call SSCC18 encoder function in Crystal Reports. See KB10023 for details.

Sample Report

To download a sample report file, click here. Crystal Reports 9 or above is required to open this file.