Structured COBOL Programming, Stern & Stern, 9th Edition

Slides:



Advertisements
Similar presentations
DT266/2 Information Systems COBOL Revision. Chapters 1 & 2 Hutty & Spence Divisions of a Cobol Program Identification Division Program-ID. Environment.
Advertisements

2-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)
Benchmark Series Microsoft Access 2010 Level 1
8-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)
2-1 Chapter 2.  Coding Requirements of IDENTIFICATION DIVISION  Sections of ENVIRONMENT DIVISION  Assigning Files to Devices in ENVIRONMENT DIVISION.
3-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emertius)
MODULE 4 File and Folder Management. Creating file and folder A computer file is a resource for storing information, which is available to a computer.
The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2.
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
14-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)
Guide To UNIX Using Linux Third Edition
Microsoft Office Word 2013 Expert Microsoft Office Word 2013 Expert Courseware # 3251 Lesson 4: Working with Forms.
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
Chapter 8 Printing 1. In COBOL you send data to the printer by writing data to a file. In COBOL, the printer is defined as a file, and it is opened, closed,
Chapter Seven Advanced Shell Programming. 2 Lesson A Developing a Fully Featured Program.
VSAM KSDS and COBOL Department of Computer Science Northern Illinois University August 2005 Some of the illustrations are from VSAM: Access Method Services.
15-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)
Topics Covered: Data preparation Data preparation Data capturing Data capturing Data verification and validation Data verification and validation Data.
Chapter 15 Relative Files.  File organization that converts key field to actual disk address to find location of record No need to look up disk address.
Structured COBOL Programming, Stern & Stern, 9th edition
4-1 Coding Complete COBOL Programs: The PROCEDURE DIVISION Chapter 4.
4-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)
4-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)
2-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)
1 Chapter 4. To familiarize you with methods used to 1. Access input and output files 2. Read data from an input file 3. Perform simple move operations.
3-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emertius)
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
Chapter Four UNIX File Processing. 2 Lesson A Extracting Information from Files.
Guide To UNIX Using Linux Fourth Edition
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
1 Chapter 14 - Sorting System Concepts –Sort key Major Key (Primary) Minor Key (Secondary) –Sort sequence Ascending - Low to high Descending – High to.
The DATA DIVISION Chapter 3. COBOL Data Organization Field - group of characters forming a meaningful unit or basic fact –Characters in a name or digits.
3-1 Chapter 3. To familiarize you with  Ways in which data is organized in COBOL  Rules for forming data-names  Defining input and output files in.
3-1 The DATA DIVISION Chapter Chapter Objectives To familiarize you with Systems design considerations Ways in which data is organized Rules for.
Discovering Computers Fundamentals Fifth Edition Chapter 9 Database Management.
14- 1 Chapter 14.  To familiarize you with ◦ How files may be sorted ◦ How to process file during SORT procedure  Before it is sorted  After it is.
Chapter 7 File I/O 1. File, Record & Field 2 The file is just a chunk of disk space set aside for data and given a name. The computer has no idea what.
Indexed and Relative File Processing
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.
Pseudocode Simple Program Design Third Edition A Step-by-Step Approach 2.
Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout.
Structured Programming
12- 1 Chapter 12.  Single-Level OCCURS Clauses  Processing Data Stored in Array  Using OCCURS Clause for Table Handling  Use of SEARCH Statement 
Structured COBOL Programming, Stern & Stern, 9th Edition CHAPTER 2 Cobol Language Fundamentals.
13-1 Sequential File Processing Chapter Chapter Contents Overview of Sequential File Processing Sequential File Updating - Creating a New Master.
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
2-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)
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.
Lesson 13 Databases Unit 2—Using the Computer. Computer Concepts BASICS - 22 Objectives Define the purpose and function of database software. Identify.
13- 1 Chapter 13.  Overview of Sequential File Processing  Sequential File Updating - Creating a New Master File  Validity Checking in Update Procedures.
Session 1 Module 1: Introduction to Data Integrity
COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
Aggregator  Performs aggregate calculations  Components of the Aggregator Transformation Aggregate expression Group by port Sorted Input option Aggregate.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Sorting in COBOL M. M. Pickard.
THE SORT STATEMENT for files (chp. 14)
Structured Programming
Designing and Debugging Batch and Interactive COBOL Programs
Topics Introduction to File Input and Output
Chapter 3 The DATA DIVISION.
An Introduction to Structured Program Design in COBOL
Structured COBOL Programming
Chapter 14 Sorting and Merging.
Chapter Four UNIX File Processing.
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
CHAPTER 17 The Report Writer Module
Topics Introduction to File Input and Output
Decision Making Using the IF and EVALUATE Statements
Presentation transcript:

