Has anyone built a compute or define for
calculating a Modulus 10 check digit on a variable length number? If so, I would be very grateful if you could share this with me?This message has been edited. Last edited by: Kerry,
I think someone here did it, but did it by calling an OS command.
Take a look at the function IMOD
I think that will do what you need
There are many different formulae for calculating a Modulus 10 check digit.
You can add all the digits and find the remainder when dividing by 10.
You can have different multipliers for each digit.
You can take the complement for the check digit calculated in one of the above examples.
So, which is yours?
In Focus since 1982
wf 8.202M/Win10/IIS/SSA - WrapApp Front End for WF
The following focexec...
-* File TheModSquad.fex APP PREPENDPATH IBISAMP -* DEFINE FUNCTION GET_DIGIT(SN/D20, X1/D20) GET_DIGIT/I2 = DMOD(SN, X1, 'D2') / (X1 / 10); END -* DEFINE FUNCTION SUM_DIGIT(DIVIDEND/I2) SUM_DIGIT/I1 = (IMOD(DIVIDEND, 100, 'I2') / 10) + IMOD(DIVIDEND, 10, 'I2') ; END -* DEFINE FILE CAR -* Generating numbers to use as test cases (starting numbers). START_NUM/D10 = DECODE CAR ('DATSUN' 7992739871 'AUDI' 23 'TOYOTA' 5556); -* Add a zero to the end of the Starting Number. START_NUM_D20/D20 = START_NUM * 10; -* Double every other digit, and then sum the resulting digit(s). DIGIT02/I2 = SUM_DIGIT(GET_DIGIT(START_NUM_D20, 100) * 2); DIGIT03/I2 = SUM_DIGIT(GET_DIGIT(START_NUM_D20, 1000)); DIGIT04/I2 = SUM_DIGIT(GET_DIGIT(START_NUM_D20, 10000) * 2); DIGIT05/I2 = SUM_DIGIT(GET_DIGIT(START_NUM_D20, 100000)); DIGIT06/I2 = SUM_DIGIT(GET_DIGIT(START_NUM_D20, 1000000) * 2); DIGIT07/I2 = SUM_DIGIT(GET_DIGIT(START_NUM_D20, 10000000)); DIGIT08/I2 = SUM_DIGIT(GET_DIGIT(START_NUM_D20, 100000000) * 2); DIGIT09/I2 = SUM_DIGIT(GET_DIGIT(START_NUM_D20, 1000000000)); DIGIT10/I2 = SUM_DIGIT(GET_DIGIT(START_NUM_D20, 10000000000) * 2); DIGIT11/I2 = SUM_DIGIT(GET_DIGIT(START_NUM_D20, 100000000000)); -* Add each, and multiply by 9. CHECKIT/D3 = (DIGIT02 + DIGIT03 + DIGIT04 + DIGIT05 + DIGIT06 + DIGIT07 + DIGIT08 + DIGIT09 + DIGIT10 + DIGIT11) * 9; -* Pull the check digit. CHECKDIGIT/D1 = DMOD(CHECKIT, 10, 'D1'); -* Create the final full output number. FULL_NUMBER/D22c = START_NUM_D20 + CHECKDIGIT; END -* TABLE FILE CAR PRINT START_NUM AS 'Starting/Input Number' FULL_NUMBER AS 'Final Full/Output Number' IF CAR EQ 'DATSUN' OR 'AUDI' OR 'TOYOTA' ON TABLE SET PAGE NOPAGE ON TABLE SET ONLINE-FMT STANDARD END
Produces the following output..
Starting/Input Number Final Full/Output Number --------------------- ------------------------ 7,992,739,871 79927398713 5,556 55566 23 232
All tests pass the LUHN-10 Checking tool at http://www.ee.unb.ca/cgi-bin/tervo/luhn.pl
Here's a pure Dialogue Manager solution I wrote.
&n = the number you are starting with.
&c = is the check digit calculated from &n.
-DEFAULT &n = '7992739871'; -SET &c = 0; -SET &o = IMOD(&n.LENGTH + 1, 2, 'I1'); -REPEAT ENDREPEAT FOR &i FROM &n.LENGTH TO 1 STEP -1 -SET &d = SUBSTR(&n.LENGTH, &n, &i, &i, 1, 'A1'); -SET &c = IF IMOD(&i, 2, 'I1') EQ &o THEN (&c + &d) ELSE (&c + DECODE &d (0 0 1 2 2 4 3 6 4 8 5 1 6 3 7 5 8 7 9 9)); -ENDREPEAT -SET &c = IMOD(&c * 9, 10, 'I1'); -TYPE Number = &n Check Digit = &c
Win10 / IE11
AHTML EXL2K PDF
thanks so much I will give these examples a try and post back my results!
|Powered by Social Strata|