Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

SEPA IBAN Calculation - Val() Function Problems

122 views
Skip to first unread message

handst...@gmx.de

unread,
Apr 20, 2013, 5:32:55 AM4/20/13
to
Hi there,

the result of the val() function seems to be limited ?
with long strings like "700901001234567890131400" it is not working correct

Example:

function mk_IBAN()
Local sIBAN
? ""
wait "IBAN calcualtion for debugging"
BLZ := "70090100" // Bank Identifiercode Germany
ktnr:= "1234567890" // Bank Accountnumber Germany
landkenn:= "131400" // "DE" (D = 13, E = 14 - adding "00")
BBAN:= BLZ+ktnr
BBAN1:= BBAN+landkenn
?
? "BBAN1 = "+BBAN1
prfsumme:= val(BBAN1)
dtype := valtype(prfsumme)
? "prfsumme:= val(BBAN1) "+ str(prfsumme)
? "Valtype(prfsumme)= "+dtype
modulo := 97
prziffer:= prfsumme % modulo // 700901001234567890131400 modulo 97 = 90
? "prziffer:= prfsumme % 97 = "+str(prziffer,2,0)+" - should be 90" // 700901001234567890131400 modulo 97 = 90
prziffer2:= 98 - prziffer // should be 90
? "prziffer2:= 98 - prziffer = "+str(prziffer2,2,0)+" - should be 8"
sIBAN :="DE"+str(prziffer2,2,0)+BBAN
? "IBAN = "+sIBAN
wait ""
return nil

Ella

unread,
Apr 20, 2013, 10:01:01 AM4/20/13
to
Hello,

>
> the result of the val() function seems to be limited ?
>
> with long strings like "700901001234567890131400" it is not working correct
>

The IBAN string listed by you is equivalent with a numeric value holding 24 significant digits, and thus its PRECISION exceeds 15 significant digits, which is the precision of the DOUBLE floating point datatype commonly used in xBase and many other languages for representing numeric data.

You need to split up your IBAN string for extracting at least two numbers and applying the appropiate arithmetical formulas for obtaining the desired result.

Ella Stern

handst...@gmx.de

unread,
Apr 21, 2013, 8:15:20 AM4/21/13
to
Okay now another Try,

// test.prg
#include "hbclass.ch"
#include "common.ch"
Main()
PROCEDURE Main()
prziffer := get_IBAN("700901001234567890131400", 97)
? "prziffer:= BBAN1 % 97 = "+str(prziffer,2,0)
wait ""
RETURN
***************************************
#pragma BEGINDUMP
#include <windows.h>
#include "hbapi.h"

HB_FUNC(get_IBAN)
{
char *string = hb_parc(1);
long sIBAN;
sIBAN = atol(string);
hb_retnl(sIBAN % hb_parnl(2)) ;
}
#pragma ENDDUMP

-------------------
REMARK 926 Lines !!!!!!!!
but i after linking i get the following funny errors :

hbmk2: Processing environment options: -compiler=mingw
hbmk2: Compiling Harbour sources...
Harbour 3.2.0dev (Rev. 18706)
Copyright (c) 1999-2012, http://harbour-project.org/
Compiling 'inline_c.PRG'...
Lines 926, Functions/Procedures 2
Generating C source output to 'obj\inline_c.c'... Done.
hbmk2: Compiling...
hbmk2: Linking... IBANTest.exe
obj/inline_c.o:inline_c.c:(.data+0x28): undefined reference to `HB_FUN_GET_IBAN'
collect2: ld returned 1 exit status

hbmk2: Error: Referenced, missing, but unknown function(s): GET_IBAN()



Enrico Maria Giordano

unread,
Apr 21, 2013, 9:04:27 AM4/21/13
to


> HB_FUNC(get_IBAN)

HB_FUNC(GET_IBAN)

EMG

--
EMAG Software Homepage: http://www.emagsoftware.it
The EMG's ZX-Spectrum Page: http://www.emagsoftware.it/spectrum
The Best of Spectrum Games: http://www.emagsoftware.it/tbosg
The EMG Music page: http://www.emagsoftware.it/emgmusic


handst...@gmx.de

unread,
Apr 21, 2013, 10:30:10 AM4/21/13
to
Am Sonntag, 21. April 2013 15:04:27 UTC+2 schrieb Enrico Maria Giordano:
> > HB_FUNC(get_IBAN)
>
>
>
> HB_FUNC(GET_IBAN)
>
>
>
> EMG
>
>
1000*(thank you),

Matthias

handst...@gmx.de

unread,
Apr 21, 2013, 5:42:29 PM4/21/13
to
Ok, i found a workaround

PROCEDURE Main()
//BBAN1:= "200800000970375700131400"
BBAN1:= "700901001234567890131400"
Rest1 := val(substr(BBAN1,1,9)) % 97
lenRest1 := len(alltrim(str(Rest1,2,0)))

BBAN2 := alltrim(str(Rest1,2,0))+substr(BBAN1,10,(9-lenRest1))
Rest2 := val(BBAN2) % 97
lenRest2 := len(alltrim(str(Rest2,2,0)))

BBAN3 := alltrim(str(Rest2,2,0))+substr(BBAN1,10+(9-lenRest1),9)
Rest3 := val(BBAN3) % 97

? "BBAN1 = "+BBAN1
prziffer:= Rest3 % 97 // 700901001234567890131400 modulo 97 = 90
? "prziffer = "+str(prziffer,2,0) // 700901001234567890131400 modulo 97 = 90
prziffer2:= 98 - prziffer // should be 8
? "prziffer2 = "+str(prziffer2,2,0)
if prziffer2 < 10
prfstring := "0"+alltrim(str(prziffer2,2,0))
else
prfstring := str(prziffer2,2,0)
endif
sIBAN :="DE"+prfstring+BBAN
? "IBAN = "+sIBAN
wait ""
RETURN

handst...@gmx.de

unread,
Apr 22, 2013, 1:37:53 PM4/22/13
to
correction
> sIBAN :="DE"+prfstring+left(BBAN1,18)
0 new messages