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:
01 FUNCTION fetch_cust(p_fetch_flag)
02   DEFINE p_fetch_flag SMALLINT,
03             fetch_ok SMALLINT
04
05   LET fetch_ok = FALSE
06   IF (p_fetch_flag = 1) THEN
07     FETCH NEXT cust_curs 
08       INTO mr_custrec.*
09   ELSE
10     FETCH PREVIOUS cust_curs 
11       INTO mr_custrec.*
12   END IF
13
14   IF (SQLCA.SQLCODE = NOTFOUND) THEN
15     LET fetch_ok = FALSE
16   ELSE
17     LET fetch_ok = TRUE
18   END IF
19
20   RETURN fetch_ok 
21
22 END FUNCTION
Note: