Function item_insert

This function inserts a new row into the items database table using the values input in the current array record on the form.

Function item_insert:
01 FUNCTION item_insert(curr_pa) 
02   DEFINE curr_pa SMALLINT
03 
04   WHENEVER ERROR CONTINUE
05   INSERT INTO items (
06      order_num,
07      stock_num, 
08      quantity, 
09      price 
10   ) VALUES ( 
11      order_rec.order_num, 
12      arr_items[curr_pa].stock_num,
13      arr_items[curr_pa].quantity,
14      arr_items[curr_pa].price 
15   )
16   WHENEVER ERROR STOP
17 
18   IF (SQLCA.SQLCODE == 0) THEN
19      MESSAGE msg08
20   ELSE
21      ERROR SQLERRMESSAGE
22   END IF
23 
24 END FUNCTION
Note:
  • Line 02 the index of the current row in the array is passed to this function and stored in the variable curr_pa.
  • Lines 05 thru 15 The embedded SQL INSERT statement uses the value of order_num from the current order record displayed on the form, together with the values from the current row of the arr_items array, to insert a new row in the items table.