Function order_new

This function handles the input of an order record.

Function order_new (orders.4gl):
01 FUNCTION order_new()
02   DEFINE id INTEGER, name STRING
03 
04   MESSAGE msg11
05   INITIALIZE order_rec.* TO NULL
06   SELECT MAX(order_num)+1 INTO order_rec.order_num 
07     FROM orders 
08   IF order_rec.order_num IS NULL
09    OR order_rec.order_num == 0 THEN
10      LET order_rec.order_num = 1
11   END IF 
12
13   LET int_flag = FALSE
14   INPUT BY NAME
15       order_rec.store_num, 
16       order_rec.store_name, 
17       order_rec.order_num, 
18       order_rec.order_date, 
19       order_rec.fac_code,
20       order_rec.ship_instr,
21       order_rec.promo 
22     WITHOUT DEFAULTS
23     ATTRIBUTES(UNBUFFERED)
24 
25     BEFORE INPUT
26        LET order_rec.order_date = TODAY
27        LET order_rec.fac_code = "ASC"
28        LET order_rec.ship_instr = "FEDEX"
29        LET order_rec.promo = "N"
30 
31     ON CHANGE store_num 
32        SELECT store_name INTO order_rec.store_name 
33          FROM customer 
34         WHERE store_num = order_rec.store_num 
35        IF (SQLCA.SQLCODE == NOTFOUND) THEN
36           ERROR msg12
37           NEXT FIELD store_num 
38        END IF
39 
40     ON ACTION zoom1
41        CALL display_custlist() RETURNING id, name 
42        IF (id > 0) THEN
43           LET order_rec.store_num = id 
44           LET order_rec.store_name = name 
45        END IF
46 
47   END INPUT
48 
49   IF (int_flag) THEN
50      LET int_flag=FALSE
51      CLEAR FORM
52      MESSAGE msg03
53      RETURN FALSE
54   END IF
55 
56   RETURN order_insert()
57  
58 END FUNCTION
Note:
  • Lines 06 and 11 execute a SELECT to get a new order number from the database; if no rows are found, the order number is initialized to 1.
  • Lines 14 thru 47 use the INPUT interactive dialog statement to let the user input the order data.
  • Lines 25 thru 29 the BEFORE INPUT block initializes some members of the order_rec record, as default values for input.
  • Lines 31 thru 38 the ON CHANGE block on the store_num field retrieves the customer name for the changed store_num from the customer table, and stores it in the store_name field. If the customer doesn't exist in the customer table, an error message displays.
  • Lines 40 thru 45 implement the code to open the zoom window of the store_num BUTTONEDIT field, when the action zoom1 is triggered. The function display_custlist in the custlist.4gl module allows the user to select a customer from a list. The action zoom1 is enabled during the INPUT statement only.
  • Line 56 calls the order_insert function to perform the INSERT SQL statement.