A customer app built in Uniface 10 creates e-invoices (XRechnung). An e-invoice carries the seller's bank account, so the form that stores the seller data should refuse an IBAN with a typo before it ends up in hundreds of invoices.
Tested with Rocket Uniface 10.4.03 Community Edition (10.4.03.021) on Windows, November 2026. The app uses SQLite through the SLE driver (SQLite 3.50.2).
The rule
An IBAN such as DE89 3704 0044 0532 0130 00 is checked like this (ISO 13616 / ISO 7064 MOD 97-10):
- Remove the spaces, upper case.
- Move the first four characters (country code and check digits) to the end.
- Replace every letter by two digits: A = 10, B = 11, ..., Z = 35.
- Read the result as one integer. The IBAN is valid if the remainder of a division by 97 is 1.
Step 4 is the problem: the number has 30 digits and more, far beyond what a numeric variable holds exactly.
Remainder one digit at a time
You do not need the whole number. If m is the remainder of what you have read so far, appending the next digit d gives the remainder (m * 10 + d) mod 97. A letter stands for two digits, so it shifts by 100 instead of 10. The running value never grows beyond 96 * 100 + 35, and ProcScript can reduce it with a short subtraction loop instead of a modulo function.
The entry
This is the complete local entry of the service. Two small SQL calls do the parts SQL is good at (normalising, a pattern check, a length table); the checksum is plain ProcScript.
entry IBAN_RESULT
params
string pIban : IN
string pNorm : OUT
string pResult : OUT
endparams
variables
string vNorm, vCountry, vSql, vR, vEsc, vX, vC
numeric vLen, vWant, vRest, vM, vI, vD
endvariables
vEsc = pIban
call SQL_ESCAPE(vEsc)
call GET_TEXT("SELECT replace(upper('%%(vEsc)'), ' ', '')", vNorm)
pNorm = vNorm
pResult = "OK"
vLen = $length(vNorm)
vEsc = vNorm
call SQL_ESCAPE(vEsc)
call GET_TEXT("SELECT CASE WHEN '%%(vEsc)' GLOB '[A-Z][A-Z][0-9][0-9]*' AND NOT '%%(vEsc)' GLOB '*[^0-9A-Z]*' THEN 'Y' ELSE 'N' END", vR)
if (vR != "Y")
pResult = "WRONG_CHARACTERS"
return 0
endif
vCountry = vNorm[1:2]
call GET_TEXT("SELECT CASE '%%(vCountry)' WHEN 'DE' THEN 22 WHEN 'AT' THEN 20 WHEN 'CH' THEN 21 WHEN 'FR' THEN 27 WHEN 'NL' THEN 18 WHEN 'BE' THEN 16 WHEN 'IT' THEN 27 WHEN 'ES' THEN 24 WHEN 'LU' THEN 20 WHEN 'DK' THEN 18 WHEN 'PL' THEN 28 WHEN 'CZ' THEN 24 WHEN 'GB' THEN 22 WHEN 'IE' THEN 22 WHEN 'SE' THEN 24 WHEN 'FI' THEN 18 WHEN 'NO' THEN 15 WHEN 'PT' THEN 25 WHEN 'LI' THEN 21 ELSE 0 END AS L", vR)
vWant = vR
if ((vWant > 0 & vLen != vWant) | vLen < 15 | vLen > 34)
pResult = "WRONG_LENGTH"
return 0
endif
vRest = vLen - 4
vX = $concat(vNorm[5:vRest], vNorm[1:4])
vM = 0
vI = 1
while (vI <= vLen)
vC = vX[vI:1]
vD = $scan("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", vC) - 1
if (vD < 10)
vM = vM * 10 + vD
else
vM = vM * 100 + vD
endif
while (vM >= 97)
vM = vM - 97
endwhile
vI = vI + 1
endwhile
if (vM != 1)
pResult = "WRONG_CHECKSUM"
endif
return 0
end
Notes on the code:
-
vNorm[5:vRest]is a substring from position 5 with lengthvRest;vNorm[1:4]are the first four characters. Together they are step 2. -
$scanreturns the position of the character in the list0-9A-Z, so position minus 1 is exactly the value from step 3: digits 0 to 9, letters 10 to 35. - The
GLOBcheck runs first, so the loop only ever sees digits and capital letters. - The length table covers the countries this app deals with; for any other country only the general limit of 15 to 34 characters applies.
- The length
CASEhas an alias (AS L). The companion article on debugging explains why that matters with this driver.
GET_TEXT is a small helper that runs a query and returns the first column of the first row:
entry GET_TEXT
params
string pSql : IN
string pValue : OUT
endparams
variables
string vData, vRow
endvariables
pValue = ""
sql/data pSql, "CUSTOMERS"
if ($status < 0)
return -1
endif
vData = $result
if (vData = "")
return 0
endif
getitem vRow, vData, 1
getitem pValue, vRow, 1
return 0
end
Trying it
Three public example IBANs and one with a changed last digit:
| Input | Result |
|---|---|
DE89 3704 0044 0532 0130 00 |
OK |
GB82 WEST 1234 5698 7654 32 |
OK |
DE89 3704 0044 0532 0130 01 |
WRONG_CHECKSUM |
AT61 1904 3002 3457 320 |
WRONG_LENGTH |
The same results come from the automatic test service of the module, which also stores a seller IBAN through the form logic and expects the normalised value DE89370400440532013000 in the settings table.
Why not in SQL?
A first version computed the remainder with a recursive CTE and the % operator in SQLite. It is correct in the sqlite3 shell. When the test process of this module crashed inside this entry, the CTE was the first suspect; the real cause turned out to be another statement (described in the companion article). I kept the ProcScript loop anyway: 30 iterations, no driver involved, easy to step through in the debugger.
Limits
- A valid check digit does not mean the account exists. It catches typos and swapped digits, which is what a data entry form needs.
- The country length table is deliberately short. Extend it from the official IBAN registry if your users enter accounts from more countries.
Top comments (0)