Re: FOREACH syntax error
Posted in 1995
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. : 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? Maybe, you have some GLOBAL or local variables with names filename, colname, coltype, collength ? If it's true, you need SELECT @filename, @colname, @coltype, @collength ... It seems strange, but Informix cannot deal with host variables in SELECT list (sometimes they can be very useful). For example, such a 4gl code produces syntax error at run-time PREPARE stmt FROM "SELECT ? FROM mytable" But PREPARE stmt FROM "SELECT ? + 0 FROM mytable" works fine ! WBR, Vadim J. Nikitin