Information Technology Reference
In-Depth Information
account-number
was initially set to
9 .
Assuming the read is without fail, the first account record is moved to the first element of
our array. The variable
i-sub
will be 1 to accomplish this but when we read the second record, it will be 2 and thus we
will move that record to the second element of our array. This will continue until we
reach the end of the file, which is found when
acct-status
is equal to 9. The lines
if acct-status = 9
process-sw = 1
record-count = i-sub - 1
else
error-msg = “problem reading the file; program aborting - press enter”
go to end-program
end-if
take care of that and note that we set
process-sw
to 1 so that our perform of the paragraph will end. One thing we don't want is the
program to keep looping and never end. We also set the variable
record-count
to 1 less than
i-sub .
We have to subtract that 1 because the variable
i-sub
at this point is 1 more than the number of records in the file since it will be in this
paragraph once more after the last record is read. We will use
record-count
later as we sort the table and also when we write out the records to a new file from our
sorted table. The final
else
will result if
acct-status
is neither 0 nor 9 and that means that there is something drastically wrong with our file.
This shouldn't happen but we put this code into our program just in case since there will
be times when problems can occur that are out of our control. That takes care of the
reading of our file and loading to the array.
We will come back to the actual sort in a while but next let us consider
write-file: new-record = c-element(i-sub)
Search WWH ::




Custom Search