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 FUNCTION
Note:
- Lines
02
thru07
add the next unused order number to theorder_num
field of theorder_rec
program record, based on the existing order numbers in theorders
database table. - Lines
08
thru13
set the order total to zero, and add default values to someorder_rec
fields. - Lines
15
thru31
execute the SQL statement to insert a new row in theorders
database table using values from theorder_rec
program record. - Lines
32
thru36
clear the form and display an error message if the insert into the database table failed, and returnFALSE
to the calling function. - Line
37
inserts a new empty element into thearr_ordnums
array at the first position, after the successful insert into theorders
table. - Line
38
sets the value of the new element to the order number of theorder_rec
program record. Thearr_ordnums
array keeps track of the order numbers of the orders that were retrieved from the database or newly inserted. - Line
39
clears the program array foritems
, preparing for the addition of items for the new order. - Line
40
displays a message indicating the insert of a new row in theorders
database table was successful. - Line
42
returnsTRUE
to the calling function, indicating the insert into theorders
database table was successful.