Introduction
Newtronics Plc. is a company which sells electronic parts (diodes, transistors, IC's, LED's thermostats etc.) and goods. Currently, the company is being computerised and you have been retained to write one of the programs required.
Information about the parts and goods held in stock by the company is contained in two files; the Stock Master File and the Supplier Master File. Adjustments to stock, such as selling an item or receiving new supplies into stock are made on-line by an update program written by others. File maintenance (Insertion, Deletion and Adjusting of records) to the master files will be achieved by applying a file of transaction records to them at the end of each day. Your task is to write the program which will take the Transaction file and apply it to the master files.
The Transaction File
The Transaction File is a unsorted, unvalidated file containing a number of different types of transaction record. Each transaction record type is identified by a transaction type code in the first character position. The following transaction types have been identified :-
| Trans Type | Description |
|---|---|
| 1 | Delete Stock Record |
| 2 | Insert Stock Record |
| 3 | Adjust Reorder Level |
| 4 | Adjust Reorder Qty |
| 5 | Adjust Price |
| 6 | Delete Supplier Record |
| 7 | Insert Supplier Record |
Transaction Record Descriptions
Descriptions of the different types of transaction record are shown below.
Delete Stock Record
| FieldName | Type | Length | Format |
|---|---|---|---|
| Transaction-Type | Numeric | 1 | Value 1 |
| Stock-Number | Character | 7 | 9999999 |
Insert Stock Record
| FieldName | Type | Length | Format |
|---|---|---|---|
| Transaction-Type | Numeric | 1 | Value 2 |
| Stock-Number | Numeric | 7 | 9999999 |
| Qty-In-Stock | Numeric | 5 | 99999 |
| Price | Numeric | 6 | 9999.99 |
| Reorder-Level | Numeric | 3 | 999 |
| Reorder-Qty | Numeric | 5 | 99999 |
| Supplier-Number | Character | 4 | X999 |
Adjust Reorder Level
| FieldName | Type | Length | Format |
|---|---|---|---|
| Transaction-Type | Numeric | 1 | Value 3 |
| Stock-Number | Numeric | 7 | 9999999 |
| Reorder-Level | Numeric | 3 | 999 |
Adjust Reorder Qty
| FieldName | Type | Length | Format |
|---|---|---|---|
| Transaction-Type | Numeric | 1 | Value 4 |
| Stock-Number | Numeric | 7 | 9999999 |
| Reorder-Qty | Numeric | 5 | 99999 |
Adjust Price
| FieldName | Type | Length | Format |
|---|---|---|---|
| Transaction-Type | Numeric | 1 | Value 5 |
| Stock-Number | Numeric | 7 | 9999999 |
| Price | Numeric | 6 | 9999.99 |
Delete Supplier Record
| FieldName | Type | Length | Format |
|---|---|---|---|
| Transaction-Type | Numeric | 1 | Value 6 |
| Supplier-Number | Character | 4 | X999 |
Insert Supplier Record
| FieldName | Type | Length | Format |
|---|---|---|---|
| Transaction-Type | 9 | 1 | Value 7 |
| Supplier-Number | X | 4 | X999 |
| Supplier-Name | X | 20 | - |
| Supplier-Address | X | 35 | - |
The Master Files
The Stock Master File
The Stock Master File is an Indexed file with the following record description.
| FieldName | Key type | Type | Length | Format |
|---|---|---|---|---|
| StockNumber | Primary | 9 | 7 | 9999999 |
| QtyInStock | 9 | 5 | 99999 | |
| Price | 9 | 6 | 9999.99 | |
| ReorderLevel | 9 | 3 | 999 | |
| ReorderQty | 9 | 5 | 99999 | |
| SupplierNumber | ALT with Duplicates | X | 4 | X999 |
The Supplier Master File
The Supplier Master File is an Indexed file with the following record description.
| FieldName | Key type | Type | Length | Format |
|---|---|---|---|---|
| SupplierNumber | Primary | X | 4 | X999 |
| SupplierName | ALT with Duplicates | X | 20 | - |
| SupplierAddress | X | 40 | - |
The Stock Archive File
The Stock Archive File is a sequential file with the following record description.
| FieldName | Type | Length | Format |
|---|---|---|---|
| StockNumber | 9 | 7 | 9999999 |
| QtyInStock | 9 | 5 | 99999 |
| Price | 9 | 6 | 9999.99 |
| ReorderLevel | 9 | 3 | 999 |
| ReorderQty | 9 | 5 | 99999 |
| SupplierNumber | X | 4 | X999 |
The Error File
The Error File is an unordered Sequential File. Records in the Error File have the same format as those in the Transaction File.
Validation Requirements
For the sake of efficiency, the Transaction File should be sorted on ascending TransactionType within ascending StockNumber before the records are applied to the Master Files. Some of the validation can be done before the Sort executes and should be done in an Input Procedure. The rest of the processing should be done in an Output Procedure.
When an error occurs the transaction record should be written to an Error File. Records in the Error File have the same format as those in the Transaction File. As soon as an error is found in a transaction record, the record should be written to the Error File and no further checking should be done.
General Validation
Ensure that the Transaction-Type is numeric and within range 1 to 7.General Transaction Record Validation
Ensure that the Stock-Number is numeric and that the check digit is correct (implement check digit validation as a contained sub-program with no Global data).Delete Stock Record Special Validation
Ensure that the record does exist in the master file and that the Qty-In-Stock in the master file record is zero. If all is OK write the Stock Master File record to the Stock Archive File and then delete the master file record.Insert Stock Record Special Validation
Ensure that the record does not already exist and that there is a corresponding record in the Supplier Master File. Ensure that the Qty-In-Stock, Price, Reorder-Level and Reorder-Qty fields are numeric and initialized to zero. If all is OK insert the record.Adjust Special Validation
Ensure that the record does exist in the master file. If all is OK update the master record.Insert Supplier Record Special Validation
Ensure that the record does not already exist. If all is OK then insert the record.Delete Supplier Record Special Validation
Ensure that the record does exist and that there are no records with this SupplierNumber left in the Stock Master File. If all is OK delete the master file record.
Validating The StockNumber Check Digit
The StockNumber is a seven digit number with the seventh (rightmost) digit being the calculated check digit. Each of the real digits ( the first six) has a weight associated with it. Starting from the leftmost digit the weights are as follows:-
D1 = 7, D2 = 6, D3 = 5, D4 = 4, D5 = 3, D6 = 2.
In the StockNumber the check digit modulus is 11. The check digit can be calculated as follows:-
Multiply each digit by its weight and add the results together. Divide the sum of the results by the modulus 11 and subtract the remainder from the modulus. The result is the check digit. The check digit in your student number is calculated in exactly the same way so any valid student number will be a valid StockNumber.
Here is an example:-
StockNumber = 7944454 Real Number = 794445 Check Digit = 4
Digit D1 D2 D3 D4 D5 D6 * * * * * *
Weight 7 6 5 4 3 2
---- ---- ---- ---- ---- ----
Result R1 + R2 + R3 + R4 + R5 + R6 = Sum Of Results
Digit 7 9 4 4 4 5
* * * * * *
Weight 7 6 5 4 3 2
---- ---- ---- ---- ---- ----
Result 49 + 54 + 20 + 16 + 12 + 10 = 161
StockNumbers that yield check digits of 10 and 11 are invalid StockNumbers.
So the check digit is 4.
If you only want to discover whether a check digit is correct or not then get the Sum Of Results as above, add the check digit to it and divide by 11. If there is no remainder then the check digit is correct.