1 Chapter 14 - Sorting System Concepts –Sort key Major Key (Primary) Minor Key (Secondary) –Sort sequence Ascending - Low to high Descending – High to.

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

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)
Concepts of Database Management Seventh Edition
Concepts of Database Management Sixth Edition
Concepts of Database Management Seventh Edition
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)
Concepts of Database Management Sixth Edition
Microsoft Access 2010 Chapter 7 Using SQL.
Structured COBOL Programming, Stern & Stern, 9th Edition
VSAM KSDS and COBOL Department of Computer Science Northern Illinois University August 2005 Some of the illustrations are from VSAM: Access Method Services.
Concepts of Database Management, Fifth Edition
COBOL Basics 1. COBOL coding rules  Almost all COBOL compilers treat a line of COBOL code as if it contained two distinct areas. These are known as;
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.
Fortran 1- Basics Chapters 1-2 in your Fortran book.
Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout.
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)
12- 1 Chapter 12.  Single-Level OCCURS Clauses  Processing Data Stored in Array  Using OCCURS Clause for Table Handling  Use of SEARCH Statement 
History COBOL (Common Business Oriented Language) was one of the earliest high-level programming languages. COBOL was first proposed in 1959 by the Conference.
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed.
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.
UNIT 1 UNIT 1 Stephen S. Linkin Houston Community College System 8/28/ Copywrite © Houston Community College System 2007 Graphics Courtesy of IBM.
CS CS Computing for Business Instructor:David Tucker GTA:Batul Mirza.
Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File.
1 Single Table Queries. 2 Objectives  SELECT, WHERE  AND / OR / NOT conditions  Computed columns  LIKE, IN, BETWEEN operators  ORDER BY, GROUP BY,
Concepts of Database Management Seventh Edition
Using Special Operators (LIKE and IN)
Concepts of Database Management Seventh Edition
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.
1 Chapter – 12 Table Lookups Table Codes –Expanded Values –Types of Codes Numeric Alphabetic Alphanumeric.
Lecture 81 Table Search (1) 02ART HISTORY 04BIOLOGY 19CHEMISTRY 21CIVIL ENGINEERING 24COMP INF SYS 32ECONOMICS 39FINANCE 43MANAGEMENT 49MARKETING 54STATISTICS.
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.
CPSC3111/CISM3111 COBOL Structured COBOL Programming Text: murach’s structured COBOL Authors: Murach, Prince, Menendez.
Microsoft Office XP Illustrated Introductory, Enhanced Tables and Queries Using.
Concepts of Database Management Eighth Edition Chapter 3 The Relational Model 2: SQL.
More Syntax in COBOL  Moving Data  Selection Statements  System Date  Indicators in Display files.
Structured Programming
1 Chapter 5 – The Procedure Division File handling statements –OPEN statement Initiates processing for a file Input Output Each file opened must have been.
13-1 Sequential File Processing Chapter Chapter Contents Overview of Sequential File Processing Sequential File Updating - Creating a New Master.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
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.
Lecture 21 ENVIRONMENT DIVISION  defines files external to the program and devices.  contains two sections: 1.CONFIGURATION SECTION.  identifies computers.
13- 1 Chapter 13.  Overview of Sequential File Processing  Sequential File Updating - Creating a New Master File  Validity Checking in Update Procedures.
Business Programming I Fall – 2000 By Jim Payne Lecture 05Jim Payne - University of Tulsa2 Alphanumeric Storage Numbers that are not numbers? Alphabetic.
COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
Analysis of SAMPLE1.CBL Please check speaker notes for additional information!
11- 1 Chapter 11.  Avoiding Logic Errors by Validating Input  What to Do If Input Errors Occur  Global Considerations in COBOL  When Data Should Be.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
LOGICAL CONTROL STRUCTURES (chp. 8)
Sorting in COBOL M. M. Pickard.
Submitting Instructions on web site CS 1024 students Read guide
THE SORT STATEMENT for files (chp. 14)
Structured Programming
Chapter 2 (16M) Sorting and Searching
Designing and Debugging Batch and Interactive COBOL Programs
Chapter 3 The DATA DIVISION.
Chapter 14 Sorting and Merging.
Dr. Clincy Professor of CS
Agenda Collating sequence / Sorting data
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
CHAPTER 17 The Report Writer Module
Any Questions?.
Decision Making Using the IF and EVALUATE Statements
Presentation transcript:

1 Chapter 14 - Sorting System Concepts –Sort key Major Key (Primary) Minor Key (Secondary) –Sort sequence Ascending - Low to high Descending – High to low

