11 Chapter 111 Sequential File Merging, Matching, and Updating Programming Logic and Design, Second Edition, Comprehensive 11.

Slides:



Advertisements
Similar presentations
Understanding the Need for Sorting Records
Advertisements

Chapter 9: Advanced Array Manipulation
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
Programming Logic and Design Fourth Edition, Introductory
Writing a Complete Program
A Guide to Oracle9i1 Advanced SQL And PL/SQL Topics Chapter 9.
Modules, Hierarchy Charts, and Documentation
C++ Programming: Program Design Including Data Structures, Fifth Edition Chapter 17: Linked Lists.
Programming Logic and Design Fourth Edition, Comprehensive
Chapter 13: Object-Oriented Programming
General Algorithms for Common Business Problems
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Programming Logic and Design, Third Edition Comprehensive
- Meeting 4 – Writing a Complete Program
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
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)
Programming Logic and Design, Second Edition, Comprehensive
Chapter 13 Sequential File Processing. Master Files Set of files used to store companies data in areas like payroll, inventory Usually processed by batch.
The Fun That Is File Structures Pages By: Christine Zeitschel.
Mail merge I: Use mail merge for mass mailings Perform a complete mail merge Now you’ll walk through the process of performing a mail merge by using the.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Twelve Access Databases and LINQ.
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 6: Sequential Data Files.
Programming Logic and Design, Second Edition, Comprehensive
Selection Control Structures. Simple Program Design, Fourth Edition Chapter 4 2 Objectives In this chapter you will be able to: Elaborate on the uses.
Chapter 17 Creating a Database.
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.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 12 Manipulating Larger Quantities of Data.
6 Chapter 61 Looping Programming Logic and Design, Second Edition, Comprehensive 6.
Databases. What is a database?  A database is used to store data. The word DATA is actually Latin for FACTS. A database is, therefore, a place, or thing.
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.
Chapter 16: Using Relational Databases Programming Logic and Design, Third Edition Comprehensive.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 16 Using Relational Databases.
Programming Logic and Design Fourth Edition, Comprehensive Chapter 8 Arrays.
System design : files. Data Design Concepts  Data Structures  A file or table contains data about people, places or events that interact with the system.
Types of Processing of Data www. ICT-Teacher.com.
13-1 Sequential File Processing Chapter Chapter Contents Overview of Sequential File Processing Sequential File Updating - Creating a New Master.
FIRST COURSE Word Tutorial 6 Using Mail Merge. Objectives Learn about the mail merge process Use the Mail Merge task pane Select a main document Create.
Chapter 10: Using Menus and Validating Input Programming Logic and Design, Third Edition Comprehensive.
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
Chapter 11: Sequential File Merging, Matching, and Updating Programming Logic and Design, Third Edition Comprehensive.
Presentation on Database management Submitted To: Prof: Rutvi Sarang Submitted By: Dharmishtha A. Baria Roll:No:1(sem-3)
Sequential Processing to Update a File Please use speaker notes for additional information!
Programming Logic and Design Fifth Edition, Comprehensive Chapter 6 Arrays.
( ) 1 Chapter # 8 How Data is stored DATABASE.
Microsoft Visual Basic 2010: Reloaded Fourth Edition
Chapter 6: Sequential Data Files
Learning Objectives Today we will Learn:
Programming Logic and Design Eighth Edition
Chapter 7 Files and Exceptions
Databases Lesson 2.
Please use speaker notes for additional information!
Programming Logic and Design Fourth Edition, Comprehensive
Designing and Writing Control-Break Programs
Chapter 14 Sorting and Merging.
Searching an Array or Table
Writing a Complete Program
Programming Logic and Design Fifth Edition, Comprehensive
Chapter 10: Using Menus and Validating Input
III. Responsibilities of Admin
Chapter 4: Writing and Designing a Complete Program
Presentation transcript:

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

Chapter 112 Objectives After studying Chapter 11, you should be able to: Understand sequential files and the need for merging them Create the mainline and housekeeping() logic for a merge program Create the mainLoop() and finishUp() modules for a merge program Modify the housekeeping() module to check for eof

11 Chapter 113 Objectives After studying Chapter 11, you should be able to: 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

11 Chapter 114 Understanding Sequential Data Files and the Need for Merging Files A sequential file is a file where records are stored one after another in some order Examples of sequential files include: –A file of employees stored in order by Social Security number –A file of parts for a manufacturing company stored in order by part number –A file of customers for a business stored in alphabetical order by last name

11 Chapter 115 Understanding Sequential Data Files and the Need for Merging Files Merging files involves combining two or more files while maintaining the sequential order Before you can merge files, two closely related conditions must be met: –Each file used in the merge must be sorted in order based on some field –Each file used in the merge must be sorted in the same order (ascending or descending) on the same field as the others

11 Chapter 116 Understanding Sequential Data Files and the Need for Merging Files

