CHAPTER 13

 

SEQUENTIAL FILE PROCESSING

 

 

CHAPTER OBJECTIVES

 

Upon completion of this chapter, the student should be able to:

 

1.         Distinguish between a master file and a transaction file.

 

2.         Explain the procedures for a typical sequential master file update.

 

3.         Explain the purpose of a control listing or audit trail.

 

4.         Explain the types of validation that should be performed during an update procedure.

 

5.                  Explain the differences in logic when coding for a single transaction record per master record as opposed to multiple transaction records for the same master record.

 

6.         Describe how the Balanced Line Algorithm works.

 

7.         Explain how a sequential file is updated in place.

 

8.         Explain the purpose of activity-status codes.

 

9.         Explain the purpose of the OPEN EXTEND statement and demonstrate its use.

 

10.       Describe situations in which it would be appropriate to compare the key fields of records from separate files for checking purposes.


LECTURE OUTLINE

 

I.          Systems Overview of Sequential File Processing

 

A.        Master Files

 

1.         A master file is the major collection of data pertaining to a specific application.

 

2.         Master files are stored on magnetic media because disk files:

a.         Can store very large files.

b.         Can read and write data very quickly.

c.         Can store records of any size.

 

3.         Disk files can be processed either sequentially or randomly, while tapes can only be processed sequentially.

 

4.         Tapes are not used much anymore.

 

B.         Typical Master File Procedures: A Systems Overview

 

1.         When designing a master file, the following elements should be considered:

a.         Determine whether the file should be organized for sequential or random processing.

b.         The first field or fields should be key fields that uniquely identify the record.

c.         Where possible, key fields should consist of numbers.

d.         Secondary key fields should follow primary key fields in a record.

e.         Fields should appear in order of importance.

f.          Be sure that fields are large enough to accommodate the data.

g.                   Use coded fields where possible to save space.

h.                   Define all date fields with a four-digit year in order to make them Y2K-compliant.

 

2.         The primary objective of a program that creates a master file is ensuring data integrity.

 

3.         Change records are stored in a transaction file.  File design and data integrity issues should be applied to the development of the transaction file.


4.         Updating is the process of making a master file current.  A master file is updated by incorporating the changes from the transaction file.

 

5.         The purpose of maintaining a master file is to store data that will provide users with meaningful output.

a.         Scheduled reports are produced on a regular basis.

b.         On demand output, which is either in report or display form, is produced on request.

 

                        6.         Creating Original Master and Transaction Files for New Systems.

 

 

II.         Sequential File Updating - Creating a New Master File

 

A.        Files Used

 

1.         Three files are used in a sequential update:

a.         The input master file contains information current through the previous updating period.

b.         The input transaction file contains data to be used for updating the master file.

c.         The output (updated) master file incorporates current transactions with previous master information.

 

2.         A fourth file, a control listing or audit trail, is usually produced during a sequential file update for error control purposes.  This print file should list:

a.         Changes made to the master file.

b.         Errors encountered during processing.

c.         Totals to be used for control and checking purposes.

 

B.         Ordering of Records for Sequential Updates

 

1.         In a sequential master file, all records are in sequence by a key field.

 

2.         The transaction file must also be in the same key field sequence.

 

C.        Procedures Used For Sequential Updates

 

This section develops logic for a sequential file update in which there is at most one transaction record for each master record.

 

1.         A record is read from each file immediately after the files are opened.

 


2.         The key fields from the master and transaction records are compared to determine what processing should be done:

a.         When a record exists on the master file with a corresponding transaction record (TRANS-KEY = MASTER-KEY):

i.          The master record is updated and written to the new master file.

ii.          Records are read from both the master and transaction files.

 

b.         When there is a record on the master file with no corresponding transaction record (TRANS-KEY > MASTER-KEY):

i.          No updating occurs.  The old master record is written to the new master file as is. 

ii.          A record is read from the old master file.

 

c.         When a record exists on the transaction file for which there is no corresponding record on the master file (TRANS-KEY < MASTER-KEY):

i.          Either a new record is created from the transaction record or an error has occurred, depending on the type of update being performed.

