- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.6K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 115 Navision DOS
- 854 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 615 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 296 Dynamics CRM
- 109 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 993 SQL General
- 384 SQL Performance
- 34 SQL Tips & Tricks
- 34 Design Patterns (General & Best Practices)
- Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.7K General
- 1.1K General Chat
- 1.6K Website
- 79 Testing
- 1.2K Download section
- 23 How Tos section
- 259 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions

Aravindh_Navision
Member Posts: **258**

Hi Friends,

Does anyone worked in Luhn algorithm or Luhn formula, also known as the "modulus 10" or "mod 10" algorithm (in Navision)?

Luhn algorithm is a simple checksum formula used to validate a variety of identification numbers, such as credit card numbers, barcodes etc., Also see this link: http://en.wikipedia.org/wiki/Modulus_10

Am totally blank about this. Can anyone please provide me with how to handle this in Navision or with links which addresses this topic?

Thanks,

Aravindh

Does anyone worked in Luhn algorithm or Luhn formula, also known as the "modulus 10" or "mod 10" algorithm (in Navision)?

Luhn algorithm is a simple checksum formula used to validate a variety of identification numbers, such as credit card numbers, barcodes etc., Also see this link: http://en.wikipedia.org/wiki/Modulus_10

Am totally blank about this. Can anyone please provide me with how to handle this in Navision or with links which addresses this topic?

Thanks,

Aravindh

0

## Comments

90Ltxt_resultstring is also a text, all the other variables are integers.

413901,136The following example is from Wikipedia The sum calculated by STRCHECKSUM was 82 and therefore the check digit 8. This is because STCHECKSUM includes 18 and 16 in its sum. The Lunh algorithm, however sums up their cross sum, so adds up 1+8=9 and 1+6=7 instead.

geronimo's Code assumes an odd number of digits in it's Ptxt_String parameter to work correctly.

901,136geronimo's code starts from the left.

Therefore it matters whether you have an even or odd number of digits to evaluate.

The code may easily be anhanced, though.

90ah i must have read past that part it is indeed fairly easy to adapt the code however

258Thank you guys for joining in this discussion and providing solutions and your ideas. It was useful. The client had changed the logic now which is given below.

I need to find the verification digit to the following value: 3070841326319000361243033388633240620117 (Length - 39 char)

1. Sum odd positions [3, 7, 8, 1, 2, 3, 9, 0, 3, 1, 4, 0, 3, 8, 6, 3, 4, 6, 0, 1]. (SumOdd = 72)

2. Multiply SumOdd * 3. (Mult = 72 * 3 = 216)

3. Sum even positions [0, 0, 4, 3, 6, 1, 0, 0, 6, 2, 3, 3, 3, 8, 3, 2, 0, 2, 1]. (SumEven = 47)

4. Sum = Mult + SumEven, (Sum = 216 + 47 = 263)

5. Verification digit 7. (We need to add the integer value 7 to 263 so the nearest higher value which should divisible by 10 and the remainder remains 0.)

To find the lowest number (verification digit)...:

VeriDigit = 10 - (Sum - (int(Sum/10) * 10))

VeriDigit = 10 - (263 -(int(263/10) * 10))

= 10 - (263 - (26 * 10))

= 10 - (263 - 260) = 10 - 3

VeriDigit = 7

Can anyone please help me in solving this?

Thanks in advance,

Aravindh

9Please find my solution for NAV C/AL in the following post >> https://forum.mibuso.com/discussion/77912/luhn-algorithm-modulus-10-in-dynamics-nav-c-al-code-creating-a-check-digit/p1?new=1

This can easily be converted to work in Business Central AL code

9Hello Aravindh,

Here is my take on a solution for your problem. It is similar to the solution I posted earlier.

I was initially confused by the results but I realized I had to take the last digit out of the number before putting it into the algorithm

But I must ask why the sum of odd numbers is multiplied by 3 specifically and is it always 3?

Anyways, here is the code below:

Variables:

Name DataType Subtype Length

i Integer

LengthOfDigit Integer

CodeCharacter Code 250

Product BigInteger

SumProduct BigInteger

SingleDigit Integer

SumOfOddNumbers Integer

SumOfEvenNumbers Integer