Function order_new
This function inserts a new row in the database table orders, using
        the values from the order_rec program record.
Function 
order_new
            (orders.4gl)01 FUNCTION order_new()
02   SELECT MAX(order_num)+1 INTO order_rec.order_num 
03     FROM orders 
04   IF order_rec.order_num IS NULL
05    OR order_rec.order_num == 0 THEN
06     LET order_rec.order_num = 1
07   END IF
08  LET order_total = 0
09   -- We keep the same store...
10   LET order_rec.order_date = TODAY
11   LET order_rec.fac_code = "ASC"
12   LET order_rec.ship_instr = "FEDEX"
13   LET order_rec.promo = "N"
14
15   WHENEVER ERROR CONTINUE
16   INSERT INTO orders (
17      store_num,
18      order_num,
19      order_date,
20      fac_code,
21      ship_instr,
22      promo 
23   ) VALUES (
24      order_rec.store_num,
25      order_rec.order_num,
26      order_rec.order_date,
27      order_rec.fac_code,
28      order_rec.ship_instr,
29      order_rec.promo 
30   )
31   WHENEVER ERROR STOP
32   IF SQLCA.SQLCODE <> 0 THEN
33      CLEAR FORM
34      CALL __mbox_ok(title1,SQLERRMESSAGE,"stop")
35      RETURN FALSE
36   END IF
37   CALL arr_ordnums.insertElement(1)
38  LET arr_ordnums[1] = order_rec.order_num 
39   CALL arr_items.clear()
40   MESSAGE msg11
41   RETURN TRUE
42 END FUNCTIONNote: 
- Lines 
02thru07add the next unused order number to theorder_numfield of theorder_recprogram record, based on the existing order numbers in theordersdatabase table. - Lines 
08thru13set the order total to zero, and add default values to someorder_recfields. - Lines 
15thru31execute the SQL statement to insert a new row in theordersdatabase table using values from theorder_recprogram record. - Lines 
32thru36clear the form and display an error message if the insert into the database table failed, and returnFALSEto the calling function. - Line 
37inserts a new empty element into thearr_ordnumsarray at the first position, after the successful insert into theorderstable. - Line 
38sets the value of the new element to the order number of theorder_recprogram record. Thearr_ordnumsarray keeps track of the order numbers of the orders that were retrieved from the database or newly inserted. - Line 
39clears the program array foritems, preparing for the addition of items for the new order. - Line 
40displays a message indicating the insert of a new row in theordersdatabase table was successful. - Line 
42returnsTRUEto the calling function, indicating the insert into theordersdatabase table was successful.