PRACTICE Lab2
Problem
ISBN
number - format 9-999-99999-9
Book
title - alphanumeric length 20
Author
Name -
First Name:
alphabetic length 10
Middle Initial:
alphabetic length 1
Last Name:
alphabetic length 12
On
SAMPLE
INPUT RECORDS:
0-123-45678-9title
of book
#1 John
EBoy
01012001
2-345-67890-1title
of book
num 2 Sivaramen JPanda 12102001
4-567-89012-3title
of book
no 3 Laura
BConstantine 03122002
OUTPUT:
Page
heading centered
(blank line)
Column
headers
(blank line)
Data
centered under each column header in the following order:
Last
Name, First Name, Middle initial in the
format:
xxxxxxxxxxxxxxx, xxxxxxxxxx
x.
Book Title
ISBN number
On
(blank line)
END OF
REPORT
WORKING THROUGH
THE SOLUTION…
The
solution to the problem is to move the input record data to an
output record for printing, but some questions occur…
1.
What type and length is the ISBN
number?
a.
One solution is to declare this
field X(13). Since you don’t need to
split up or use the
individual numeric values in any way, this is the best solution.
b.
Another possibility is to read
the ISBN number as
individual pieces of data. For instance, pic
9,
pic x, pic
999, pic x, pic
99999, pic x and pic
9, where the pic x denotes the dash
symbols. However, moving all
these individual memory locations into the output buffer record would
be a
pain!
2.
How am I going to get the
Author’s name to be in a
different order?
In order to get the name in a different
order and add a comma and a period to the output record name
information, you
will need to read in the data separately. However, there are two
different ways to do this! The question is,
do
you want/need a group item (i.e. author-name) to describe the 3
individual data
items?
05 author-name-in.
10 first-name-in
pic X(10) or A(10)
10 middle-init-in
pic x or a
10 last-name-in
pic x(12) or A(12)
Or would it be okay to drop the 05
author-name-in, and just make the three elementary items below at the
05 level
instead of the 10 level. Since you usually don’t know the answer
to this
question when you are just starting to write the program, it is always
a good
idea to use a group item as it can’t hurt. Now you are ready to
move the
name into the output record buffer. The output buffer record
portion for
the author name can be:
05 author-name-out.
10 last-name-out
pic x(12).
10 pic
xx value “, “.
10 first-name-out
pic x(10).
10 pic
x value space.
10 middle-init-out
pic x.
10 pic
x value “.”
Notice that there may be some blanks
between the last name and the comma since not all the last names will
be of
length 12. We will solve this problem in
the future! In the procedure division,
you have to move first-name-in to first-name-out, middle-init-in to
middle-init-out and last-name-in to last-name-out (yes, three separate
move
statements) before you can write the output buffer (remember, you
always have
to fill up the entire output buffer before writing).
Another issue to think about is that the
output buffer also needs to print the page and column headings as well. So, another possible solution is to put input
buffer information into working-storage then move this information into
a
generic output buffer:
FD output-file.
01
output-rec
pic x(80).
Where 80 is the longest possible line for a
piece of output data
that you need.
3.
How is the date going to get the
/ symbol between
the month, day and year?
I am not going to go into detail here
about this solution :o) however, you will need to do it in the same way
the
author name problem was solved! See
below code!
GENERIC SOLUTION
FD input-file.
01 input-rec.
05 isbn-number
pic x(13).
05 book-title pic
x(20).
05 author-name-in.
10 first-name-in pic X(10).
10 middle-init-in
pic X.
10 last-name-in pic x(12).
05 on-sale-date.
10 month-in pic
99.
10 day-in pic
99.
10 year-in pic
9999.
FD output-file.
01 output-rec
pic x(70).
.......... working storage section
01 ws-input-data.
05 ws-author-name.
10 ws-last-name pic
x(12).
10 pic xx value “, “.
10 ws-first-name pic
x(10).
10 pic x value space.
10 ws-middle-init pic
x.
10 pic x value “.”
05 ws-book-title
pic x(20).
05 ws-isbn-number pic
x(13).
05 ws-on-sale-date.
***** continue solution here!
01 ws-page-header.
05 pic
x(27)
value spaces.
05 pic
x(15)
value “HOME BOOK STORE”.
05 pic
x(28) value
spaces.
01 ws-column-header.
***** continue
solution here!
*****
procedure division
Open input and
output files
Write page and
column headers (including blank lines after each)
Read the first
record
Perform paragraph
until end of file
Write
“end of report”
line
Close
files
Stop
run
*****
in
paragraph
Move isbn-number to ws-isbn-number
Move book-title to ws-book-title
Move last-name-in to ws-last-name
Move middle-init-in to ws-middle-init
Move first-name-in to ws-first-name
Move date information to fill up ws-on-sale-date!
Write output-rec from ws-input-data
Read next record