Re: FOREACH syntax error
Posted in 1995
I have had fun in the past with SQL statements that work fine on
their own, but imbed them in a large program and I get inexplicable
errors. One thing that is worth checking is: are any of the column
names / table names in the SQL fragment also names of variables
in the program? If so, that may be the problem.
I had a lot of fun with a statement like this:
select max(end_date) from <blah blah>
that turned out to be due to the fact that somewhere in a module long ago
and far away, end_date was declared as a variable (OK, it was probably in
the globals file).
Paul
In article <44hc3b$jvj@cssun.mathcs.emory.edu>,
Jack Parker <jparker@hpbs3645.boi.hp.com> wrote:
>
>Interesting problem (at least to me). I have a cursor:
>
> DECLARE ct_curs CURSOR FOR
> SELECT filename, colname, coltype, collength
> FROM source_tables, source_columns
> WHERE source_tables.file_id = source_columns.file_id
> AND source_tables.end_date IS NULL
> ORDER BY filename, colname >
>and a simple FOREACH loop;
>
>LET c_idx = 1
>FOREACH ct_curs INTO col_rec[c_idx].tabname, col_rec[c_idx].colname,
> col_rec[c_idx].coltype, col_rec[c_idx].collength
> LET col_rec[c_idx].tag = ''
> LET c_idx = c_idx + 1
> IF c_idx > 1000 THEN
> EXIT FOREACH
> END IF
>END FOREACH
>
>This works fine by itself. When I use the same code in a bigger and finer
>program I get a -201 syntax error on the FOREACH. Checking the .ec code
>it appears that it doesn't like trying to open the cursor.
>