ii.          In either case, after the transaction is processed, a record is read from the transaction file only.

 

3.         Since both the end of the old master file and the end of the transaction file will not be reached at the same time, some provision must be made so processing continues properly:

a.         HIGH-VALUES can be moved to the key field of the file which has reached end-of-file to ensure that records from the other file will continue to be processed correctly.

b.         Processing continues until the key fields of both the master and transaction input records contain HIGH-VALUES.

 

4.         HIGH-VALUES is a COBOL reserved word which refers to the largest value in the computer's collating sequence.  HIGH-VALUES means that all bits are on.

 

III.       Validity Checking in Update Procedures

 

A.        Checking for New Accounts

 

1.         Data validation techniques should be incorporated to minimize errors during a master file update procedure.

 


2.         New records to be added to a master file usually include a coded field to indicate that this is, in fact, an addition.  A check should be made to verify that a transaction record with no corresponding master record is an addition.  Similarly, the coded field should be used to identify a transaction as an update.

 

B.         Checking for Delete Codes and Deleting Records from a Sequential Master File

 

1.         The master file update procedure must provide for eliminating or deleting records.

 

2.         Deleting a record is accomplished by bypassing the corresponding record from the old master file, therefore not writing it to the new master file.

 

3.         The coded field technique is used to identify if a record is to be deleted from the master file.

 

4.         A transaction coded as a deletion is processed in the update module (TRANS-KEY = MASTER-KEY).

 

5.         A valid deletion is processed by coding CONTINUE, which indicates that no action is to be taken.  New records are then read from both the master and transaction files.

 

C.        Checking for Sequence Errors

 

1.         Records in both the master file and the transaction file must be in the same key field sequence.

 

2.         If the possibility for a sequence error exists, include one of the following in the update procedure:

a.         a sequence check in the program.

b.         a sort procedure executed prior to the update procedure.

 

IV.       Update Procedures with Multiple Transaction Records for Each Master Record

 

A.        For some applications, more than one change record may exist in the transaction file for a given master file record.

 

B.         For multiple transaction records, the update routine contains a loop that processes all transactions for a particular master record before writing the updated record to the new master file.


V.                 The Balanced Line Algorithm for Sequential File Updating

 

A.                 The balanced line algorithm is viewed by many as the most efficient and effective sequential file update method.

 

B.                 The WORKING-STORAGE fields that control the logic of the algorithm are:

 

1.                  WS-CONTROL-KEY, which holds the value of the key currently being processed.  This field systematically contains each unique value of the key field found in either (or both) the old master file and the transaction file.

 

2.                  A flag WS-ALLOCATED-SWITCH, which serves different functions depending upon the portion of logic being executed.

 

C.                 The following steps are executed once for each unique value of WS-CONTROL-KEY:

 

1.                  The old master file is processed.

a.                   If there is an old master record matching WS-CONTROL-KEY, then

i.                     The switch WS-ALLOCATED-SWITCH is set to “YES”.

ii.                   The old master record is moved to the new master record area, where any updates to the record will be made.

iii.                  The next record is read from the old master file.

b.         If there is no current master record matching WS-CONTROL-KEY, then the switch WS-ALLOCATED-SWITCH is set to “NO”.

 

2.                  All transaction records for the current value of WS-CONTROL-KEY are processed.  The switch WS-ALLOCATED-SWITCH serves two functions at this point of the algorithm:  first, it is used to determine whether the action requested by the transaction is valid, and second, its value is changed when the transaction involves adding or deleting a record.  The specific categories of transactions are processed as follows:

a.                   For an addition to be valid, WS-ALLOCATED-SWITCH must contain the value “NO”.  The record is added by setting up the new master record and moving “YES” to WS-ALLOCATED-SWITCH.

b.                  Changes are valid when WS-ALLOCATED-SWITCH contains “YES”.  In this case, the master record (which is located in the new master record area) is updated as specified by the transaction.

c.                   Deletions are valid if WS-ALLOCATED-SWITCH = “YES”.  To delete a record, the only action taken at this point is to move “NO” to WS-ALLOCATED-SWITCH.


 

