13. Dezember 2006 13:47
13. Dezember 2006 14:09
STRCHECKSUM (String)
Use this function to calculate a checksum for a string containing a number.
CheckNumber :=STRCHECKSUM(String [, WeightString] [, Modulus])
String
Data type: text constant or code
This string contains the number for which you want to calculate a checksum. You can only enter the numeric characters 0-9 in this string. Entering anything else will cause a run-time error.
WeightString
Data type: text constant or code
This string contains numbers you want the system to use as weights when calculating the checksum. The default value is a string containing STRLEN(String) '1'-characters.
You can only enter the numeric characters 0-9 in this string. Entering anything else will cause a run-time error.
If String is longer than WeightString, the system will concatenate a string containing STRLEN(String) - STRLEN(WeightString) '1'-characters to the end of WeightString. If WeightString is longer than String, a run-time error occurs.
Modulus
Data type: integer
The number you want to use in the checksum formula (see below). The default value is 10.
CheckNumber
Data type: integer
The checksum, which the system calculates using this formula:
where n = STRLEN(String).
Example
These examples show how to use the STRCHECKSUM function.
Calculating a checksum:
StrNumber := '4378';
Weight := '1234';
Modulus := 7;
CheckSum := STRCHECKSUM(StrNumber, Weight, Modulus);
MESSAGE(Text000 + Text001, StrNumber, CheckSum);
Create the following text constants in the C/AL Globals window:
Text Constant
ENU Value
Text000
'The number: %1\'
Text001
'has the checksum: %2'
STRCHECKSUM('4378','1234', 7) returns:
(7 - (4x1 + 3x2 + 7x3 + 8x4) MOD 7) MOD 7 = 0
The message window shows:
The number: 4378
has the checksum: 0
Calculating a modulus 10 checksum for a bar code:
The STRCHECKSUM function can be used to calculate checksums for 13- and 8-digit EAN (European Article Number) and EAN compatible bar codes such as UPC (Universal Product Code) or JAN (Japanese Article Number).
A 13-digit EAN code has this format:
The system uses the 12 digits in positions 13 to 2 to calculate the checksum at position 1.
Starting with position 2, the system totals all even values. It then multiplies the result by three. This value is called Even.
Starting with position 3, the system totals all odd values. The result is called Odd.
Total = Even + Odd.
The modulus 10 checksum is then: (10 - Total MOD 10) MOD 10.
Here's how to use STRCHECKSUM to calculate this result:
StrNumber := '577622135746';
Weight := '131313131313';
CheckSum := STRCHECKSUM(StrNumber, Weight);
MESSAGE(Text000 + Text001, StrNumber, CheckSum);
Create the following text constants in the C/AL Globals window:
Text Constant
ENU Value
Text000
'The EAN code: %1\'
Text001
'has the checksum: %2'
The message window shows:
The EAN code: 577622135746
has the checksum: 3
13. Dezember 2006 14:09
13. Dezember 2006 14:16
// Verify modul 10 rec. check digit and return it
IF DELCHR(_Input,'=','01234567890') <> '' THEN
ERROR(Text004,_Input);
Tabl[ 1] := 0;
Tabl[ 2] := 9;
Tabl[ 3] := 4;
Tabl[ 4] := 6;
Tabl[ 5] := 8;
Tabl[ 6] := 2;
Tabl[ 7] := 7;
Tabl[ 8] := 1;
Tabl[ 9] := 3;
Tabl[10] := 5;
Carry := 0;
Maxlength := STRLEN(_Input);
Pos := 1;
WHILE Pos < Maxlength + 1 DO BEGIN
EVALUATE(Test,COPYSTR(_Input,Pos,1)); // get 1 testnbr from string
i := Test + Carry; // add carried to testchar
IF i > 9 THEN
i := i - 10;
Carry := Tabl[i+1]; // get new carry from table
Pos := Pos + 1; // set pointer to next char
END;
IF Carry = 0 THEN
Carry := 10; // adjust carry if 0
_Output := FORMAT(10 - Carry); // calc checkdig. from carry
13. Dezember 2006 14:17
13. Dezember 2006 14:21
13. Dezember 2006 14:50
Natalie hat geschrieben:Was ist denn eine Modulomethode? Und wofür brauchst du das? *OchsvormBerg*