After you execute a statement and you have some results to get back, then you'll call OdbcFetch. OdbcFetch retrieves one row's columns, so you will loop around a call to OdbcFetch until you have read the columns for all rows that match your SQL query/operation.

The first arg is the name of the stem variable where you want stored the data for the columns in the next row. If omitted, then the results are not returned, and you can follow up with calls to OdbcGetData yourself.

The second arg is the number of columns that were returned by OdbcExecute.

OdbcFetch will read the next row's column data, and store it in your stem variable. If successful, OdbcFetch will return an empty string, otherwise an error message. (It will also raise ERROR condition if you prefer to trap that).

Note: When there is not another row to fetch, OdbcFetch will return the string "DONE". Even if you have elected to have ODBC functions raise some condition, that will not happen in this case.

Here is an example of fetching and displaying the results after a call to OdbcExecute:

/* Display all the rows of results. */
DO

   /* Get the next row's columns. */
   DO WHILE OdbcFetch("data.", columns) \== "DONE"

      /* Display the row */
      DO col = 1 TO columns
         CHAROUT(, data.col)
         /* If this is the last column of the row, then end the line. Otherwise, just display a comma */
         IF col = columns THEN SAY
         ELSE CHAROUT(, ", ")
      END

   END

   CATCH ERROR
      CONDITION("M")
      RETURN
END