3.                  The new master file is processed.

a.                   If WS-ALLOCATED-SWITCH = “YES”, then the data located in the new master record area is written to the new master file.

b.                  If WS-ALLOCATED-SWITCH = “NO”, then no action is taken.

 

4.                  The next value of WS-CONTROL-KEY is chosen.  The value selected is always the smaller of the two key values contained in the next records available in the old master and transaction files.

 

D.                 The above process is repeated until all records in each input file have been processed.

 

1.                  When either file runs out of records, HIGH-VALUES is moved to the key field of that file’s record area.

 

2.                  This use of HIGH-VALUES guarantees that any remaining records in the other file will be processed, because their key values will always be less than HIGH-VALUES.

 

3.                  When the key fields of both files contain HIGH-VALUES, the next value selected for WS-CONTROL-KEY will be HIGH-VALUES.  This serves as the signal that both files have been completely processed.

 

VI.       Sequential File Updating - Rewriting Records on a Disk

 

A.        REWRITE Statement for a Disk File Opened as I-O

 

1.         Disk files can serve as both input and output during the same run.  Thus, it is possible to read a record, make changes to the record, and update the record in place.

 

2.         For this type of update procedure, only two files are required:

a.         The master file.

b.         The transaction file.

 

3.         The major changes in the update logic are:

a.         The master file is opened as I-O, which allows records to be read and written back to it.

b.         Master file records that have no corresponding transaction record are bypassed by reading the master file in a loop until a master is found that matches the key field of the current transaction record.

c.         The REWRITE statement is used to place updated records back on the master file.

 

4.         Since all changes are made directly to the master file, it is good practice to create a backup copy of the master file before executing the update procedure and to create a control listing during the file update.

 

B.         Using an Activity-Status Field for Designating Records to be Deleted

 

1.         When a sequential file is updated in place, a special procedure is needed for deleting records.  A common technique is to place an activity-status code at the beginning of each record.

 

2.         The activity-status field identifies whether a record is active or inactive:

a.         The activity-status field code is set to active when master records are created.

b.         The code is changed to inactive when the record is deleted.

 

3.         Records that are inactive are not physically deleted from the file. 

 

4.         The activity-status code must be checked prior to processing any record so that only active records are processed.

 

C.        The EXTEND Option for Adding Records to the End of a Sequential File

 

1.         It is not possible to add a record in sequence to a sequential master file that has been opened as I-O.  There is no physical gap in the file where the records could be inserted in their proper place.

 

2.         Records may be added to the end of a sequential disk (or tape) file if the OPEN EXTEND statement is executed.

 

3.         When the OPEN EXTEND statement is executed, the record pointer is positioned at the end of the file, immediately after the last record.

 

4.         The WRITE statement is used to add records to the end of the file.

 

5.         Since the file is opened differently when records are to be updated and/or deleted than when records are to be added, the additions must either be done in a separate program or a separate procedure.

 

6.         The updated master file will need to be sorted if the added records are not in sequence.


 

VII.      Matching Files for Checking Purposes

 

A.        Sometimes it is necessary to match the key fields of records from separate files.

 

B.         This procedure may be used either to ascertain that matching records do exist on both files, or that records in one file do not exist in the other file.

 

C.        The process is similar to that of updating a file.


SOLUTIONS TO REVIEW QUESTIONS

 

I.          True-False Questions

 

1.         T

 

2.         F          Disk files can be processed sequentially and randomly.

 

3.         T

 

4.         T

 

5.         F          There may still be additional transaction records to process.

 

6.         F          A transaction record with no corresponding master record may be an

                        addition to the master file.

 

7.         T

 

8.         T

 

9.         T

 

10.       F          Records should be in order for sequential file processing.

 

II.      General Questions

 

1.         A new record may be added to the master file from the data in the transaction record.

 

An error message, NO MATCHING RECORD, might be printed indicating the key field is invalid.  The transaction record would not be processed any further, and processing would continue with the next record in the transaction file.

 

The program may be terminated.

 

2.         On demand output is a report that is produced only when it is requested.

 

