Re: FOREACH syntax error
Posted in 1995
In article <44hc3b$jvj@cssun.mathcs.emory.edu> jparker@hpbs3645.boi.hp.com (Jack Parker) writes:
>From: jparker@hpbs3645.boi.hp.com (Jack Parker)
>Subject: FOREACH syntax error
>Date: 29 Sep 1995 13:58:03 -0400
>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.
>Obviously there is some piece of code nested in the 4000+ odd lines that is
>causing this problem. I have no idea what it is. My standard debugging
>technique involves ripping things out until the pain stops. Does this
>ring a bell for anyone? In other words does anyone have some idea what
>I should be looking for?
A couple of suggestions:
Have you re-used one of the column or table names as a variable name in the
larger program?
Try printing out SQLERRD when it bombs. One of the elements (I can't remember
which offhand) is a pointer into the SQL where the parser realises it's in
trouble.
Ian