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 FUNCTION
Note:
- Line
1
declares the function without parameters and with no return values. - Lines
2
thru 4 define local function variables. - Lines
9
thru46
contain theWHILE
statement that is executed until an order is successfully selected or the user cancels the operation. - Lines
13
thru17
specify the form fields that will contain the search criteria for theCONSTRUCT
statement. - Lines
19
thru24
define anON ACTION
clause for thezoom1
button in theorders
form specification file. Here with call theselect_customer
function of thecustlist
module. 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
26
thru27
display the message when the user selects theabout
option. - Lines
31
thru44
test whether the user wants to interrupt the dialog and responds accordingly. - Lines
32
thru39
When the user interrupts, a message box is displayed if theordnums
array is empty, allowing the user to exit the program, or to continue. If the array is not empty, the function simply returns. - Lines
41
thru43
if the user validates the query, theorders_fetch_nums
function is called to retrieve the order information of the first element in the list; then theWHILE
loop is exited.