3.         A key field is a field that uniquely identifies each record in a file.  It is also used to sequence the records in a file.

 

4.         Sequential file processing is the method of processing records in the order in which they are located in a file.  Normally, a sequential file is processed on a record-by-record basis from the first record to the last record.


 

5.         FILE SECTION entries:   

 

FD  OLD-MASTER-FILE.

     01  OLD-MASTER-RECORD.

         05  SSNO-OMR                PIC X(9).

         05  LAST-NAME-OMR           PIC X(15).

         05  FIRST-NAME-OMR          PIC X(10).

         05  SALARY-OMR              PIC 9(6).

 

     FD  TRANSACTION-FILE.

     01  TRANSACTION-RECORD.

         05  SSNO-TR                 PIC X(9).

         05  LAST-NAME-TR            PIC X(15).

         05  FIRST-NAME-TR           PIC X(10).

         05  SALARY-TR               PIC 9(6).

 

     FD  NEW-MASTER-FILE.

     01  NEW-MASTER-RECORD.

         05  SSNO-NMR                PIC X(9).

         05  LAST-NAME-NMR           PIC X(15).

         05  FIRST-NAME-NMR          PIC X(10).

         05  SALARY-NMR              PIC 9(6).

 

PROCEDURE DIVISION code:

 

100-MAIN-MODULE.

    PERFORM 800-INITIALIZATION

    PERFORM 200-PROCESS-ONE-SSNO

        UNTIL SSNO-OMR = HIGH-VALUES

                      AND

              SSNO-TR  = HIGH-VALUES

    PERFORM 900-TERMINATION

    STOP RUN.

 


200-PROCESS-ONE-SSNO.

    EVALUATE TRUE

        WHEN SSNO-OMR = SSNO-TR

            PERFORM 300-CHANGE-SALARY

        WHEN SSNO-OMR < SSNO-TR

            PERFORM 400-WRITE-WITH-NO-CHANGE

        WHEN OTHER

            PERFORM 500-DISPLAY-ERROR-MESSAGE

    END-EVALUATE.

 

300-CHANGE-SALARY.

    MOVE OLD-MASTER-RECORD TO NEW-MASTER-RECORD

    MOVE SALARY-TR TO SALARY-NMR

    WRITE NEW-MASTER-RECORD

    PERFORM 600-READ-OLD-MASTER-FILE

    PERFORM 700-READ-TRANSACTION-FILE.

 

400-WRITE-WITH-NO-CHANGE.

    WRITE NEW-MASTER-RECORD FROM OLD-MASTER-RECORD

    PERFORM 600-READ-OLD-MASTER-FILE.

 

500-DISPLAY-ERROR-MESSAGE.

    DISPLAY 'ERROR - THE FOLLOWING TRANSACTION RECORD'

    DISPLAY '        HAS NO CORRESPONDING MASTER RECORD: '

    DISPLAY '      - ' TRANSACTION-RECORD

    PERFORM 700-READ-TRANSACTION-FILE.

 

600-READ-OLD-MASTER-FILE.

    READ OLD-MASTER-FILE

        AT END

            MOVE HIGH-VALUES TO SSNO-OMR

    END-READ.

 

700-READ-TRANSACTION-FILE.

    READ TRANSACTION-FILE

        AT END

            MOVE HIGH-VALUES TO SSNO-TR

    END-READ.

 


800-INITIALIZATION.

    OPEN INPUT  OLD-MASTER-FILE

                TRANSACTION-FILE

         OUTPUT NEW-MASTER-FILE

    PERFORM 600-READ-OLD-MASTER-FILE

    PERFORM 700-READ-TRANSACTION-FILE.

 

900-TERMINATION.

    CLOSE OLD-MASTER-FILE

          TRANSACTION-FILE

          NEW-MASTER-FILE.

 

6.         Make the following modifications to the solution for Question 5:

 

Add the following entry in the WORKING-STORAGE SECTION: 

 

01  VALID-DATA-FLAG     PIC X(3)    VALUE 'YES'.

         88  VALID-DATA                  VALUE 'YES'.

 