2 Figure 14.1Sorting Vocabulary NAME YEARMAJOR Smith1Liberal arts Jones4Engineering Adams3Business Howe2Liberal arts Frank1 Engineering Zev4Business Benjamin 4Business Grauer3Liberal arts Crawford 2Engineering Deutsch4Business Makoske 1Business (a) Unsorted Data

3 Primary Key: Name (Ascending) NAME YEARMAJOR Adams3Business Benjamin 4Business Crawford 2Engineering Deutsch4Business Frank1 Engineering Grauer3Liberal arts Howe2Liberal arts Jones4Engineering Makoske 1Business Smith1Liberal arts Zev4Business Figure 14.1 (b) Sorted Data, One Key

4 Primary key: Year (descending) Secondary key: Name (ascending) NAME YEARMAJOR Benjamin 4Business Deutsch4Business Jones4Engineering Zev4Business Adams3Business Grauer3Liberal arts Crawford 2Engineering Howe2Liberal arts Frank1 Engineering Makoske 1Business Smith1Liberal arts Figure 14.1 Sorted Data, Two Keys

5 Figure 14.1 Sorted Data, Three Keys Primary Key: major (Ascending) Secondary Key: year (Descending) Tertiary Key: name (Ascending) NAMEYEARMAJOR Benjamin 4Business Deutsch4Business Zev4Business Adams3Business Makoske 1Business Jones4Engineering Crawford 2Engineering Frank1 Engineering Grauer3Liberal arts Howe2Liberal arts Smith1Liberal arts

6 –Collating Sequence (order of sorting) Alphabetic fields –Green vs. Greenfield Alphanumeric fields – 111 vs. AAA EBCDIC sequence – IBM Mainframe ASCII sequence – Most other computers

7 EBCDIC (space).(period, decimal point) (greater than) ‘(apostrophe) =(equal sign) “(quotation mark) a through z (lower case) A through Z (upper case) 0 through 9 ASCII (space) “(quotation mark) $(currency symbol) ‘(apostrophe) ((left parenthesis) )(right parenthesis) *(asterisk) +(plus symbol),(comma) -(hyphen, minus symbol).(period, decimal point) /(slash) 0 through 9 ;(semicolon) (greater than) A through Z (upper case) a through z (lower case) Figure 14.2EBCDIC & ASCII Collating Sequences

8 COBOL Implementation –SORT command Syntax INPUT PROCEDURE statement –Selective sorting –Sorting on calculated fields USING statement OUTPUT PROCEDURE statement –Use of temporary work file GIVING statement –Retention of sorted data

9 SORT file-name-1 ON {DESCENDING KEY { data-name-1}... } ASCENDING} WITH DUPLICATES IN ORDER COLLATING SEQUENCE IS alphabet-name INPUT PROCEDURE IS procedure-name-1 USING {file-name-2} OUTPUT PROCEDURE IS procedure-name-2 GIVING {fine-name-3} SORT syntax

10 Uses 3 files to sort –Input file – contains unsorted records –Output file – contains sorted records –Sort file – temporary file used by COBOL to sort the records First 2 must be defined in the FD section Sort file must be defined in a SD section

11 Input File Sort Output File Sort file

12 Ex.) SD SALESPERSON-SORT-FILE 01 SALESPERSON-SORT-RECORD 05 SP-REGION PIC SP-NUMBER PIC XXXX. 05 FILLER PIC X(52). … SORT SALESPERSON-SORT-FILE ON ASCENDING KEY SP-REGION SP-NUMBER USING SALESPERSON-INPUT-FILE GIVING SALESPERSON-OUTPUT-FILE

13 SORT SALESPERSON-SORT-FILE ON DESCENDING KEY SP-REGION ON ASCENDING KEY SP-NUMBER USING SALESPERSON-INPUT-FILE GIVING SALESPERSON-OUTPUT-FILE

14 Assume that the records in a file named X-FILE are to be sorted descending sequence by X-FIELD. The records in X-FILE are 40 characters long. X-FIELD is located in positions 8-12 and is alphanumeric. The file sorted output is called Y-FILE a. Code the SD entry and record description b. Code the sort statement c. Assume is should be sorted into ascending sequence by Y-FIELD and then into descending sequence by X- FIELD. Code the sort statements.

15 The registrar has asked for a simple report listing students by year, and alphabetically within year. Thus all freshmen are to appear first, then sophomores..The incoming record has the follow layout: 01 STUDENT-RECORD. 05 ST-NAME PIC X(15). 05 ST-MAJOR PIC X(15). 05 ST-YEAR PIC XX. 05 ST-CREDITSPIC X(10). ST-YEAR USES FR,SO,JR AND GR. Develop the procedure division code to accomplish the desired sort.

16 Merge statement