CID number sometimes wrong

Hi everybody,

I have a custom pstn macro which does add a zero or (if it comes from
another old pbx) removes the first digits to/from the callerID Number.
This Macro is like the one in the faq:

[from-Tevitel-custom]
exten => _X.,1,GotoIf($["${CALLERID(num):0:7}" = “6154638”]?istIntern:nullDavor)

exten => _X.,n(istIntern),Set(CALLERID(num)=${CALLERID(num):7})
exten => _X.,n,Goto(from-pstn,${EXTEN},1)

exten => _X.,n(nullDavor),Set(CALLERID(num)=0${CALLERID(num)})
exten => _X.,n,Goto(from-pstn,${EXTEN},1)

The Macro works fine most of the time.
But sometimes the Macro sets a wrong number. (out of 1207 calls there are 65 wrong)
I have no clue why this happens.
the 1200 calls are the amount of calls for two days.
Is there an unsafe use of the variable CALLERID(num)?

The Logfile says this (when it don´t set the right number):

[Jan 20 17:05:10] VERBOSE[6547] logger.c: – Accepting overlap call from ‘06257940233’ to ‘638171’ on channel 0/2, span 1
[Jan 20 17:05:10] VERBOSE[17016] logger.c: – Starting simple switch on ‘Zap/2-1’
[Jan 20 17:05:13] DEBUG[17016] chan_dahdi.c: Echo cancellation already on
[Jan 20 17:05:13] VERBOSE[17016] logger.c: – Executing [638171@from-Tevitel-custom:1] GotoIf(“Zap/2-1”, “0?istIntern:nullDavor”) in new stack
[Jan 20 17:05:13] VERBOSE[17016] logger.c: – Goto (from-Tevitel-custom,638171,4)
[Jan 20 17:05:13] VERBOSE[17016] logger.c: – Executing [638171@from-Tevitel-custom:4] Set(“Zap/2-1”, “CALLERID(num)=0638201”) in new stack
[Jan 20 17:05:13] VERBOSE[17016] logger.c: – Executing [638171@from-Tevitel-custom:5] Goto(“Zap/2-1”, “from-pstn|638171|1”) in new stack
[Jan 20 17:05:13] VERBOSE[17016] logger.c: – Goto (from-pstn,638171,1)

The number 06257940233 calls 638171 and gets the wrong callerid number 0638201???
But why?

best regards florian

any tipps?