Example: custlist.4gl (MAIN block)
The MAIN block implements a WHILE loop, to let the
user first enter a query filter, then browse rows in the filtered result set, and repeat the same
process until the Cancel button is selected.
The
MAIN block in custlist.4gl: 1 MAIN
2 DEFINE sql_cond STRING,
3 cust_num LIKE customer.cust_num
4
5 DEFER INTERRUPT
6
7 CONNECT TO "custdemo"
8
9 OPEN FORM fca FROM "custlist"
10 DISPLAY FORM fca
11
12 WHILE TRUE
13
14 LET sql_cond = custlist_query()
15 IF sql_cond IS NULL THEN
16 EXIT WHILE
17 END IF
18
19 LET cust_num = custarr_display(sql_cond)
20 CASE
21 WHEN cust_num < 0
22 EXIT WHILE
23 WHEN cust_num == 0
24 MESSAGE "Now rows found!"
25 OTHERWISE
26 MESSAGE SFMT("Customer #%1 was selected",cust_num)
27 END CASE
28
29 END WHILE
30
31 END MAINNote:
- Lines
12thru29define theWHILEloop. - Lines
14to17do the query filter input by calling thecustlist_queryfunction. - Line
15tests the value returned by the query function. ANULLindicates that the user has canceled theCONSTRUCTinstruction. In this case, we just leave theWHILEloop with anEXIT WHILEinstruction, and the program stops. - Lines
19thru27: We call thecustarr_displayfunction, which handles the customer record list. This function returns the number of the customer selected by the user. - Line
21: Thecustarr_displayfunction returns -1, if the user has canceled theDISPLAY ARRAYdialog. In this case we leave theWHILEloop and the program stops. - Line
23: Zero is returned as customer number, if no rows where found by the SQL query, and a message is displayed to the user. - Line
25: A positive number indicates that a customer record has been choosen by the user.