Science Fiction by Mail
Order Processing Program

Time to complete This is a tough one. Allow 6 hours continuous.
Program Download SFbyMail.Cbl is a model answer. Don't look at this until you have made your own attempt at the program.
Example Output

See the Data Files with spaces inserted for easy viewing.
The contents of the Processed Orders file is shown as well as the Orders File and the Book Stock File both before and after processing.

Example Input

See the Data Files with spaces inserted for easy viewing.
The contents of the Processed Orders file is shown as well as the Orders File and the Book Stock File both before and after processing.

For the actual input files

Orders.Dat is the the sequential orders file

BSF-In.Dat is a sequential file that be converted into the indexed Book Stock File (BookStock.Dat) using the program Seq2BSF.Cbl.

The conversion program is required because Indexed files are not standard ASCII files and cannot be viewed or edited in a standard text application like Notepad.

If you want to view that contents of the indexed file you can convert it back to a sequential ASCII file using the program BSF2Seq.Cbl.

Subprograms

In a large software system, where a number of programmers are working on different subprograms, some programmers will finish before others. Programmers who have completed their work will want to test their programs. But if a completed program either CALLs, or is CALLed by, other programs, the programmer will have to wait for the other programs to be completed before any testing can be done. Obviously this not an acceptable state of affairs. The problem is usually solved by means of "stubs" and "drivers".

A"stub" is a small program that pretends to be a Called program. The stub, of course, does not provide anything like the functionality that the final subprogram will provide. It contains just enough code to allow the programmer to verify that his program is actually calling the subprogram and is passing and receiving the parameter values correctly. The stub might do this by providing a limited set of responses to a limited set of inputs or it might interrogate the user to allow him to provide a response to any input parameters.

A "driver" is the reverse of this. It is a small program that pretends to be the CALLing program. It contains just enough code to call the subprogram and to pass and receive the parameter values. Just as with the stub, the driver program might generate a very limited set of parameter values or might interrogate the user to obtain input parameters and might display the value of any output parameters.

Science Fiction by Mail calls two programs that are supposed to be written by others. Both of these programs have been provided as "stubs".

GetPostage.Cbl is the stub standing in for the real GetPostage subprogram

GetCustomerAddress.Cbl is the stub standing in for the real GetCustomerAddress.Cbl.

 

Major Constructs CALL, subprograms, Sequential files, Indexed files, READ, WRITE, REWRITE, COMPUTE, UNSTRING

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

 


Copyright Notice

This COBOL project specification is the copyright property of Michael Coughlan. You have permission to use this material for your own personal use but you may not reproduce it in any published work without written permission from the author.