Modulo-97

COBOL

The Micro Focus Developer product portfolio comprises industry leading off-mainframe COBOL development and deployment tools to modernize business-critical enterprise applications.

Modulo-97

This question is answered

[Migrated content. Thread originally posted on 05 May 2012]

How want to share the cobol sourcelines that does the calculation of a checkdigit for a IBAN number?

Thanks for helping.

Verified Answer
  • You should be able to change binary-long to... pic s9(9) comp-5...

    If precision is an issue, an alternative algorithm is document @
    http://iban.software.informer.com/wiki/#Calculating_and_validating_IBAN_checksums

    As few computers can handle numbers that long, an iterative modulus calculation is probably needed:
    1. Take the first 8 digits.
    2. Perform a modulus calculation on those.
    3. Append the next six digits to the result on step 2.
    4. Repeat steps 2 and 3 until there are no more digits to append.

    This works because X MOD 97x10^n is an integer product of 97 plus X MOD 97
All Replies
  • Using documentation on the internet, I've thrown together an example on how to validate the checksum on a gb iban... hopefully this helps..

    Note: I really have thrown this together, so use it at your peril.


           program-id. ibanchk as "ibanchk".

           environment division.
           configuration section.

           data division.
           
           working-storage section.
           *>  GBkk BBBB SSSSSS CC CC CC CC
           *>    B = alphabetical bank code,
           *>    S = sort code (often a specific branch),
           *>    C = account No.
           01 iban-gb typedef.
               03 first-four.
                   05 countryCode      pic xx.
                   05 checkSum         pic xx.
               03 the-rest.
                   05 bankcode         pic x(4).
                   05 sort-code        pic x(6).
                   05 account-num.
                       07 account-num-part1 pic x(4).
                       07 last-four    pic x(4).
                       
               
           01 iban-gb-example      iban-gb.
         
           01 tmp-x4               pic x(4).
           
           01 big-x                 pic 9(38).
           01 res                  pic 9(38).
           
           01 tmp-x40              pic x(40).
           01 tmp-count            binary-long.
           01 tmp-new-count        binary-long.
           01 tmp-x                pic x.
           01 tmp-x-9              pic x comp-5 redefines tmp-x.
           01 tmp-x2               pic xx.
           01 tmp-iban-gb          iban-gb.
           
           procedure division.
               move "GB54BARC20992012345670" to iban-gb-example
               perform iban-check-gb
           
               move "GB54BARC20992012345678" to iban-gb-example
               perform iban-check-gb
               
               stop "-- end"
               stop run.
           
           iban-check-gb section.
               move iban-gb-example to tmp-iban-gb
               
               move first-four of iban-gb-example to tmp-x4
               move the-rest of iban-gb-example to iban-gb-example
               move tmp-x4 to last-four of iban-gb-example
               
               move 1 to tmp-new-count
               perform varying tmp-count from 1 by 1 until tmp-count
                   greater length of iban-gb-example
               
                   move iban-gb-example(tmp-count:1)  to tmp-x
                   if tmp-x >= 'A' and
                       tmp-x
                       subtract 55 from tmp-x-9
                       move tmp-x-9 to tmp-x2
                       move tmp-x2 to tmp-x40(tmp-new-count:2)
                       add 2 to tmp-new-count
                   else
                       move iban-gb-example(tmp-count:1) to
                           tmp-x40(tmp-new-count:1)
                       add 1 to tmp-new-count
                   end-if
               end-perform
               move function numval(tmp-x40) to big-x
               
               move tmp-iban-gb to iban-gb-example       
               compute res = function mod(big-x, 97)
               if res equals 1
                   display iban-gb-example " is okay"
               else
                   display iban-gb-example " is invalid"
               end-if   
               .

           end program ibanchk.

  • I use AcuGT version 9.1.1.
    A picture clause with 38 is not around, with compiler option -Dd31 is the max 31 digits.
    The binary-long is giving an error to.
  • You should be able to change binary-long to... pic s9(9) comp-5...

    If precision is an issue, an alternative algorithm is document @
    http://iban.software.informer.com/wiki/#Calculating_and_validating_IBAN_checksums

    As few computers can handle numbers that long, an iterative modulus calculation is probably needed:
    1. Take the first 8 digits.
    2. Perform a modulus calculation on those.
    3. Append the next six digits to the result on step 2.
    4. Repeat steps 2 and 3 until there are no more digits to append.

    This works because X MOD 97x10^n is an integer product of 97 plus X MOD 97