Example: orders.4gl (Function order_query)
This function allows the user to search for a specific order by entering criteria
into the form (Query by Example). This CONSTRUCT statement is not a sub-dialog of a
DIALOG statement. It is a stand-alone statement called by the action
find, triggered when the user selects the corresponding menu item or toolbar icon
on the form orders.
Function
order_query
(orders.4gl): 1 PRIVATE FUNCTION order_query() RETURNS ()
2 DEFINE sql_cond STRING,
3 num LIKE customer.cust_num,
4 name LIKE customer.cust_name
5
6 MESSAGE msg02
7 CLEAR FORM
8
9 WHILE TRUE
10
11 LET int_flag = FALSE
12 CONSTRUCT BY NAME sql_cond ON
13 orders.cust_num,
14 customer.cust_name,
15 orders.order_num,
16 orders.order_date,
17 orders.fac_code
18
19 ON ACTION zoom1
20 CALL custlist.select_customer() RETURNING num, name
21 IF num > 0 THEN
22 DISPLAY num TO orders.cust_num
23 DISPLAY name TO customer.cust_name
24 END IF
25
26 ON ACTION about
27 CALL comutils.mbox_ok(title1,msg18)
28
29 END CONSTRUCT
30
31 IF int_flag THEN
32 MESSAGE msg03
33 IF ordnums.getLength()==0 THEN
34 IF comutils.mbox_yn(title1,msg15) THEN
35 EXIT PROGRAM
36 END IF
37 CONTINUE WHILE
38 END IF
39 RETURN
40 ELSE
41 IF orders_fetch_nums(sql_cond) THEN
42 EXIT WHILE
43 END IF
44 END IF
45
46 END WHILE
47
48 END FUNCTIONNote:
- Line
1declares the function without parameters and with no return values. - Lines
2thru 4 define local function variables. - Lines
9thru46contain theWHILEstatement that is executed until an order is successfully selected or the user cancels the operation. - Lines
13thru17specify the form fields that will contain the search criteria for theCONSTRUCTstatement. - Lines
19thru24define anON ACTIONclause for thezoom1button in theordersform specification file. Here with call theselect_customerfunction of thecustlistmodule. After the user selects the desired customer from the customer list that is displayed, the customer number and name are stored in the corresponding fields of the form. - Lines
26thru27display the message when the user selects theaboutoption. - Lines
31thru44test whether the user wants to interrupt the dialog and responds accordingly. - Lines
32thru39When the user interrupts, a message box is displayed if theordnumsarray is empty, allowing the user to exit the program, or to continue. If the array is not empty, the function simply returns. - Lines
41thru43if the user validates the query, theorders_fetch_numsfunction is called to retrieve the order information of the first element in the list; then theWHILEloop is exited.