Example: custlist.4gl (Function custlist_query)
The custlist_query function implements the CONSTRUCT
instruction to
get an SQL condition that will be used in the SELECT
statement to filter customer
table rows.
The
custlist_query
function in
custlist.4gl
: 1 PRIVATE FUNCTION custlist_query() RETURNS STRING
2 DEFINE sql_cond STRING
3
4 CLEAR FORM
5
6 LET int_flag = FALSE
7 CONSTRUCT BY NAME sql_cond ON cust_num, cust_name
8
9 IF int_flag THEN
10 RETURN NULL
11 ELSE
12 RETURN sql_cond
13 END IF
Note:
- Line
1
defines the function with not parameters, and a single return value of typeSTRING
. - Line
4
clears all form fields with theCLEAR FORM
instruction. - Line
6
resets theint_flag
register toFALSE
. - Line
7
declares theCONSTRUCT
instruction. For more details, go to Tutorial Chapter 4: Query by Example. - Lines
9
thru13
: Depending on the int_flag, we return the SQL condition or NULL, if the user has selected the Cancel button.