Getting Started with TRANSACT (32247-90007)

94 Chapter5
Automatic Error Handling and Prototyping
The main thing done to this version is to replace the automatic looping on data errors
until the data is valid with explicit programmatic looping until the errors are corrected.
Lines 1.21 to 1.26 define new variables to programmatically detect whether a data entry
form contains valid data or not. Valid can be viewed as a switch which is either yes or no
depending on whether the data entered is valid or not.
Lines 3.3, 3.4, 4.99, and 4.991 set up the boundaries of a loop that is executed until the
data entered is valid.
Within the loop, the valid flag will be set to indicate the data is invalid if an error is found.
However, before any data validation is done, line 3.5 sets the default for the flag to be that
the data is valid.
Line 4.9 changes the verb of the previous prototype from GET to FIND. GET was useful
when depending on the automatic error handling facility, because when we use GET,
Transact assumes that we know the data we want either exists or doesn't exist. Therefore
it is an error if the opposite condition occurs. When we use FIND though, Transact does
not assume that we know whether the data exists or not. In effect we are asking whether it
does exist or not. Therefore, it is not automatically an error if the data does not exist.
FIND tells us how many records it found by putting the number of records in the system
variable called STATUS. Lines 4.901 to 4.906 detect whether the user is attempting to add
an order that already exists. If so, line 4.904 uses the WINDOW option to highlight the
order-no field as being in error and to display the error message “order already exists” in
the VPLUS form window.
Lines 4.92 to 4.98 perform a similar validity check on the cust-no field. The only difference
is that the error occurs if there is no existing customer record.
Lines 8.1, 8.2, 9.996, and 9.997 set up a loop that will repeat until the data for an order
line item is valid.
Lines 9.91 to 9.97 validate the part-number.
Lines 9.98 to 9.995 perform an additional validation on the order quantity which we could
not do using automatic error handling.