This morning I had the need to know the control code to obtain the IBAN (International Bank Account Number) of a series of accounts.
The formula is very simple: to the 20 digits of the old CCC, the 6 digits of the country are added; then it is divided by 97, and the remainder is taken; finally, the control code = 98 - remainder.
The problem comes when trying to divide a number of 26 digits, because for such operation Harbour admits up to 18 (even rounds the amount to those 18 digits).
I have been able to solve it by creating a function that I have called "ABACUS" (a laugh) and that consists of performing the operations by breaking the 26 digits in two blocks of 13:
Code: Select all
FUNCTION ABACUS() LOCAL V1,V2,R1,R2,R3 CCC:="11112222333344445555142800" // PUBLIC VARIABLE OF // THE ACCOUNT CODE V1:=VAL( LEFT(CCC,13) ) V2:=VAL( RIGHT(CCC,13) ) R1:=V1%97 // REMAINDER OF THE FIRST HALF OF CCC R2:=R1*(10**13)+V2 // MULTIPLY THE FIRST REMAINDER BY 10^13 // AND ADDED TO THE SECOND HALF OF CCC R3:=R2%97 // REMAINDER OF CCC/97 RETURN R3