Example: custquery.4gl

The custquery module implements the SQL cursor to browser the customer record set produced from a QBE CONSTRUCT query. In this section we describe the changes done from the custquery.4gl version of the previous chapter.

The header of the custquery.4gl module:
  1 IMPORT FGL custdata
  2 
  3 SCHEMA custdemo
  4 
  5 PRIVATE DEFINE mr_custrec custdata.t_custrec
Note:
  • Line 1 imports public symbols from the custdata module.
  • Line 3 defines the database schema to be used for LIKE definitions.
  • Line 5 defines a private, module variable with the user type t_custrec defined in the custdata module.
The fetch_cust function has beem enhanced, to accept more values for the fetch flag, allowing to fetch the first (0), last (2) or current (3) row in the scroll cursor result set:
  1 PRIVATE FUNCTION fetch_cust(p_fetch_flag SMALLINT) RETURNS BOOLEAN
  2   CASE p_fetch_flag
  3   WHEN 0
  4      FETCH FIRST cust_curs INTO mr_custrec.*
  5   WHEN 1
  6      FETCH NEXT cust_curs INTO mr_custrec.*
  7   WHEN -1
  8      FETCH PREVIOUS cust_curs INTO mr_custrec.*
  9   WHEN 2
 10      FETCH LAST cust_curs INTO mr_custrec.*
 11   WHEN 3
 12      FETCH CURRENT cust_curs INTO mr_custrec.*
 13   END CASE 
 14   RETURN (SQLCA.SQLCODE == 0)
 15 END FUNCTION
Note:
  • Line 3 thru 4: Implements the code to fetch to the first row of the scroll cursor.
  • Line 9 thru 10: Implements the code to fetch to the last row of the scroll cursor.
  • Line 11 thru 12: Implements the code to fetch to row at the current position of the scroll cursor.