Structured COBOL Programming, Stern & Stern, 9th Edition SORTING AND MERGING Structured COBOL Programming, Stern & Stern, 9th Edition

Structured COBOL Programming, Stern & Stern, 9th Edition OBJECTIVES To Familiarize you with: 1. How files may be sorted within a COBOL program. 2. How to process a file during a SORT procedure before it is actually sorted. 3. How to process a file during a SORT procedure after it is sorted but before it is created as output. 4. How to use the MERGE verb for merging files. Structured COBOL Programming, Stern & Stern, 9th Edition

Structured COBOL Programming, Stern & Stern, 9th Edition CONTENTS THE SOFT FEATURE: AN OVERVIEW Format of the SORT Statement ASCENDING or DESCENDING KEY Coding a Simple SORT Procedure with the USING and GIVING Options PROCESSING DATA BEFORE AND/OR AFTER SORTING INPUT PROCEDURE OUTPUT PROCEDURE When to Use INPUT and/or OUTPUT Procedures THE MERGE STATEMENT Structured COBOL Programming, Stern & Stern, 9th Edition

Structured COBOL Programming, Stern & Stern, 9th Edition THE SORT STATEMENT Records in files frequently must be sorted into specific sequences for updating, answering inquiries, or generating reports. Sorting is a common procedure used for arranging records into a specific order so that sequential processing can be performed. There are two techniques used for sorting files processed by COBOL programs. One is to use either a utility or a database management system's sort program. This sort program is completely separate from the COBOL program. Structured COBOL Programming, Stern & Stern, 9th Edition

FORMAT OF THE SORT STATEMENT The second alternative is COBOL's SORT verb, which can make it very useful as part of a COBOL program. Often, a COBOL program will SORT a file prior to processing it. A simplified format follows: SORT file-name-1 {ON {DESCENDING}{ASCENDING} KEY data-name-1. .} USING file-name-2 GIVING file-name-3 Structured COBOL Programming, Stern & Stern, 9th Edition

ASCENDING or DESCENDING Key The programmer must specify whether the key field is to be an ASCENDING KEY or a DESCENDING KEY, depending on which sequence is required: (1) ASCENDING: From lowest to highest (2) DESCENDING: From highest to lowest Records may be sorted using either numeric or nonnumeric key fields. Structured COBOL Programming, Stern & Stern, 9th Edition

ASCENDING or DESCENDING Key Collating Sequence The two major codes used for representing data in a computer are EBCDIC primarily used on mainframes, and ASCII used widely on PCs. The sequence of characters from lowest to highest, which is referred to as the collating sequence, is somewhat different in EBCDIC and ASCII. Structured COBOL Programming, Stern & Stern, 9th Edition

Structured COBOL Programming, Stern & Stern, 9th Edition Collating Sequence EBCDIC ASCII Low Blank Blank Special Characters Special Characters Lowercase letters a-z Integers 0-9 Uppercase letters A-Z Special Characters Integers 0-9 Uppercase letters A-Z High Lowercase letters a-z Structured COBOL Programming, Stern & Stern, 9th Edition

Sequencing Records with More Than One SORT Key The SORT verb may be used to sequence records with more than one key field. Suppose that we wish to sort fields in ascending alphabetic sequence by name, within each office. That is: Office number is the major sort field Level number is the intermediate sort field Name is the minor sort field Structured COBOL Programming, Stern & Stern, 9th Edition

Sequencing Records with More Than One SORT Key The following is a SORT statement that sorts records into ascending alphabetic NAME sequence within LEVEL-NO within OFFICE-NO: SORT SORT-FILE ON ASCENDING KEY OFFICE-NO ON ASCENDING KEY LEVEL-NO ON ASCENDING KEY NAME USING PAYROLL-FILE-IN GIVING SORTED-PAYROLL-FILE-OUT Structured COBOL Programming, Stern & Stern, 9th Edition

ASCENDING / DESCENDING Key If all key fields are to be sorted in ascending sequence we can code using the phrase ON ASCENDING KEY only once: SORT SORT-FILE ON ASCENDING KEY MAJOR-KEY INTERMEDIATE -KEY MINOR-KEY Structured COBOL Programming, Stern & Stern, 9th Edition

Coding a Simple SORT Procedure with the USING and GIVING Options There are three major files used in a sort: 1. Input file: File of unsorted input records. 2. Work or sort file: File used to store records temporarily during the sorting process. 3. Output file: File of sorted output records. Structured COBOL Programming, Stern & Stern, 9th Edition

Coding a Simple SORT Procedure with the USING and GIVING Options A sort file is usually assigned to a special work device--in the ENVIRONMENT DIVISION--indicated as SYSWORK in the following: SELECT UNSORTED-MASTERN-FILE ASSIGN TO DISK1. SELECT SORT-FILE ASSIGN TO SYSWORK. SELECT SORTED-MASTERN-FILE ASSIGN TO DISK2. Structured COBOL Programming, Stern & Stern, 9th Edition

Coding a Simple SORT Procedure with the USING/GIVING Options The SORT-FILE is actually assigned to a temporary work area that is used during processing but not saved. Only the unsorted disk file and the sorted output disk file are assigned standard file-names so that they can be permanently stored. FDs are used in the DATA DIVISION to define and describe the input and output files in the usual way. The sort or work file is described with an SD entry. Structured COBOL Programming, Stern & Stern, 9th Edition

Structured COBOL Programming, Stern & Stern, 9th Edition THE MERGE STATEMENT COBOL has a MERGE statement that will combine two or more files into a single file. Its format is similar to that of the SORT: MERGE file-name-1 {ON {ASCENDING} {DESCENDING} KEY data-name-1. .} USING file-name-2 {file-name-3} . . . {OUTPUT PROCEDURE IS procedure-name-1 GIVING {file-name-4 [{THROUGH}{THRU} procedure-name-2]} Structured COBOL Programming, Stern & Stern, 9th Edition

Structured COBOL Programming, Stern & Stern, 9th Edition THE MERGE STATEMENT File-name-1 is a work file designated as an SD. The key field specified as data-name-1, and any subsequent key fields, are defined within the SD. The first key field indicated in the ASCENDING or DESCENDING KEY clause of the MERGE is the major one, followed by intermediate and minor key fields. Rules for ASCENDING/DESCENDING KEY, USING, GIVING, and OUTPUT PROCEDURE are the same as for the SORT. Structured COBOL Programming, Stern & Stern, 9th Edition

Structured COBOL Programming, Stern & Stern, 9th Edition THE MERGE STATEMENT With the USING clause, we indicate the files to be merged. Unlike the SORT, however, an INPUT PROCEDURE may not be specified with a MERGE statement: you may only process records after they have been merged, not before. The OUTPUT PROCEDURE has the same format as the SORT and may be used with a MERGE to: 1. Flag duplicate records as errors. 2. Ensure duplicate records. Structured COBOL Programming, Stern & Stern, 9th Edition

Structured COBOL Programming, Stern & Stern, 9th Edition THE MERGE STATEMENT The MERGE statement automatically handles the opening, closing, and input/output (READ/WRITE functions) associated with the files. The files to be merged must each be in sequence by the key field. If ASCENDING KEY is specified, then the merged output file will have records in increasing order by key field. If DESCENDING KEY is specified, the merged output file will have key fields from high to low. Structured COBOL Programming, Stern & Stern, 9th Edition

Structured COBOL Programming, Stern & Stern, 9th Edition CHAPTER SUMMARY A. The SORT is used for sorting records in either ascending or descending order. 1. A program can simply sort a file on key fields: SORT file-name-1 {ON {ASCENDING}{DESCENDING} KEY data-name1...}... USING file-name-2 GIVING file-name-3 Structured COBOL Programming, Stern & Stern, 9th Edition

Structured COBOL Programming, Stern & Stern, 9th Edition CHAPTER SUMMARY a. File-name-1 is a work or sort file that is described with an SD (sort file description) in the FILE SECTION. b. The KEY field(s) to be sorted are data-names defined within the SD or sort file. c. Files can be sorted into ascending or descending sequence. d. Files can be sorted using more than one key field. The first field specified is the main sort field followed by intermediate and/or minor ones. Structured COBOL Programming, Stern & Stern, 9th Edition

Structured COBOL Programming, Stern & Stern, 9th Edition CHAPTER SUMMARY B. The MERGE statement can be used to merge two or more files. It is very similar to the SORT. It can have a USING and GIVING option or an OUTPUT PROCEDURE in place of the GIVING option. It cannot, however, have an INPUT PROCEDURE. Structured COBOL Programming, Stern & Stern, 9th Edition