Programming Logic and Design Fourth Edition, Comprehensive

Slides:



Advertisements
Similar presentations
Chapter 9: Advanced Array Manipulation
Advertisements

Programming Logic and Design Fourth Edition, Introductory
Programming Logic and Design, Second Edition, Comprehensive
Chapter 7: Control Breaks Programming Logic and Design, Third Edition Comprehensive.
Programming Logic and Design, Third Edition Comprehensive
File Management Chapter 12. File Management A file is a named entity used to save results from a program or provide data to a program. Access control.
Programming Logic and Design Fourth Edition, Introductory
A Guide to SQL, Seventh Edition. Objectives Create a new table from an existing table Change data using the UPDATE command Add new data using the INSERT.
Writing a Complete Program
Chapter 9 Using Data Flow Diagrams
Chapter 7 Using Data Flow Diagrams
A Guide to SQL, Seventh Edition. Objectives Embed SQL commands in PL/SQL programs Retrieve single rows using embedded SQL Update a table using embedded.
Programming Logic and Design Fourth Edition, Comprehensive
General Algorithms for Common Business Problems
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
File Management Chapter 12. File Management File management system is considered part of the operating system Input to applications is by means of a file.
Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout.
10- 1 Chapter 10. To familiarize you with  Main types of computer-generated reports  Techniques used for efficient printing of group reports and control.
Programming Logic and Design Seventh Edition
10-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
Chapter 13 File Structures. Understand the file access methods. Describe the characteristics of a sequential file. After reading this chapter, the reader.
Chapter 13 Sequential File Processing. Master Files Set of files used to store companies data in areas like payroll, inventory Usually processed by batch.
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 6: Sequential Data Files.
Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File.
File Handling and Control Break Logic. Objectives In this chapter, you will learn about: Computer files Writing a program that reads from and/or writes.
6 Chapter 61 Looping Programming Logic and Design, Second Edition, Comprehensive 6.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 6 Looping.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 7 Files.
13-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
Sequential Files Chapter 13. Master Files Set of files used to store companies data in areas like payroll, inventory Set of files used to store companies.
Now, please open your book to page 60, and let’s talk about chapter 9: How Data is Stored.
General Algorithms for Common Business Problems Simple Program Design Third Edition A Step-by-Step Approach 10.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 8 Arrays.
Pascal Programming Today Chapter 11 1 Chapter 11.
13-1 Sequential File Processing Chapter Chapter Contents Overview of Sequential File Processing Sequential File Updating - Creating a New Master.
13- 1 Chapter 13.  Overview of Sequential File Processing  Sequential File Updating - Creating a New Master File  Validity Checking in Update Procedures.
Master File Update Processing. Objectives On completing this section you should be able to: w Distinguish between online processing and batch processing.
Control Break Processing
A Guide to SQL, Eighth Edition Chapter Six Updating Data.
Chapter 11: Sequential File Merging, Matching, and Updating Programming Logic and Design, Third Edition Comprehensive.
11 Chapter 111 Sequential File Merging, Matching, and Updating Programming Logic and Design, Second Edition, Comprehensive 11.
Bubble Sort. Sorting  Computers only use numeric values for sorting  Does this mean you cannot sort a file by a character field (such as last name or.
Sequential Processing to Update a File Please use speaker notes for additional information!
Topics Covered: File Components of file Components of file Terms used Terms used Types of business file Types of business file Operations on file Operations.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
( ) 1 Chapter # 8 How Data is stored DATABASE.
Programming Logic and Design Fourth Edition, Introductory Chapter 2 Understanding Structure.
Processing multiple files
Create a PO-Based Invoice
Chapter 6: Sequential Data Files
File and Database Processing
A Guide to SQL, Seventh Edition
Programming Logic and Design Fourth Edition, Comprehensive
Starting Out with Programming Logic & Design
Programming Logic and Design Eighth Edition
Topics Introduction to File Input and Output
Chapter 7 Files and Exceptions
Databases Lesson 2.
Please use speaker notes for additional information!
Designing and Writing Control-Break Programs
Chapter 14 Sorting and Merging.
Writing a Complete Program
Please use speaker notes for additional information!
Chapter 8 Advanced SQL.
Chapter 5: Control Structures II (Repetition)
Cohesion and Coupling.
2 file sequential matching with multiple records allowed on file 2
Topics Introduction to File Input and Output
Chapter 4: Writing and Designing a Complete Program
Presentation transcript:

Programming Logic and Design Fourth Edition, Comprehensive Chapter 11 Sequential File Merging, Matching, and Updating

Objectives Understand sequential files and the need for merging them Create the mainline and housekeeping() logic for a merge program Create the mergefiles() and finishUp() modules for a merge program Modify the housekeeping() module to check for eof Programming Logic and Design, Fourth Edition, Comprehensive

Objectives (continued) Understand master and transaction file processing Match files to update master file fields Allow multiple transactions for a single master file record Update records in sequential files Programming Logic and Design, Fourth Edition, Comprehensive

Understanding Sequential Data Files and the Need for Merging Files Sequential file: records are stored one after another in some order Temporal order: order based on time Records are often stored based on the contents of one or more fields within each record Merging files: combining two or more files while maintaining the sequential order Programming Logic and Design, Fourth Edition, Comprehensive

Understanding Sequential Data Files and the Need for Merging Files (continued) Two conditions required for merging files: Each file must have same record layout Each file must be sorted in the same order based on the same field Programming Logic and Design, Fourth Edition, Comprehensive

Understanding Sequential Data Files and the Need for Merging Files (continued) Programming Logic and Design, Fourth Edition, Comprehensive

Creating the Mainline and housekeeping() Logic for a Merge Program Mainline logic similar to other file processing programs, except for handling two files With two input files, must determine when both files are at eof In housekeeping() module: Define a flag variable to indicate that both files have reached eof Must define two input files At end of module, read one record from each input file Programming Logic and Design, Fourth Edition, Comprehensive

Creating the Mainline and housekeeping() Logic for a Merge Program (continued) Programming Logic and Design, Fourth Edition, Comprehensive

Creating the Mainline and housekeeping() Logic for a Merge Program (continued) Programming Logic and Design, Fourth Edition, Comprehensive

Creating the mergeFiles() and finishUp() Modules for a Merge Program Two records are in memory, one from each file Must decide which record to write to output file first After writing one record, must read again from the same file Then compare both records again to determine which is written next Must always have one record from each file to compare before writing one Programming Logic and Design, Fourth Edition, Comprehensive

Creating the mergeFiles() and finishUp() Modules for a Merge Program (continued) Programming Logic and Design, Fourth Edition, Comprehensive

Creating the mergeFiles() and finishUp() Modules for a Merge Program (continued) Merge technique: Compare two records Write the record with the lower value Read another record from the same input file Programming Logic and Design, Fourth Edition, Comprehensive

Creating the mergeFiles() and finishUp() Modules for a Merge Program (continued) Programming Logic and Design, Fourth Edition, Comprehensive

Creating the mergeFiles() and finishUp() Modules for a Merge Program (continued) Data to be merged: Programming Logic and Design, Fourth Edition, Comprehensive

Creating the mergeFiles() and finishUp() Modules for a Merge Program (continued) High value: a value that is greater than any possible value in a field Because the files are different lengths, you must continue to process the longer file To use the same loop, you must handle the comparison operation Technique: Use a high value for the comparison to guarantee that the record will be “selected” and written Programming Logic and Design, Fourth Edition, Comprehensive

Creating the mergeFiles() and finishUp() Modules for a Merge Program (continued) Programming Logic and Design, Fourth Edition, Comprehensive

Creating the mergeFiles() and finishUp() Modules for a Merge Program (continued) When both files are at eof, execute the finishUp() module Programming Logic and Design, Fourth Edition, Comprehensive

Modifying the housekeeping() Module in the Merge Program to Check for eof Must check for eof during first read, in case one file is empty Programming Logic and Design, Fourth Edition, Comprehensive

Modifying the housekeeping() Module in the Merge Program to Check for eof (continued) Programming Logic and Design, Fourth Edition, Comprehensive

Modifying the housekeeping() Module in the Merge Program to Check for eof (continued) Programming Logic and Design, Fourth Edition, Comprehensive

Master and Transaction File Processing When merging files, the records usually contain the same fields in the same order When not the same format, one file may be used to update another file Master file: holds relatively permanent data Transaction file: contains temporary data to be used to update the master file Matching record: record in the master file with same key field value as a record in the transaction file Programming Logic and Design, Fourth Edition, Comprehensive

Master and Transaction File Processing (continued) Matching may be done for several reasons: To update the master file: transaction file record is used to make changes to the master file record Use information from both master and transaction file to create another entity, such as an invoice There may be 0, 1, or many transaction records matching each master file record Two approaches to updating a master file: Update in place, changing the existing master file Create a copy of the master, making the changes in the new version Programming Logic and Design, Fourth Edition, Comprehensive

Master and Transaction File Processing (continued) When a new copy of the master is created during updating: Parent file: original saved master file Child file: updated version of master file Programming Logic and Design, Fourth Edition, Comprehensive

Matching Files to Update Fields in Master File Records Logic used to match records in two files is similar to merge logic Programming Logic and Design, Fourth Edition, Comprehensive

Matching Files to Update Fields in Master File Records (continued) Goal: create a new master file with updated custTotalSales field Technique: Inspect each master file record Determine if there are any new transaction records matching the master file record Add transaction amount to master file custTotalSales field in master record Pre-sorting both master and transaction files will improve the efficiency Programming Logic and Design, Fourth Edition, Comprehensive

Matching Files to Update Fields in Master File Records (continued) Programming Logic and Design, Fourth Edition, Comprehensive

Matching Files to Update Fields in Master File Records (continued) Programming Logic and Design, Fourth Edition, Comprehensive

Matching Files to Update Fields in Master File Records (continued) Programming Logic and Design, Fourth Edition, Comprehensive

Matching Files to Update Fields in Master File Records (continued) 3 possibilities when comparing records: transCustNumber value = custNumber transCustNumber value > custNumber transCustNumber value < custNumber If =, update custTotalSales If >, there was no sale for that customer If <, there is no matching master record  error Programming Logic and Design, Fourth Edition, Comprehensive

Matching Files to Update Fields in Master File Records (continued) Programming Logic and Design, Fourth Edition, Comprehensive

Matching Files to Update Fields in Master File Records (continued) Programming Logic and Design, Fourth Edition, Comprehensive

Allowing Multiple Transactions for a Single Master File Record To handle multiple transactions for a single master file record, you must Match a transaction to the master file record Process that transaction Read again only from the transaction file Determine if the new transaction applies to the same master record Programming Logic and Design, Fourth Edition, Comprehensive

Allowing Multiple Transactions for a Single Master File Record (continued) Programming Logic and Design, Fourth Edition, Comprehensive

Updating Records in Sequential Files Application must be able to: Make changes to data in a master file record Add new records to master file Eliminate records in master file Transaction file records usually contain a transaction code to indicate the type of action to take Programming Logic and Design, Fourth Edition, Comprehensive

Updating Records in Sequential Files (continued) Types of transaction records: Addition: create a new master file record Deletion: remove a master file record Change: modify data in a master file record Programming Logic and Design, Fourth Edition, Comprehensive

Updating Records in Sequential Files (continued) Programming Logic and Design, Fourth Edition, Comprehensive

Updating Records in Sequential Files (continued) Programming Logic and Design, Fourth Edition, Comprehensive

Updating Records in Sequential Files (continued) Programming Logic and Design, Fourth Edition, Comprehensive

Updating Records in Sequential Files (continued) Programming Logic and Design, Fourth Edition, Comprehensive

Updating Records in Sequential Files (continued) When transaction record matches master file record: If transaction code = “A”  error If transaction code = “C”, make the changes in the master record If transaction code is not “A” or “C”, must be a “D”, so do not write existing master file record to the new master file When complete, read one new record from each of the input files Programming Logic and Design, Fourth Edition, Comprehensive

Updating Records in Sequential Files (continued) Programming Logic and Design, Fourth Edition, Comprehensive

Updating Records in Sequential Files (continued) If master file record > transaction record, there is no master file record that matches the transaction record If transaction code is not an “A”  error When complete, do not read another master record There may be more transactions for the newly added record Programming Logic and Design, Fourth Edition, Comprehensive

Updating Records in Sequential Files (continued) Programming Logic and Design, Fourth Edition, Comprehensive

Updating Records in Sequential Files (continued) If master file record < transaction record, there is no transaction record that matches the transaction record Write the master file record to the new master file Read the next master file record Programming Logic and Design, Fourth Edition, Comprehensive

Updating Records in Sequential Files (continued) Programming Logic and Design, Fourth Edition, Comprehensive

Updating Records in Sequential Files (continued) If transaction file reaches eof first, set transEmpNum to 999 Master file record will always be lower, causing master file record to be written to new master file If master file reaches eof first, set EmpNum to 999 Transaction record will always be lower, causing new records to be added (if code = “A”) or error to be generated (if code not = “A”) When both files reach eof, set bothAtEof = “Y” and perform finishUp() module Programming Logic and Design, Fourth Edition, Comprehensive

Updating Records in Sequential Files (continued) Programming Logic and Design, Fourth Edition, Comprehensive

Updating Records in Sequential Files (continued) Programming Logic and Design, Fourth Edition, Comprehensive

Summary Sequential file: records are stored one after another in some order Key field: field on which you sort records When merging two files Compare records from each input file Write the appropriate record from one file Read another record from the same file When eof is reached on one input file, set key field to a high value and finish processing the other file Programming Logic and Design, Fourth Edition, Comprehensive

Summary (continued) Master file: holds relatively permanent data Transaction file: holds temporary data that corresponds to records in master file To match transaction file and master file, determine if a transaction record exists for each master If yes: update or delete the master based on the transaction code If no: add a new master record based on the transaction code Programming Logic and Design, Fourth Edition, Comprehensive

Summary (continued) With multiple transactions per master file record Process a matching transaction record Read again from the transaction file When transaction record > master file record, read from master file Transaction file records usually have the same fields as the master, with a transaction code field Programming Logic and Design, Fourth Edition, Comprehensive