Advanced PowerBuilder

HomePrevious Lesson: Phantom Rows
Next Lesson: Cursors and Transaction Objects

The FETCH Statement

To retrieve each row in a cursor and load it into host variables, you use a FETCH statement. This statement allows you to fetch one row at a time, moving through the result set, after each FETCH. You need to check SQLCA.SQLCODE to find the end of the result set. Have a look at the following example:
FETCH lProductMasterCursor1 
INTO :li_ProductNo, :lProductDesc ;
Do While SQLCA.SQLCODE <> 100
   // Do While SQLCA.SQLCODE = 100
   // Some processing such as loading into a ListBox, etc.
   FETCH lProductMasterCursor1 
      INTO :li_ProductNo, :lProductDesc ;
Loop
CLOSE lProductMasterCursor1 ;

Once all rows are returned, we close the cursor with the CLOSE command.
HomePrevious Lesson: Phantom Rows
Next Lesson: Cursors and Transaction Objects