A fixed-list SELECT statement is a statement that returns a predictable number of data items of a known type from an open cursor. For each of these items, a host variable is required to accommodate incoming data.
To issue a fixed-list SELECT statement dynamically:
Be sure to handle any errors.
The following example shows how to execute a fixed-list SELECT statement dynamically.
* include SQLDA copybook 
     EXEC SQL 
         INCLUDE SQLDA 
     END-EXEC
* assign value to variable sqlcmd. 
     MOVE 'select e_no, ' & 
          'lname from employee where dept="1050"' TO sqlcmd
* prepare SELECT command. 
     EXEC SQL 
         PREPARE q1 FROM :sqlcmd 
     END-EXEC
* declare cursor for SELECT command. 
     EXEC SQL 
         DECLARE c1 CURSOR FOR q1 
     END-EXEC
* open cursor. 
     EXEC SQL 
         OPEN c1 
     END-EXEC
* fetch data into program variables EMPNO, LASTNME and 
* FIRSTNME. 
     EXEC SQL 
         FETCH c1 INTO :EMPNO, :LASTNME 
     END-EXEC 
* close cursor. 
     EXEC SQL 
         CLOSE c1 
     END-EXEC