OPEN AND FETCH - error. Why?
Posted in 1996
} } DATABASE vendor } Hi All, } I am getting error on "OPEN and FETCH" stmnt. Could someone help } on this? } } Engine Version: 5.x, 4GL version 4.10UE2. } h/w is SunOS 4.1.3. } } code starts here--------- } MAIN } CALL validate_ids() } END MAIN } } FUNCTION validate_ids() } DEFINE } p_pid char (10) , } pccd char (10), } p_parent_desc char(30) } } LET p_pid = "41893" } } CALL prep_statements() } } OPEN c_sel USING p_pid } | } | The cursor "c_sel" has not yet been declared in this program } | module. It must be declared before it can be used. } | See error number -4372. } } FETCH c_sel into pccd, p_parent_desc } | } | The cursor "c_sel" has not yet been declared in this program } | module. It must be declared before it can be used. } | See error number -4372. } } END FUNCTION } } FUNCTION prep_statements() } DEFINE sel_str char(500) } } LET sel_str = " SELECT comp_cd, comp.comp_ident FROM comp ", } " WHERE comp.comp_id = ? " } } PREPARE prep_stmt FROM sel_str } DECLARE c_sel CURSOR FOR prep_stmt } } end function } Simple. FUNCTION prep_statements() needs to physically occur in your code before it is opened. The compiler doesn't care that it's ABOUT to be defined - even if the definition will occur logically before it is used - it wants to see it defined before it is used. Move your 'prep_statements' function up before validate_ids() and you will no longer get that error. cheers j. _____________________________________________________________________________ Jack Parker - Hewlett Packard, DMD/IS Boise, Idaho, USA jparker@boi.hp.com Currently on loan to PLD/PE _____________________________________________________________________________ If anything can go wrong, fix it. To hell with Murphy. _____________________________________________________________________________ Any opinions expressed herein are my own and not those of my employers. _____________________________________________________________________________