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 FUNCTIONNote: 
- Line 
08uses thegetLengthbuilt-in function to determine the number of rows in the arrayarr_items. - Lines 
9thru60contain theINPUT ARRAYstatement. - Lines 
12and14use aBEFORE ROWclause to store the index of the current row of the array in the variablecurr_pa. We also set theopflagflag to "U", in order to indicate we are in update mode. - Lines 
16thru18use aBEFORE INSERTclause to set the value ofopflagto "I" if the current operation is an Insert of a new row in the array. Line18sets a default value for thequantity. - Lines 
20thru22AnAFTER INSERTclause calls theitem_insertfunction to add the row to the database table, passing the index of the current row and calls theitems_line_totalfunction, passing the index of the current row. - Lines 
24thru25use aBEFORE DELETEclause, to call the functionitem_delete, passing the index of the current row. - Lines 
27thru29contain anON ROW CHANGEclause to detect row modification. Theitem_updatefunction and theitems_line_totalfunction are called, passing the index of the current row. - Lines 
31thru34use aBEFORE FIELDclause to prevent entry in thestock_numfield if the current operation is an update of an existing row. - Lines 
36thru44implement the code for thezoom2action, opening a list from thestocktable for selection. - Lines 
46thru52use anON CHANGEclause to check whether the stock number for a new record that was entered in the fieldstock_numexists in thestocktable. - Line 
62uses thegetLengthbuilt-in function to determine the number of rows in the array after theINPUT ARRAYstatement has terminated. - Line 
63calls the functionorder_total, passing the number of rows in the array. - Lines 
65thru67reset theINT_FLAGtoTRUEif the user has interrupted theINPUTstatement.