A specification of an INTO clause in this context overrides any INTO clause identified in the related open statement.
In most cases, the EGL runtime issues an implicit close statement occurs after the last iteration of the forEach statement. That implicit statement modifies the SQL system variables, for which reason you may want to save the values of SQL-related system variables in the body of the forEach statement.
The EGL runtime does not issue an implicit close statement if the forEach statement ends because of an error other than noRecordFound.
VGVar.handleHardIOErrors = 1; try open selectEmp with #sql{ select empnum, empname from employee where empnum >= :empnum for update of empname } into empnum, empname; onException myErrorHandler(6); // exits program end try forEach (from selectEmp) empname = empname + " " + "III"; try execute #sql{ update employee set empname = :empname where current of selectEmp }; onException myErrorHandler(10); // exits program end end // end forEach; cursor is closed automatically // when the last row in the result set is read onException // the exception block related to forEach is not run if the condition // is "sqlcode = 100", so avoid the test "if (sqlcode != 100)" myErrorHandler(8); // exits program end sysLib.commit();
Related concepts
resultSetID
SQL support
Related tasks
Syntax diagram for EGL statements and commands
Related reference
EGL statements
exit
open
SQL examples