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 FUNCTIONNote:
- Lines
06and11execute aSELECTto get a new order number from the database; if no rows are found, the order number is initialized to 1. - Lines
14thru47use theINPUTinteractive dialog statement to let the user input the order data. - Lines
25thru29theBEFORE INPUTblock initializes some members of theorder_recrecord, as default values for input. - Lines
31thru38theON CHANGEblock on thestore_numfield retrieves the customer name for the changedstore_numfrom thecustomertable, and stores it in thestore_namefield. If the customer doesn't exist in thecustomertable, an error message displays. - Lines
40thru45implement the code to open the zoom window of thestore_numBUTTONEDITfield, when the actionzoom1is triggered. The functiondisplay_custlistin the custlist.4gl module allows the user to select a customer from a list. The actionzoom1is enabled during theINPUTstatement only. - Line
56calls theorder_insertfunction to perform theINSERTSQL statement.