Example: orders.4gl (Function item_insert)
This function implements the SQL row creation for a new order item row.
Function
item_insert (orders.4gl): 1 PRIVATE FUNCTION item_insert(x INTEGER) RETURNS BOOLEAN
2
3 TRY
4 INSERT INTO items (
5 order_num,
6 stock_num,
7 quantity,
8 price
9 ) VALUES (
10 order_rec.order_num,
11 orditems[x].stock_num,
12 orditems[x].quantity,
13 orditems[x].price
14 )
15 CATCH
16 CALL comutils.mbox_ok(title2,SQLERRMESSAGE)
17 RETURN FALSE
18 END TRY
19
20 MESSAGE msg08
21 CALL comp_order_total()
22 RETURN TRUE
23
24 END FUNCTION
Note:
- Line
1declares the function with thexinteger parameter representing the index in theorditemsarray, and returns a boolean to indicate if the SQL command succeeds. - Lines
4thru15implement the SQLINSERTcommand, to insert a new row into theitemstable. - Lines
16and17are executed when an SQL error occurs, and returns from the function withFALSE. - Line
20shows a message to the user to indicate that the SQL operation succeeded. - Line
13re-computes the order total by calling thecomp_order_totalfunction. - Line
14returnsTRUEto the caller.