Information Technology Reference
In-Depth Information
The first statement
update-check: if update-switch = 1
determines whether we need an update or not. Recall that we set this field
update-switch
to 1 when a change was made and if there were no modifications, the value of this
variable would be 0. If
update-switch
is 1 we will have to read the account file for this specific record and lock the record so no
one else can have it for updating. The new keyword
update
will do just that in the line
read acctfile update
and we have seen this type of statement before except for the
update .
We now check the file status in the line
if acct-status = 3,
which will be the case if someone else has the record for updating. We won't be able to
do the update at this time. This means that the operator will have to try again by making
the changes later. If someone else is just reading the record, the status will not be 3 and
we'll be able to proceed. A status of 3 then produces a message by the statement
screen (24,20) “that record is unavailable - no update done”
and this will then get us back to enter another account number. I'll spend a bit more time
later on a record being busy and unavailable for update. Both reads in the program are
indexed reads since we're after a specific account number. In any read of this type, the
status will never be 9 - indicating the end of file condition - even if the record read is the
last record in the file.
The next lines
if acct-status > 0
error-msg = “update problem; program ending - press enter”
mean that we tried to do a read but somehow it failed. Since we were successful before as
we did display the data earlier, you might think that it should be successful now and it
really should. If the file status is 0, it means we got the record for updating and the next
lines
balance = new-balance
first-name = new-first-name
last-name = new-last-name
move the new values to the record before we write it. You might think that if we didn't
change first name the old value would be wiped out since
new-first-name
Search WWH ::




Custom Search