fetch returns the specified number of rows from the currently active set. Each fetch returns the subsequent batch of rows. For example, if the currently active set has 150 rows and you select and fetch 60 rows, the first fetch returns the first 60 rows. The next fetch returns the following 60 rows. The third fetch returns the last 30 rows.
To find the total number of rows fetched, see the SQLERRD variable
in the SQLCA, as described in “SQLCA variables”.
Following is an example of selecting into an array:
exec sql begin declare section end-exec
TITLEID-ARRAY PIC X(6) occurs 100 times.
exec sql end declare section end-exec
...
exec sql
select title_id into :titleid_array
from titles
end-exec
IF (SQLERRD OF SQLCA LESS THAN 50)
DISPLAY "No of title_ids is less than 50");
ENDIF.