Example: orders.4gl (Function item_update)
This function implements the SQL row modification for an order item row.
Function
item_update (orders.4gl): 1 PRIVATE FUNCTION item_update(x INTEGER) RETURNS BOOLEAN
2
3 TRY
4 UPDATE items SET
5 quantity = orditems[x].quantity
6 WHERE items.stock_num = orditems[x].stock_num
7 AND items.order_num = order_rec.order_num
8 CATCH
9 CALL comutils.mbox_ok(title2,SQLERRMESSAGE)
10 RETURN FALSE
11 END TRY
12
13 MESSAGE msg09
14 CALL comp_order_total()
15 RETURN TRUE
16
17 END FUNCTIONNote:
- Line
1declares the function with thexinteger parameter representing the index in theorditemsarray, and returns a boolean to indicate if the SQL command succeeds. - Lines
4thru7implement the SQLUPDATEcommand, to modify the row from theitemstable that has thestock_numequal to the current order item of the list (orditems[x].stock_num), and the order number equal to the current order number (order_rec.order_num) - Lines
9and10are executed when an SQL error occurs, and returns from the function withFALSE. - Line
13shows a message to the user to indicate that the SQL operation succeeded. - Line
14re-computes the order total by calling thecomp_order_totalfunction. - Line
15returnsTRUEto the caller.