Example custquery.4gl (function cust_select)

This function is called by the function query_cust, if the row count returned by the function get_cust_cnt indicates that the criteria previously entered by the user and stored in the variable where_clause would produce an SQL SELECT result set.

Function cust_select:
01 FUNCTION cust_select(p_where_clause) 
02   DEFINE p_where_clause STRING,
03         sql_text STRING,
04         fetch_ok SMALLINT
05
06   LET sql_text = "SELECT store_num, " ||
07      " store_name, addr, addr2, city, " ||
08      " state, zip_code, contact_name, phone " ||
09      " FROM customer WHERE " || p_where_clause ||
10      " ORDER BY store_num"
11 
12   DECLARE cust_curs SCROLL CURSOR FROM sql_text 
13   OPEN cust_curs 
14   CALL fetch_cust(1)   -- fetch the first row 
15     RETURNING fetch_ok 
16   IF NOT (fetch_ok) THEN
17     MESSAGE "no rows in table."   
18   END IF
19
20   RETURN fetch_ok 
21 
22 END FUNCTION
Note: