Information Technology Reference
In-Depth Information
had nothing in it. We prevent this situation by the three statements in the program just
after the beginning
new-last-name = last-name
new-first-name = first-name
new-balance = balance ,
which move the old values of the names and balance to their corresponding new fields.
Thus a change to any of the fields will result in the new value but no change will find the
old value there. It won't hurt to move the old value if it didn't change before we write the
record. We could handle this another way by keeping track of the fields that change and
only move them to the appropriate fields when they change but that would mean more
variables and
if
statements and our approach will eliminate that.
The next lines
write acctfile
if acct-status > 0
error-msg = “update problem; program ending - press enter”
go to end-program
end-if
accomplish the rewriting of the record. This is done by writing the record from a specific
layout or structure, as given in the definition of the file. This keyword works similarly to
the read keyword. The modified record is written - rewritten, for you purists - but note
that at most three fields were changed. Once more we check the status. If there is a
problem we will not only not do the update, but we will also terminate the program
because there is a serious problem, moving an error message to be displayed on the
screen. If the update is successful, the operator can enter another account number.
All the statements have been covered so let me talk about the approach to
updating as well as records being unavailable. There are many ways to accomplish the
same results in our program. We could have initially opened the record for update but we
chose to do it only if an update was necessary. Doing it initially means we are locking
others out from the record when we may not even be updating it so our method will have
it frozen for a shorter period of time. Some systems lock the entire file, which we are not
doing. Our approach means records will be more available. We could also have locked
the record just before we made a change to one of the fields but the fact that the operator
is keying data and may have to change another of the three fields implies that the record
will be unavailable a great deal longer than if we were to use the approach we take. Our
method will only have the record unavailable to others for update for less than a second.
It is true that one of the other ways of reading the record for update may have
made the programming easier but we really want to avoid the situation where the record
is busy and can't be updated. Our means of getting the record for update should help to
Search WWH ::




Custom Search