OPEN
The OPEN statement executes the SELECT statement the cursor refers to and positions the cursor immediately before the first row returned.
Format 1
EXEC SQL [ AT Database ]
 
  OPEN { Cursor-Name } [ USING Host-Variable, ... ] [ INTO Host-Variable, ... ]
       { Host-Var    }
 
END-EXEC
Format 2
EXEC SQL [ AT Database ]
 
  OPEN { Cursor-Name } [ USING DESCRIPTOR Sql-Descriptor ]
       { Host-Var    }
 
END-EXEC
Syntax rules
1. Cursor-Name is a Nonnumeric Literal, as defined in the Definitions section of the Preface of this document.
2. Host-Var must be USAGE HANDLE
3. Host-Variable is a host variable.
4. Sql-Descriptor is a SQLDA structure. This syntax is compiled only if iscobol.compiler.esql.db2 (boolean) is set to ‘1’, ‘on’, ‘true’ or ‘yes’ in the Compiler configuration.
General rules
1. Cursor-Name must be previously defined by a DECLARE statement.
Examples
Declare, open and fetch a cursor
exec sql 
   declare cust_cur  cursor for select * from customers
end-exec
 
exec sql 
   open cust_cur
end-exec     
 
perform until 1 = 2
   exec 
      sql fetch next cust_cur into :ws-cust-code, :ws-cust-name
   end-exec
 
   display "code: " ws-cust-code " name: " ws-cust-name
   if sqlcode = 100
      exit perform
   end-if
 
end-perform
 
exec sql 
   close cust_cur
end-exec