Richard,
You need to determine what your "true" error is. The FOREACH
command is actually a combination OPEN and FETCH. If the OPEN
fails, all you see if the FETCH error (almost always -400). If
the code allows, you might be able to stick an "OPEN cursor" just
before your FOREACH. Of course, this isn't correct syntax but it's
a quick and dirty way to see what error the OPEN is returning.
Otherwise, you'll probably need to rewrite the FOREACH as an explicit
OPEN/WHILE OK/FETCH loop.
Another thing to remember is that a COMMIT or ROLLBACK will close any
cursor not declared as "WITH HOLD". It's a mistake I commonly make
that would fit your scenario.
--Craig (craig@chemistry.utah.edu)
>
> Can anyone give me an insight into a Fetch on unopen cursor
> problem. 4.1 RDS and SE on HP-UX 9.04. A very simple cursor
> 'SELECT * FROM fred' immediately followed by a FOREACH which
> gives -400 Fetch on unopen cursor. In another part of the program
> we do inserts to table fred (not in a cursor). The problem occurs
> after we have done the inserts. If we exit the program, re-enter
> and run the SELECT without doing the inserts there is no problem.
>