Tutorial Chapter 11: Master/Detail / The Orders Program orders.4gl |
This function handles the input of an order record.
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