Obviously you can limit the amount fo rows returned by using WHERE clauses. But if you only want the first 5 rows, when 100 satisfy the WHERE clauses, then you can code:
FETCH FIRST 5 ROW ONLY
to the select statement. After 5 rows have been obtained (or however many you need) an SQLCODE of 100 will be returned.
Hope this helps.
Marc