OPEN
The OPEN statement executes the SELECT statement the cursor refers to and positions the cursor immediately before the first row returned.
General format
EXEC SQL [ AT Database ]
 
  OPEN { Cursor-Name } [ USING Host-Variable, ... ] [ INTO Host-Variable, ... ]
       { 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.
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