To find the verification digit for a given value.

Aravindh_NavisionAravindh_Navision Member Posts: 258
Hai Friends,

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

Logic for finding the Verification Digit:

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))
VeriDigit = 10 - (263 - (26 * 10))
VeriDigit = 10 - (263 - 260) = 10 - 3
VeriDigit = 7 (Answer)

Can anyone please help me in solving this in NAV?

Thanks in advance.

Comments

  • mohana_cse06mohana_cse06 Member Posts: 5,504
    Create a function and pass the Sum value and get return value as
    EXIT(Sum - (int(Sum/10) * 10))
    
  • Aravindh_NavisionAravindh_Navision Member Posts: 258
    Thanks Mohana. How to operate with the given 39 char length value? This contains 2 types of logic. How to proceed with the first one?
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    from where do you get that value? based on that you can calculate the first 4 steps..right?
  • Aravindh_NavisionAravindh_Navision Member Posts: 258
    Actually I am getting Ptxt_String value from the combination of few fields. Could you please correct where I am missing out the logic in the below lines of coding?

    Ptxt_String = 3070841326319000361243033388633240620117 (39 char)
    Ltxt_resultstring, Ltxt_resultstringO, Ptxt_String are text varialbles and others are integer variables
    CLEAR(LInt_total);
    CLEAR(LInt_totalO);
    CLEAR(LInt_TempInt);
    CLEAR(LInt_TempIntO);
    
    FOR a := 1 TO STRLEN(Ptxt_String) DO BEGIN
      EVALUATE(LInt_TempInt,COPYSTR(Ptxt_String,a,1));
      EVALUATE(LInt_TempIntO,COPYSTR(Ptxt_String,a,1));
      IF (a MOD 2) <> 0 THEN BEGIN
        LInt_TempInt *= 3;
        Ltxt_resultstring := Ltxt_resultstring + FORMAT(LInt_TempInt);
      END ELSE IF (a MOD 2) = 0 THEN BEGIN
        LInt_TempIntO *= 1;
        Ltxt_resultstringO := Ltxt_resultstringO + FORMAT(LInt_TempIntO);
      END;
    END;
    
    EVALUATE(LInt_TempInt,COPYSTR(Ptxt_String,STRLEN(Ptxt_String),1));
    EVALUATE(LInt_TempIntO,COPYSTR(Ptxt_String,STRLEN(Ptxt_String),1));
    Ltxt_resultstring := Ltxt_resultstring + FORMAT(LInt_TempInt);
    Ltxt_resultstringO := Ltxt_resultstringO + FORMAT(LInt_TempIntO);
    
    FOR a := 1 TO STRLEN(Ltxt_resultstring) DO BEGIN
      EVALUATE(LInt_TempInt,COPYSTR(Ltxt_resultstring,a,1));
      LInt_total += LInt_TempInt;
    END;
    
    FOR a := 1 TO STRLEN(Ltxt_resultstringO) DO BEGIN
      EVALUATE(LInt_TempIntO,COPYSTR(Ltxt_resultstringO,a,1));
      LInt_totalO += LInt_TempIntO;
    END;
    
    LInt_FinalTotal := LInt_total + LInt_totalO;
    
  • MBergerMBerger Member Posts: 413
    message('%1',strchecksum('307084132631900036124303338863324062011',
                             '313131313131313131313131313131313131313')) ;
    
    this returns your '7' :)
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    I need to find the verification digit to the following value: 3070841326319000361243033388633240620117 (Length - 39 char)
    STRLEN is 40 not 39 in above example
    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)
    [0, 0, 4, 3, 6, 1, 0, 0, 6, 2, 3, 3, 3, 8, 3, 2, 0, 2, 1,7]
    Here Sum is 54
    4. Sum = Mult + SumEven, (Sum = 216 + 47 = 263)
    Here Sum = 216 + 54 = 270
    [/quote]

    Try this code
    Ptxt_String := '3070841326319000361243033388633240620117';
    CLEAR(LInt_total);
    CLEAR(LInt_totalO);
    CLEAR(LInt_TempInt);
    CLEAR(LInt_TempIntO);
    
    FOR a := 1 TO STRLEN(Ptxt_String) DO BEGIN
      EVALUATE(LInt_TempInt,COPYSTR(Ptxt_String,a,1));
      EVALUATE(LInt_TempIntO,COPYSTR(Ptxt_String,a,1));
      IF (a MOD 2) <> 0 THEN BEGIN
        LInt_TempInt *= 3;
        Ltxt_resultstring := Ltxt_resultstring + LInt_TempInt;
      END ELSE 
      IF (a MOD 2) = 0 THEN BEGIN
        LInt_TempIntO *= 1;
        Ltxt_resultstringO := Ltxt_resultstringO + LInt_TempIntO;
      END;
    END;
    Message('%1',Ltxt_resultstring);
    Message('%1',Ltxt_resultstringO);
    
    LInt_FinalTotal := Ltxt_resultstringO + Ltxt_resultstring;
    Message('%1',LInt_FinalTotal);
    

    Where Ltxt_resultstring and Ltxt_resultstringO also integers..
  • Aravindh_NavisionAravindh_Navision Member Posts: 258
    Mohana,

    Sorry I missed to delete the last character in the given value. Yeah I will try with your code and let know about the result. Thanks you very much for your effort.

    MBerger,

    STRCHECKSUM function worked for me. Thank you very much. Let me try with Mohana's modified code too.


    Thanks.
Sign In or Register to comment.