Professional Documents
Culture Documents
A transaction record with no corresponding master record may be an addition to the master file. Disk files can be processed sequentially and randomly.
7. 8. 9. 10. II. 1.
General Questions 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. 3.
On demand output is a report that is produced only when it is requested. 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. 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.
4.
5.
FILE SECTION entries: FD 01 OLD-MASTER-FILE. OLD-MASTER-RECORD. 05 SSNO-OMR 05 LAST-NAME-OMR 05 FIRST-NAME-OMR 05 SALARY-OMR TRANSACTION-FILE. TRANSACTION-RECORD. 05 SSNO-TR 05 LAST-NAME-TR 05 FIRST-NAME-TR 05 SALARY-TR NEW-MASTER-FILE. NEW-MASTER-RECORD. 05 SSNO-NMR 05 LAST-NAME-NMR 05 FIRST-NAME-NMR 05 SALARY-NMR
FD 01
FD 01
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 88 VALID-DATA PIC X(3) VALUE 'YES'. VALUE 'YES'.
Modify module 300-CHANGE-SALARY as shown below, and add modules 310VALIDATE-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 05 LAST-NAME-OMR 05 FIRST-NAME-OMR 05 SALARY-OMR FD 01 TRANSACTION-FILE. TRANSACTION-RECORD. 05 SSNO-TR 05 LAST-NAME-TR 05 FIRST-NAME-TR 05 SALARY-TR 05 CODE-TR 88 ADD-RECORD 88 CHANGE-SALARY 88 DELETE-RECORD NEW-MASTER-FILE. NEW-MASTER-RECORD. 05 SSNO-NMR 05 LAST-NAME-NMR 05 FIRST-NAME-NMR 05 SALARY-NMR
X(9). X(15). X(10). 9(6). X(1). VALUE '1'. VALUE '2'. VALUE '3'.
FD 01
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. 01 Add a new 88-level item to the list of valid transaction codes, and reassign the value for DELETE-RECORD. TRANSACTION-RECORD. 05 SSNO-TR 05 LAST-NAME-TR 05 FIRST-NAME-TR 05 SALARY-TR 05 CODE-TR 88 ADD-RECORD 88 CHANGE-SALARY 88 CHANGE-LAST-NAME 88 DELETE-RECORD PIC PIC PIC PIC PIC X(9). X(15). X(10). 9(6). X(1). VALUE VALUE VALUE VALUE '1'. '2'. '3'. '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. HIGH-VALUES is the highest possible value in the computer's collating sequence. Validating Data The program should include routines to verify that: a. b. c. 2. IN-OLD-QTY-ON-HAND and IN-TRANS-QTY are present and valid numeric fields. IN-TRANS-CODE is in the range 1 - 3. IN-OLD-PART-NO and IN-TRANS-PART-NO are present.
10. III. 1.
The control listing should include: a. b. c. d. e. f. The number of records processed from the old master file. The number of records processed from the transaction file. A list of each error found in the transaction file. The number of master records added. The number of master records deleted. The number of master records updated.
3.
IV. 1.
Internet/Critical Thinking Questions 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 registrars 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 universitys 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.
3.
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 > ACCTMASTER, 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. There is no loop in the module 300-EQUAL-RTN to process multiple transactions. The case in which ACCT-TRANS < ACCT-MASTER is treated as an error instead of as an addition.
b.
c.
3. 4.
Yes, this does cause a logic error. See the answer to Exercise 1. 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