Example: orders.4gl (Function order_fetch)
This function browses the ordnums list in the direction specified by
the parameter, and fetches the order header information and order lines of the new current
row.
Function
order_query
(orders.4gl): 1 PRIVATE FUNCTION order_fetch(dir SMALLINT) RETURNS BOOLEAN
2
3 CASE dir
4 WHEN move_first
5 IF ordnums.getLength() > 0 THEN
6 LET orders_index = 1
7 ELSE
8 LET orders_index = 0
9 RETURN FALSE
10 END IF
11 WHEN move_prev
12 IF orders_index > 1 THEN
13 LET orders_index = orders_index - 1
14 ELSE
15 RETURN FALSE
16 END IF
17 WHEN move_next
18 IF orders_index < ordnums.getLength() THEN
19 LET orders_index = orders_index + 1
20 ELSE
21 RETURN FALSE
22 END IF
23 WHEN move_last
24 LET orders_index = ordnums.getLength()
25 END CASE
26
27 SELECT orders.cust_num,
28 customer.cust_name,
29 orders.order_num,
30 orders.order_date,
31 orders.fac_code,
32 orders.ship_instr,
33 orders.promo
34 INTO order_rec.*
35 FROM orders, customer
36 WHERE orders.cust_num = customer.cust_num
37 AND orders.order_num = ordnums[orders_index]
38
39 CALL items_fetch()
40
41 RETURN TRUE
42
43 END FUNCTIONNote:
- Line
1defines the function with an parameter indicating the direction to move to. The function returnsTRUEon success. - Lines
3thru25implement theCASEblock, executing code blocks depending on the direction parameter. The direction options are defined with themove_*constants. The code increments or decrements theorder_indexvariable, which defines the position of the current row in theordnumsarray. - Lines
27thru37execute theSELECTstatement to fetch order header information into theorder_recvariable, from the current order number defined byordnums[order_index]. - Line
39calls theitems_fetchfunction to retrieve the order item lines for the current order, into theorditemsdynamic array. - Line
41returnsTRUE.