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 thegetLength
built-in function to determine the number of rows in the arrayarr_items
. - Lines
9
thru60
contain theINPUT ARRAY
statement. - Lines
12
and14
use aBEFORE ROW
clause to store the index of the current row of the array in the variablecurr_pa
. We also set theopflag
flag to "U", in order to indicate we are in update mode. - Lines
16
thru18
use aBEFORE INSERT
clause to set the value ofopflag
to "I" if the current operation is an Insert of a new row in the array. Line18
sets a default value for thequantity
. - Lines
20
thru22
AnAFTER INSERT
clause calls theitem_insert
function to add the row to the database table, passing the index of the current row and calls theitems_line_total
function, passing the index of the current row. - Lines
24
thru25
use aBEFORE DELETE
clause, to call the functionitem_delete
, passing the index of the current row. - Lines
27
thru29
contain anON ROW CHANGE
clause to detect row modification. Theitem_update
function and theitems_line_total
function are called, passing the index of the current row. - Lines
31
thru34
use aBEFORE FIELD
clause to prevent entry in thestock_num
field if the current operation is an update of an existing row. - Lines
36
thru44
implement the code for thezoom2
action, opening a list from thestock
table for selection. - Lines
46
thru52
use anON CHANGE
clause to check whether the stock number for a new record that was entered in the fieldstock_num
exists in thestock
table. - Line
62
uses thegetLength
built-in function to determine the number of rows in the array after theINPUT ARRAY
statement has terminated. - Line
63
calls the functionorder_total
, passing the number of rows in the array. - Lines
65
thru67
reset theINT_FLAG
toTRUE
if the user has interrupted theINPUT
statement.