Modify module 300-CHANGE-SALARY as shown below, and add modules 310-VALIDATE-NAME and 320-VALIDATE-SALARY.

 

300-CHANGE-SALARY.

         MOVE 'YES' TO VALID-DATA-FLAG

         PERFORM 310-VALIDATE-NAME

         PERFORM 320-VALIDATE-SALARY

         MOVE OLD-MASTER-RECORD TO NEW-MASTER-RECORD

         IF VALID-DATA

             MOVE SALARY-TR TO SALARY-NMR

         END-IF

         WRITE NEW-MASTER-RECORD

         PERFORM 600-READ-OLD-MASTER-FILE

         PERFORM 700-READ-TRANSACTION-FILE.

 

310-VALIDATE-NAME.

         IF  LAST-NAME-OMR NOT = LAST-NAME-TR  OR

            FIRST-NAME-OMR NOT = FIRST-NAME-TR

        DISPLAY 'ERROR - THE NAME ON THE FOLLOWING '

             DISPLAY '        TRANSACTION RECORD DOES NOT '

             DISPLAY '        MATCH THE NAME ON THE OLD '

             DISPLAY '        MASTER RECORD: '

             DISPLAY '      - ' TRANSACTION-RECORD

             MOVE 'NO ' TO VALID-DATA-FLAG

         END-IF.


320-VALIDATE-SALARY.

         IF  SALARY-TR > 1.1 * SALARY-OMR

        DISPLAY 'ERROR - THE SALARY ON THE FOLLOWING '

             DISPLAY '        TRANSACTION RECORD EXCEEDS THAT '

             DISPLAY '        ON THE OLD MASTER RECORD BY '

             DISPLAY '        MORE THAN 10%: '            

   DISPLAY '      - ' TRANSACTION-RECORD

             MOVE 'NO ' TO VALID-DATA-FLAG

         END-IF.

 

7.         DATA DIVISION entries:  

 

     FILE SECTION.

     FD  OLD-MASTER-FILE.

     01  OLD-MASTER-RECORD.

         05  SSNO-OMR                PIC X(9).

         05  LAST-NAME-OMR           PIC X(15).

         05  FIRST-NAME-OMR          PIC X(10).

         05  SALARY-OMR              PIC 9(6).

 

     FD  TRANSACTION-FILE.

     01  TRANSACTION-RECORD.

         05  SSNO-TR                 PIC X(9).

         05  LAST-NAME-TR            PIC X(15).

         05  FIRST-NAME-TR           PIC X(10).

         05  SALARY-TR               PIC 9(6).

         05  CODE-TR                 PIC X(1).

             88  ADD-RECORD                      VALUE '1'.

             88  CHANGE-SALARY                   VALUE '2'.

             88  DELETE-RECORD                   VALUE '3'.

 

     FD  NEW-MASTER-FILE.

     01  NEW-MASTER-RECORD.

         05  SSNO-NMR                PIC X(9).

         05  LAST-NAME-NMR           PIC X(15).

         05  FIRST-NAME-NMR          PIC X(10).

         05  SALARY-NMR              PIC 9(6).

 


WORKING-STORAGE SECTION.

 

     01  WS-CONTROL-KEY              PIC X(9).

     01  WS-ALLOCATED-SWITCH         PIC X(3).

 

PROCEDURE DIVISION code using the Balanced Line Algorithm:

 

100-MAIN-MODULE.

         PERFORM 900-INITIALIZATION

         PERFORM 200-PROCESS-ONE-SSNO

             UNTIL WS-CONTROL-KEY = HIGH-VALUES

         PERFORM 1000-TERMINATION

         STOP RUN.

 

200-PROCESS-ONE-SSNO.

         PERFORM 300-PROCESS-OLD-MASTER-FILE

         PERFORM 400-PROCESS-TRANSACTION-FILE

             UNTIL SSNO-TR NOT = WS-CONTROL-KEY

         PERFORM 500-PROCESS-NEW-MASTER-FILE

         PERFORM 600-CHOOSE-NEXT-SSNO.

 

300-PROCESS-OLD-MASTER-FILE.

         IF SSNO-OMR = WS-CONTROL-KEY

             MOVE 'YES' TO WS-ALLOCATED-SWITCH

             MOVE OLD-MASTER-RECORD TO NEW-MASTER-RECORD

             PERFORM 700-READ-OLD-MASTER-FILE

         ELSE

             MOVE 'NO ' TO WS-ALLOCATED-SWITCH

         END-IF.

 

400-PROCESS-TRANSACTION-FILE.

         EVALUATE TRUE

             WHEN ADD-RECORD     PERFORM 410-ADD-RECORD

             WHEN CHANGE-SALARY  PERFORM 420-CHANGE-SALARY

             WHEN DELETE-RECORD  PERFORM 430-DELETE-RECORD

                             WHEN OTHER          DISPLAY 'INVALID TRANS CODE'

         END-EVALUATE

         PERFORM 800-READ-TRANSACTION-FILE.

 


410-ADD-RECORD.

         IF WS-ALLOCATED-SWITCH = 'NO '

             MOVE SSNO-TR       TO SSNO-NMR

             MOVE LAST-NAME-TR  TO LAST-NAME-NMR

             MOVE FIRST-NAME-TR TO FIRST-NAME-NMR

             MOVE SALARY-TR     TO SALARY-NMR

             MOVE 'YES' TO WS-ALLOCATED-SWITCH

         ELSE

             DISPLAY 'INVALID ADD - MASTER ALREADY EXISTS'

         END-IF.

 

420-CHANGE-SALARY.

         IF WS-ALLOCATED-SWITCH = 'YES'

             MOVE SALARY-TR TO SALARY-NMR

         ELSE

             DISPLAY 'INVALID CHANGE - MASTER DOES NOT EXIST'

         END-IF.

 

430-DELETE-RECORD.

         IF WS-ALLOCATED-SWITCH = 'YES'

             MOVE 'NO ' TO WS-ALLOCATED-SWITCH

         ELSE

             DISPLAY 'INVALID DELETE - MASTER DOES NOT EXIST'

         END-IF.

 

500-PROCESS-NEW-MASTER-FILE.

         IF WS-ALLOCATED-SWITCH = 'YES'

             WRITE NEW-MASTER-RECORD

         END-IF.

 

600-CHOOSE-NEXT-SSNO.

         IF SSNO-OMR < SSNO-TR

             MOVE SSNO-OMR TO WS-CONTROL-KEY

         ELSE

             MOVE SSNO-TR  TO WS-CONTROL-KEY

         END-IF.

 

700-READ-OLD-MASTER-FILE.

         READ OLD-MASTER-FILE

             AT END

                 MOVE HIGH-VALUES TO SSNO-OMR

         END-READ.

 


800-READ-TRANSACTION-FILE.

         READ TRANSACTION-FILE

             AT END

                 MOVE HIGH-VALUES TO SSNO-TR

         END-READ.

 

900-INITIALIZATION.

         OPEN INPUT  OLD-MASTER-FILE

                     TRANSACTION-FILE

              OUTPUT NEW-MASTER-FILE

         PERFORM 700-READ-OLD-MASTER-FILE

         PERFORM 800-READ-TRANSACTION-FILE

         PERFORM 600-CHOOSE-NEXT-SSNO.

 

1000-TERMINATION.

         CLOSE OLD-MASTER-FILE

               TRANSACTION-FILE

               NEW-MASTER-FILE.

 

8.                  Make the following modifications to the solution for Question 7:

 

a.         Add a new 88-level item to the list of valid transaction codes, and reassign the value for DELETE-RECORD.

 

01  TRANSACTION-RECORD.

    05  SSNO-TR                 PIC X(9).

    05  LAST-NAME-TR            PIC X(15).

    05  FIRST-NAME-TR           PIC X(10).

    05  SALARY-TR               PIC 9(6).

    05  CODE-TR                 PIC X(1).

        88  ADD-RECORD                      VALUE '1'.

        88  CHANGE-SALARY                   VALUE '2'.

        88  CHANGE-LAST-NAME                VALUE '3'.

        88  DELETE-RECORD                   VALUE '4'.


 

b.         Revise module 400-PROCESS-TRANSACTION-FILE so that it includes the new type of transaction, and renumber the DELETE-RECORD module.

 

400-PROCESS-TRANSACTION-FILE.

         EVALUATE TRUE

             WHEN ADD-RECORD       PERFORM 410-ADD-RECORD

             WHEN CHANGE-SALARY    PERFORM 420-CHANGE-SALARY

             WHEN CHANGE-LAST-NAME PERFORM 430-CHANGE-LAST-NAME

             WHEN DELETE-RECORD    PERFORM 440-DELETE-RECORD

             WHEN OTHER            DISPLAY 'INVALID TRANS CODE'

         END-EVALUATE

         PERFORM 800-READ-TRANSACTION-FILE.

 

c.         Add module 430-CHANGE-LAST-NAME.

 

430-CHANGE-LAST-NAME.

    IF WS-ALLOCATED-SWITCH = 'YES'

        MOVE LAST-NAME-TR TO LAST-NAME-NMR

    ELSE

        DISPLAY 'INVALID CHANGE - MASTER DOES NOT EXIST'

    END-IF.

 

9.         The two files created are the new master file that contains the current data and the control listing/audit trail that contains a record of the changes made.

 

10.       HIGH-VALUES is the highest possible value in the computer's collating sequence.

 

III.       Validating Data

 

1.         The program should include routines to verify that:

 

a.         IN-OLD-QTY-ON-HAND and IN-TRANS-QTY are present and valid numeric fields.

b.         IN-TRANS-CODE is in the range 1 - 3.

c.         IN-OLD-PART-NO and IN-TRANS-PART-NO are present.

 

2.         The control listing should include:

 

a.         The number of records processed from the old master file.

b.         The number of records processed from the transaction file.

c.         A list of each error found in the transaction file.

d.         The number of master records added.

e.         The number of master records deleted.

f.          The number of master records updated.

 

3.         A batch total of IN-TRANS-QTY should be included.

 

IV.       Internet/Critical Thinking Questions

 

1.         Consider a student registration system.  When a student registers for courses for the upcoming semester, should all courses be stored in a single transaction record for that student, or should the system create a separate transaction record for each course the student wishes to take?

 

One factor to consider is how multiple changes would be stored in a single transaction record. If one transaction record will be used to hold all classes for which a student wishes to register, then it must be designed to handle the maximum number of classes that one student might take.  This means that if a student takes less than the maximum number of classes, the transaction record contains wasted space.  It also means that if the case should arise that a student needs to take more courses than can be stored in one transaction record, the registrar’s office has a problem that is not simple to solve.   “Sorry, but the computer system only allows you to take six classes” is not an acceptable answer to the student who must take seven courses in order to graduate.

 

Compare this to a system that allows multiple transaction records per master.  Now each transaction record would contain one course for one student.  While the student ID is showing up multiple times (once per transaction record), there is no limit on the number of classes that a student may take, and there are no unused fields in the transaction record.

 

Another factor to consider is the logic of the update program.  Again looking at the student registration system, it is neither difficult nor complex to design a program to handle multiple transactions (courses) for a specific master record (student).  On the other hand, if there is a single transaction record containing multiple courses, then the logic becomes more complex because it must now define a table of courses in the transaction record and must use table processing to register the student for each of the courses.  This logic is certainly something that any qualified programmer can handle, but it is more complex than that needed for the program that processes multiple transaction records per student.

 

In this particular situation, the user (the university’s employees and students) can be best served by designing a system that creates multiple transactions per master.  Multiple transactions per master will also result in the simplest program design in this case.

 


2.         Advantages of Using Three Files for a Master File Update

 

·        In the case of a corrupted master file, it is easy to recreate the file from the previous version of the master and the corresponding transaction file.

 

·        It is easy to determine the status of a record on a specific date because there are multiple versions of the master file.

 

·        If there is a run-time error that causes the program to abort during the file update procedure, the program may be rerun in its entirety after the correction has been made.

·        The files may be stored on disk or tape, although tapes are not used much anymore.

 

Disadvantages of Using Three Files for a Master File Update

 

