Example: custquery.4gl (function fetch_cust)
This function is designed so that it can be reused each time a row is to be fetched
from the customer database table; a variable is passed to indicate whether the
cursor should move forward one row or backward one row.
Function
fetch_cust: 1 FUNCTION fetch_cust(p_fetch_flag SMALLINT) RETURNS BOOLEAN
2 IF p_fetch_flag == 1 THEN
3 FETCH NEXT cust_curs INTO mr_custrec.*
4 ELSE
5 FETCH PREVIOUS cust_curs INTO mr_custrec.*
6 END IF
7 RETURN (SQLCA.SQLCODE == 0)
8 END FUNCTIONNote:
- Line
1The functionfetch_custaccepts a parameter and stores it in the local variablep_fetch_flag. Then function returns a boolean value. - Line
2tests the flag passed as parameter, to fetch forwards or backwards. - Line
3fetches a new row in the forward direction, by using the cursorcust_curs. - Line
4fetches a new row in the backwards direction, by using the cursorcust_curs. - Line
7evaluates and returns a boolean expression based on the value ofSQLCA.SQLCODE. IfSQLCA.SQLCODEis equal to zero, the function returnsTRUE.