11 Chapter 117 Creating the Mainline and housekeeping() Logic for a Merge Program The mainline logic for a program that merges two files is the same main logic you’ve used before in other programs: a housekeeping() module, a mainLoop() module that repeats until the end of the program, and a finishUp() module When you declare variables within the housekeeping() module, you must declare the bothAtEof flag and initialize it to any value other than “Y” A data file contains data only for another computer program to read

11 Chapter 118 Flowchart for Mainline Logic of Merge Program

11 Chapter 119 Flowchart for housekeeping() Module in Merge Program, Version 1

11 Chapter 1110 Creating the mainLoop() and finishUp() Modules for a Merge Program When you begin the mainLoop() module, two records—one from eastFile and one from westFile —are sitting in the memory of the computer Using the sample data from Figure 11-1, you can see that the record containing “Able” should be written to the output file while Chen’s record waits in memory because the eastName “Able” is alphabetically lower than the westName “Chen”

11 Chapter 1111 Beginning of the mainLoop() Module

11 Chapter 1112 Continuation of mainLoop() Module for Merge Program

11 Chapter 1113 Names from Two Files to Merge

11 Chapter 1114 The finishUp() Module for Merge Program

11 Chapter 1115 Modifying the housekeeping() Module to Check for Eof It is good practice to check for eof every time you read

11 Chapter 1116 Master and Transaction File Processing You use a master file to hold relatively permanent data about your customers The file with the customer purchases is a transaction file that holds more temporary data Often, you periodically use a transaction file to find a matching record in a master file, so you can update the master file by making changes to the values in its fields

11 Chapter 1117 Master and Transaction File Processing Here are a few other examples of files that have a master-transaction relationship: –A library maintains a master file of all patrons and a transaction file with information about each book or other items checked out –A college maintains a master file of all students and a transaction file for each course registration –A telephone company maintains a master file of every telephone line (number) and a transaction file with information about every call

11 Chapter 1118 Master and Transaction File Processing When you update a master file, you can take two approaches: –You can actually change the information on the master file –You can create a copy of the master file, making the changes on the new version. The saved version of a master file is the parent file; the updated version is the child file

11 Chapter 1119 Matching Files to Update Fields in Master File Records The logic you use to perform a match between master and transaction file records is similar to the logic you use to perform a merge As with a merge, you must begin with both files sorted in the same order on the same field

11 Chapter 1120 Matching Files to Update Fields in Master File Records

11 Chapter 1121 Matching Files to Update Fields in Master File Records Figure shows some sample data you can use to walk through the logic for this program

11 Chapter 1122 Updating Records in Sequential Files Assume you have a master employee file as shown on the left side of Figure Sometimes a new employee is hired and must be added to this file, or an employee quits and must be removed from the file Sometimes you need to change an employee record by recording a raise in salary for example, or a change of department

11 Chapter 1123 Updating Records in Sequential Files An addition record on the transaction file would contain data in the fields transNum, transName, transSalary, and transDept ; an addition record represents a new employee, and data for all the fields must be entered for the first time

11 Chapter 1124 Updating Records in Sequential Files A deletion record really needs data in only two fields—a “D” in transCode and a number in transNum A change record contains a “C” code and needs data only in fields that are going to be changed The mainline logic for an update program is the same as that for the merging and matching programs shown in Figure 11-13

11 Chapter 1125 The readEmp() and readTrans() Modules

11 Chapter 1126 Updating Records in Sequential Files As shown in Figure 11-23, within the theyAreEqual() module you check the transCode and perform one of three actions: –If the code is an “A”, print an error message –If the code is a “C”, you need to make changes –If the code is not an “A” or a “C”, it must be a “D” and the record should be deleted If the transaction record contains code “A”, that’s fine because an addition transaction shouldn’t have a master record

11 Chapter 1127 The translsLargerThanEmp() Module

11 Chapter 1128 The finishUp() Module for Update Program

11 Chapter 1129 Summary A sequential file is a file whose records are stored one after another in some order The mainline logic for a program that merges two files contains a housekeeping() module, a mainLoop() module that repeats until the end of the program, and a finishUp() module When beginning the mainLoop() module for a merge program, you compare records from each file to be merged

11 Chapter 1130 Summary In the housekeeping() module of a merge program, you read from two input files, check for the end of each file, and set a flag if both input files are at eof You use a master file to hold relatively permanent data and a transaction file to hold more temporary data that corresponds to records in the master file The logic you use to perform a match between master and transaction file records involves comparing the files to determine whether there is a transaction for each master record; when there is, you update the master record

11 Chapter 1131 Summary Using the logic that allows multiple transactions per master file record, whenever a transaction matches a master file record, you process the transaction, then you read only from the transaction file A sophisticated update program allows you to make changes to data in a record and update a master file by adding new records or eliminating records you no longer want