·        There must be system safeguards to guarantee that any program, which accesses the master file, is using the correct version of the file.

 

·        Because there are three files involved in the update, the program logic is more complex.

 

Advantages of Using a Single Master File as I-O

 

·        The logic of the update program is simpler than that for an update that uses an old master file and a new master file.

 


Disadvantages of Using a Single Master File as I-O

 

·        When adding records, new records must be added to the end of the file (using OPEN EXTEND), and then the file must be sorted into order on the key field(s).

·        When deleting records, the records are not physically removed from the file; instead a code is used to indicate that the record is not active.  The two disadvantages of this are:

·        Wasted disk space

·        All programs that access the file must check the code to see if the record is active.

·        If there is a run-time error that causes the program to abort during the file update procedure, then after correcting the program, the programmer must determine how much of the previous transaction file had been processed and must proceed with processing at that point (or the entire update may be rerun against a backup copy of the master file).

 

·        The master file must be stored on disk

·        A backup copy of the master file must be created in a separate procedure before the update takes place.

 

3.         Advantages of Using the Balanced Line Algorithm

 

·        The logic of the balanced line algorithm can handle all possible situations in a sequential file update.

 

·        If all sequential file update programs in a programming shop use the balanced line algorithm, then there is less maintenance programming overhead because all programmers understand and use the same approach to designing and coding sequential update programs.

 

Disadvantages of Using the Balanced Line Algorithm

 

·        When a program handles only a single type of transaction (such as adding records to a master file), the logic of the balanced line algorithm is more complicated than necessary.

·        When a program handles only a single type of transaction, the balanced line algorithm adds unnecessary overhead during program execution.  This is a result of the first disadvantage (the logic is more complicated than necessary for this situation).


 

4.         A Transaction File Would be Used

 

·        When a large number of changes are to be made

 

·        When the changes can be prepared before a program is run.

 

·        Time is not particularly critical.

 

A Keyed Data Update Would be Used

 

·        When a small number of changes are to be made

 

·        When the changes are not known before the program is run

 

·        Time is critical

 

 


SOLUTIONS TO DEBUGGING EXERCISES

 

1.         No, it will not produce the correct results.  When either the transaction or master file runs out of records before the other file, a program interrupt will occur.

 

a.         When the master file runs out of records before the transaction file:

 

The next transaction record processed will have ACCT-TRANS > ACCT-MASTER, so module 500-TRANS-GREATER-RTN will be performed.  In this module, the last master record will be written a second time.  Then the READ MASTER-FILE statement will cause the a program interrupt because the end of file has already been reached.

 

b.         When the transaction file runs out of records before the master file:

 

The next master record processed will have ACCT-TRANS < ACCT-MASTER, so module 400-TRANS-LESS-RTN will be executed.  In this module, the last transaction record, which has already been processed, will be listed as an error.  Then the statement READ TRANS-FILE will cause a program interrupt because the end of file has already been reached.

 

2.         The basic differences in logic are:

 

a.         End of file is handled by changing a flag rather than by moving HIGH-VALUES to the key field of the file.

 

b.         There is no loop in the module 300-EQUAL-RTN to process multiple transactions.

 

c.         The case in which ACCT-TRANS < ACCT-MASTER is treated as an error instead of as an addition.

 

3.         Yes, this does cause a logic error.  See the answer to Exercise 1.

 

4.         Yes, we could eliminate 300-EQUAL-RTN in the manner illustrated, assuming that the remaining two IF statements in 200-COMP-RTN are retained.


 

5.       If the transactions were entered interactively, the places where

 

          READ TRANS-FILE

        AT END ...

    END-READ

 

    occur, would have to be replaced with

 

DISPLAY 'IS THERE MORE DATA (Y OR N)?'

ACCEPT MORE-TRANS

IF MORE-TRANS = 'N'

    MOVE HIGH-VALUES TO ACCT-TRANS

ELSE

    DISPLAY'ACCOUNT NUMBER?'

        ACCEPT ACCT-TRANS

       

        (other DISPLAY/ACCEPT pairs depending on what fields are in the record)

       

    END-IF