Function items_inpupd

This function contains the program logic to allow the user to input a new row in the arr_items array, or to change or delete an existing row.

Function items_inpupd:
01 FUNCTION items_inpupd()
02   DEFINE opflag CHAR(1),
03          item_cnt, curr_pa SMALLINT,
04          id INTEGER
05 
06   LET opflag = "U"
07  
08   LET item_cnt = arr_items.getLength()
09   INPUT ARRAY arr_items WITHOUT DEFAULTS FROM sa_items.*
10     ATTRIBUTES (UNBUFFERED, INSERT ROW = FALSE)
11 
12     BEFORE ROW
13       LET curr_pa = ARR_CURR() 
14       LET opflag = "U"
15 
16     BEFORE INSERT
17       LET opflag = "I"
18       LET arr_items[curr_pa].quantity = 1
19 
20     AFTER INSERT
21       CALL item_insert(curr_pa)
22       CALL items_line_total(curr_pa)
23 
24     BEFORE DELETE
25       CALL item_delete(curr_pa)
26 
27     ON ROW CHANGE
28       CALL item_update(curr_pa)
29       CALL items_line_total(curr_pa)
30 
31     BEFORE FIELD stock_num 
32       IF opflag = "U" THEN
33          NEXT FIELD quantity 
34       END IF
35 
36     ON ACTION zoom2
37        LET id = display_stocklist()
38        IF id > 0 THEN
39           IF (NOT get_stock_info(curr_pa,id) ) THEN
40              LET arr_items[curr_pa].stock_num = NULL
41           ELSE
42              LET arr_items[curr_pa].stock_num = id 
43           END IF
44        END IF
45 
46     ON CHANGE stock_num 
47        IF (NOT get_stock_info(curr_pa,
48                       arr_items[curr_pa].stock_num) ) THEN
49           LET arr_items[curr_pa].stock_num = NULL
50           ERROR msg07
51           NEXT FIELD stock_num 
52        END IF
53 
54     ON CHANGE quantity 
55        IF (arr_items[curr_pa].quantity <= 0) THEN
56           ERROR msg13
57           NEXT FIELD quantity 
58        END IF
59 
60   END INPUT
61 
62   LET item_cnt = arr_items.getLength()
63   CALL ord_total(item_cnt)
64 
65   IF (int_flag) THEN
66      LET int_flag = FALSE
67   END IF
68 
69 END FUNCTION
Note:
  • Line 08 uses the getLength built-in function to determine the number of rows in the array arr_items.
  • Lines 9 thru 60 contain the INPUT ARRAY statement.
  • Lines 12 and 14 use a BEFORE ROW clause to store the index of the current row of the array in the variable curr_pa. We also set the opflag flag to "U", in order to indicate we are in update mode.
  • Lines 16 thru 18 use a BEFORE INSERT clause to set the value of opflag to "I" if the current operation is an Insert of a new row in the array. Line 18 sets a default value for the quantity.
  • Lines 20 thru 22 An AFTER INSERT clause calls the item_insert function to add the row to the database table, passing the index of the current row and calls the items_line_total function, passing the index of the current row.
  • Lines 24 thru 25 use a BEFORE DELETE clause, to call the function item_delete, passing the index of the current row.
  • Lines 27 thru 29 contain an ON ROW CHANGE clause to detect row modification. The item_update function and the items_line_total function are called, passing the index of the current row.
  • Lines 31 thru 34 use a BEFORE FIELD clause to prevent entry in the stock_num field if the current operation is an update of an existing row.
  • Lines 36 thru 44 implement the code for the zoom2 action, opening a list from the stock table for selection.
  • Lines 46 thru 52 use an ON CHANGE clause to check whether the stock number for a new record that was entered in the field stock_num exists in the stock table.
  • Line 62 uses the getLength built-in function to determine the number of rows in the array after the INPUT ARRAY statement has terminated.
  • Line 63 calls the function order_total, passing the number of rows in the array.
  • Lines 65 thru 67 reset the INT_FLAG to TRUE if the user has interrupted the INPUT statement.