Example: orders.4gl (Function item_delete)
This function implements the SQL row deletion for an order item row.
Function
item_delete
(orders.4gl): 1 PRIVATE FUNCTION item_delete(x INTEGER) RETURNS BOOLEAN
2
3 TRY
4 DELETE FROM items
5 WHERE items.stock_num = orditems[x].stock_num
6 AND items.order_num = order_rec.order_num
7 CATCH
8 CALL comutils.mbox_ok(title2,SQLERRMESSAGE)
9 RETURN FALSE
10 END TRY
11
12 MESSAGE msg10
13 CALL comp_order_total()
14 RETURN TRUE
15
16 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
3thru10implement the SQLDELETEcommand, to remove 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
8and9are executed when an SQL error occurs, and returns from the function withFALSE. - Line
12shows 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.