| Usage / INPUT ARRAY control blocks | |
The AFTER ROW block is executed each time the user moves to another row, before the current row is left. This trigger can also be executed in other situations, such as when you delete a row, or when the user inserts a new row.
A NEXT FIELD instruction executed in the AFTER ROW control block will keep the user entry in the current row. Use this behavior to implement row validation and prevent the user from leaving the list or moving to another row.
When called in this block, the ARR_CURR() function return the index of the row that you are leaving.
INPUT ARRAY p_items WITHOUT DEFAULTS
FROM s_items.*
...
AFTER ROW
IF arr_curr()>0 AND arr_curr() <= arr_count() THEN
IF NOT item_is_valid_quantity(p_item[arr_curr()].item_quantity) THEN
ERROR "Item quentity is not valid"
NEXT FIELD item_quantity
END IF
END IF
...
INPUT ARRAY p_items WITHOUT DEFAULTS
FROM s_items.*
...
BEFORE INSERT
LET op = "T"
...
AFTER INSERT
LET op = "I"
...
AFTER ROW
IF op == "I" THEN
IF NOT item_is_valid_quantity(p_item[arr_curr()].item_quantity) THEN
ERROR "Item quentity is not valid"
NEXT FIELD item_quantity
END IF
WHENEVER ERROR CONTINUE
INSERT INTO items (item_num, item_name, item_quantity)
VALUES ( p_item[arr_curr()].* )
WHENEVER ERROR STOP
IF SQLCA.SQLCODE<0 THEN
ERROR "Could not insert the record into database!"
NEXT FIELD CURRENT
ELSE
MESSAGE "Record has been inserted successfully"
END IF
END IF
...