Information Technology Reference
In-Depth Information
since the definition of the file points to the key as
account-number.
The file status is checked as in our original program. Here we have an indexed read. If the
read doesn't find that particular record, the result is a not found condition - status being a
5. If the read is successful, the program will display the values of each field for the record
that was read and the user can now enter another account number or exit the program. For
invalid account numbers entered, a message will print on line 24 starting in column 20
listing the invalid input. The keyword
else
gives us options so we will either read another record or be at the end of the program.
This is another keyword which we have not seen with if statements. We actually cover
three cases for the file status, 0, 5 and anything else. The error message
Problem with the account file; program ending - press enter
could result if the file didn't exist or there was some other problem.
You may ask why we need to restrict the account number input to numeric as the
read of the file would take care of that. We could take whatever was entered and try to
access the file. If the field keyed is not numeric we would get a not found and that
wouldn't be a problem, except the operator will have to input another account number,
slowing down the input process. If the field is numeric, the record desired may be on the
file, but maybe not. Each case would be handled. We could allow
character (9)
but then the user would have to key in leading zeros. Being defined as
integer (9)
is a better choice since it saves keying.
If you have just an if statement or a combination of if and else, you only need one
end-if .
We could also have written the code for checking the status as
if acct-status = 0
screen (4,36) account-number
screen (6,36) last-name
screen (8,36) first-name
screen (10,36) middle-initial
screen (12,36) street-address
screen (14,36) city
screen (16,36) state
screen (18,36) zip-code
screen (20,36) balance, mask ($$$$,$$9.99-)
go to input-number
end-if
if acct-status = 5
screen (24,20) β€œThe account number ” account-number β€œ is not on the file.”
go to input-number
end-if
Search WWH ::




Custom Search