Example: custquery.4gl (function fetch_rel_cust)

This function fetches a customer record in the direction specified by the flag passed as parameter.

Function fetch_rel_cust:
  1 FUNCTION fetch_rel_cust(p_fetch_flag SMALLINT) RETURNS ()
  2   MESSAGE " "
  3   IF fetch_cust(p_fetch_flag) THEN
  4     CALL display_cust()
  5   ELSE
  6     IF p_fetch_flag == 1 THEN
  7       MESSAGE "End of list"
  8     ELSE
  9       MESSAGE "Beginning of list"
 10     END IF
 11   END IF
 12 END FUNCTION
Note:
  • Line 1: The parameter passed to p_fetch_flag will be 1 or -1, depending on the direction in which the scroll cursor is to move. The function returns no value.
  • Line 2 resets the message display to blanks.
  • Line 3 calls the function fetch_cust, passing it the value of p_fetch_flag. The function fetch_cust returning FALSE if there was no row found.
  • Line 4 If a row was found (the fetch_cust function returned TRUE), the display_cust function is called to display the row in the form.
  • Line 6 If no rows were found and the direction is forward, indicated by p_fetch_flag of 1, the cursor is past the end of the result set.
  • Line 8 If no rows were found and the direction is backward, indicated by p_fetch_flag of -1, the cursor is prior to the beginning of the result set.