Introduction
Science Fiction by Mail is a company which sells Science Fiction and Fantasy books through the Internet. Customers view the book catalogues and place orders by connecting to the company's web site. When an order is placed, an Order-Number is assigned, and the details of the order are written to an Orders file (ORDERS.dat). Only already registered customers can place an order.
At the end of the day, the Orders file is processed, applying it to the Book Stock file and producing a Processed Orders file. The Processed Orders file is used by other programs (not required for this exam) to bill the customers and to produce invoices and address labels.
For each book title required in an order, the Book Stock File must be updated by subtracting the Qty-Required from the Qty-In-Stock. When a book request cannot be filled because there is insufficient stock, this must be indicated by writing zeros to the Quantity-Required field of the Processed-Orders record. The Book Stock file must not be updated.
A program is required to apply the Orders file to the Book Stock file and produce the Processed Orders file.
File Descriptions
The Orders File (Sequential)
The Orders file is an unsorted, validated, sequential file. Each record may contain an order for up to 10 different book titles. Where all ten titles are not requested the rest of the record is space filled.
The Book-Details are held in a ten element table. Each element consists of the Book-Id and the Qty-Required. The record description is as follows;
|
Field |
Type |
Length |
Occurrence |
Order-Number |
X |
7 |
1 |
Customer-Id |
X |
5 |
1 |
Book-Details |
Group |
- |
10 |
Book-Id |
X |
5 |
- |
Qty-Required |
9 |
2 |
- |
In the following example record spaces have been inserted for convenience.
1234567 C1234 B1234 01 B2345 03 B3456 02
The order number in this record is 1234567, the Customer-Id is C1234 and 3 different titles have been requested. One copy of B1234, three copies of B2345 and two copies of B3456 have been ordered.
Book Stock File (Indexed)
The Book Stock file holds details of the company's stock of books. It is an indexed file containing records with the following description;
|
Field |
Key type |
Type |
Length |
Value |
Book-Id |
Primary |
X |
5 |
- |
Book-Title |
ALT |
X |
20 |
- |
Author-Id |
ALT with Duplicates |
9 |
4 |
- |
Qty-In-Stock |
-- |
9 |
3 |
0-999 |
Copy-Price |
-- |
9 |
4 |
01.50-99.99 |
Processed Orders File (Sequential)
The Processed Orders file is a sequential file. For each book title requested in the Orders File, a record must be created in the Processed Orders File. The record description is as follows;
|
Field |
Type |
Length |
Value |
Order-Number |
X |
7 |
- |
Customer-Id |
X |
5 |
- |
Book-Title |
X |
20 |
- |
Qty-Required |
9 |
2 |
0-99 |
Title-Cost |
9 |
5 |
0.50-999.99 |
Title-Postage |
9 |
4 |
1.50-99.99 |
Sub Programs
The Copy-Postage may be obtained by calling two external subprograms. These subprograms have already been written and you may assume that they will be present in the same directory where your program is run.
GetCustomerAddress is a subprogram that takes two parameters
IN Customer-Id PIC X(5)
OUT Cust-Address PIC X(40)
Cust-Address contains the customer address. The parts of the customer address are separated from one another by commas. The last item in the customer address is a two character Country-Code. This code must be extracted from the customer address and then used to obtain the Copy-Postage (cost of posting one book to the customer).
Example address = 13 Winchester Drive, Castletroy, Limerick, Ireland, IE
GetPostage is a subprogram that takes two parameters
IN Country-Code PIC XX
OUT Copy-Postage PIC 99V99