CRN/CID Generator

asmilie2basmilie2b Member Posts: 122
edited 2014-05-19 in NAV Three Tier
We need to have NAV print a CID number generated from the document number. This is using algorithm MOD10 V01 or something compatible. I wonder if there are any resources available on doing this purely in C/AL if possible, or perhaps in .NET that anyone has encountered?

Bruce Anderson

Answers

  • asmilie2basmilie2b Member Posts: 122
    I did find this discussion here:
    viewtopic.php?f=23&t=48786&hilit=Luhn+algorithm

    However the calculation there was slightly different to what I need for the service I have to comply with, BPay.
    Below is the code i came up with. It accepts a string of the CRN to add a checksum, calculates and adds the checksums and then returns it.

    GenerateChecksum(CRN : Text) : Text
    
    
    CLEAR(TotalChars);
    CLEAR(TempInteger);
    
    // Find the sum of the multiplied digits
    FOR i := STRLEN(CRN) DOWNTO 1 DO BEGIN
      j += 1;
      EVALUATE(TempInteger,COPYSTR(CRN,i,1));
      IF (j MOD 2) <> 0 THEN BEGIN    // Only every 2nd character starting from very right
        CASE TempInteger OF
          1: TempInteger := 2;
          2: TempInteger := 4;
          3: TempInteger := 6;
          4: TempInteger := 8;
          5: TempInteger := 1;
          6: TempInteger := 3;
          7: TempInteger := 5;
          8: TempInteger := 7;
          9: TempInteger := 9;
        END;
      END;
      TotalChars += TempInteger;
    END;
    
    // Final calculations
    TempInteger := TotalChars MOD 10;
    TempInteger := 10 - TempInteger;
    CRN := CRN + FORMAT(TempInteger);
    
    EXIT(CRN);
    

    Bruce Anderson
Sign In or Register to comment.