Hi, I don't know why your stored procedure doesn't update all the records. Maybe it has to do with the lock level (table locking vs. row locking) in conjunction with the isolation level. Check out under what conditions concerning these matters the SP is executed.
But a simpler solution is to not use the FOREACH loop but make the changes in one query, like:
UPDATE table SET b = '965' || b[5,11]
WHERE b MATCHES '9656???????';
LET compteur = dbinfo('sqlca.sqlerrd2');
BTW. In your SELECT query you're making use of numeric operators on a string type column. I wouldn't do that, for one thing because it costs extra time fot the implicit conversion the server has to make to interpret the clause. That's why I use the string operator MATCHES here.