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)

Slides:



Advertisements
Similar presentations
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)
Advertisements

12-1 Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout John.
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)
16-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)
The Future of COBOL A Focus on Interactive Programming Appendix C Stern & Stern.
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)
Chapter 15 Creating Database Forms and Reports Introduction Forms Reports.
Chapter 5: Database Forms and Reports
7-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)
5-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.
Chapter 81 Creating a Production Process Chapter 8 Achieving Quality Through Continual Improvement Claude W. Burrill / Johannes Ledolter Published by John.
POKOK BAHASAN Pertemuan 25 Matakuliah: Sistem Informasi Manajemen Tahun: 2008.
Chapter 101 Information Technology For Management 6 th Edition Turban, Leidner, McLean, Wetherbe Lecture Slides by L. Beaubien, Providence College John.
COBOL for the 21st Century
Accounting Information Systems, 1st Edition
Introduction to Databases
Structured COBOL Programming, Stern & Stern, 9th Edition
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)
Structured COBOL Programming, Stern & Stern, 9th Edition PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured.
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)
Accounting Principles, Ninth Edition
12-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)
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)
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-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)
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.
PowerPoint Presentation for Dennis & Haley Wixom, Systems Analysis and Design, 2 nd Edition Copyright 2003 © John Wiley & Sons, Inc. All rights reserved.
John Wiley & Sons, Inc. © 2005 Chapter 2 The Recording Process Prepared by Naomi Karolinski Monroe Community College and and Marianne Bradford Bryant.
Chapter 4: Organizing and Manipulating the Data in Databases
Accounting Principles, Ninth Edition
Today’s Agenda  Any questions about the assignment (due Mon)?  Quiz  Quiz review  Homework for Friday:  Watch the two videos on the Coursera db website.
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
PowerPoint Presentation for Dennis & Haley Wixom, Systems Analysis and Design Copyright 2000 © John Wiley & Sons, Inc. All rights reserved. Slide 1 Systems.
7-1 Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout John.
3-1 The DATA DIVISION Chapter Chapter Objectives To familiarize you with Systems design considerations Ways in which data is organized Rules for.
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.
PowerPoint Presentation for Dennis, Wixom, & Roth Systems Analysis and Design, 3rd Edition Copyright 2006 © John Wiley & Sons, Inc. All rights reserved.
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)
Copyright © 2000 John Wiley & Sons, Inc. All rights reserved
9-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)
9-1 Iteration: Beyond the Basic PERFORM Chapter 9.
Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout.
PowerPoint Presentation for Dennis & Haley Wixom, Systems Analysis and Design, 2 nd Edition Copyright 2003 © John Wiley & Sons, Inc. All rights reserved.
Slide 1-1 Chapter 1 Terms Information Systems Overview Introduction to Information Systems Judith C. Simon.
Slide 1-1 Chapter 1 Information Systems Overview Introduction to Information Systems Judith C. Simon.
Slide 5-1 Chapter 5 Terms Applications Software for Business Introduction to Information Systems Judith C. Simon.
Copyright © 2000 John Wiley & Sons, Inc. All rights reserved. Reproduction or translation of this work beyond that permitted in Section 117 of the 1976.
7-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.
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.
COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
12-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)
Slide 8-1 Chapter 8 Terms Programming Languages Introduction to Information Systems Judith C. Simon.
A- 1. A- 2 Appendix B Standards of Ethical Conduct for Management Accountants The Institute of Management Accountants has published and promoted the following.
K-1. K-2 Appendix K Standards of Ethical Conduct for Management Accountants The Institute of Management Accountants has published and promoted the following.
Slide 11-1 Chapter 11 Terms Information Resource Management Strategies Introduction to Information Systems Judith C. Simon.
I-1. I-2 I ACCOUNTING FOR SOLE PROPRIETORSHIPS Accounting, Fifth Edition.
Slide 6-1 Chapter 6 Terms System Software Considerations Introduction to Information Systems Judith C. Simon.
“Copyright © 2001 John Wiley & Sons, Inc. All rights reserved. Reproduction or translation of this work beyond that permitted in Section 117 of the 1976.
Sorting in COBOL M. M. Pickard.
Financial Accounting, IFRS Edition
liquidation of a partnership.
Chapter 3 The DATA DIVISION.
Structured COBOL Programming
Chapter 14 Sorting and Merging.
Presentation transcript:

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) John Wiley & Sons, Inc. 11th edition

14-2 Sorting and Merging Chapter 14

14-3 Chapter Objectives To familiarize you with How files may be sorted How to process file during SORT procedure –Before it is sorted –After it is sorted How to merge files

14-4 Chapter Contents SORT Feature Processing Data Before and/or After Sorting MERGE Statement

14-5 SORT Statement Common procedure for arranging records in specific order Then sequential batch processing performed Two techniques for sorting –Use sort utility separate from COBOL program –Use COBOL's SORT verb in program

14-6 SORT Statement SORT file-name-1 ONASCENDING KEY data-name-1 … DESCENDING USING file-name-2 GIVINGfile-name-3 Simplified Format

14-7 ASCENDING, DESCENDING Key To specify sequence for key field –ASCENDING: From lowest to highest –DESCENDING: From highest to lowest Sort key fields may be numeric or nonnumeric Alphanumeric fields sorted according to collating sequence (ASCII or EBCDIC) used by computer

14-8 Multiple Sort Keys Can sequence records with more than one key field Sort payroll file in ascending alphabetic sequence by name, within each level, for each office –Office number - major sort field –Level number - intermediate sort field –Name - minor sort field

14-9 Multiple Sort Keys For Office 1, desired sequence is Office-No Level-NoName 11ADAMS, J. R. 11BROCK, P. T. 11LEE, S. 12ARTHUR, Q. C. 12SHAH, J. 13RAMIREZ, A. P.

14-10 SORT Statement Sorts records into ascending name sequence within level within office Sort Sort-File On Ascending Key Office-No On Ascending Key Level-No On Ascending Key Name Using Payroll-File-In Giving Sort-Payroll-File-Out

14-11 Multiple Sort Keys Choose either ASCENDING or DESCENDING sequence for each key If all key fields to be sorted in same sequence, can condense coding Sort Sort-File On Ascending Key Major-Key Intermediate-Key Minor-Key... Example

14-12 Duplicate Key Values Assume records to be sorted in descending order by salary If both 9th and 24th records in input file have salary of 30000, which appears first in sort file? Can specify that records with same value for key field be placed in sort file in same order that they appear in original input file

14-13 Duplicate Key Example Sort Sort-File On Descending Key Srt-Salary With Duplicates In Order Using Unsorted-File-In Giving Sorted-File-Out DUPLICATES clause ensures that 9th record appears before 24th in Sort-File if both have same Salary value

14-14 Files Used in SORT Input file: File of unsorted input records Work or sort file: File used to store records temporarily during sorting process Output file: File of sorted output records

14-15 Files Used in SORT All defined using standard SELECT … ASSIGN entries All must have same record format All are opened and closed automatically by SORT

14-16 Files Used in SORT Input and output file described with FD entries Sort work file –Described with SD entry (sort file descriptor) –Temporary file used only during sorting but not saved –Sort key fields must be described as part of sort record format

14-17 Sample FILE SECTION Data Division. File Section. FD Unsorted-File-In. 01Unsorted-Rec-In. 05Name-InPic X(20). 05Salary-InPic 9(6).

14-18 Sample FILE SECTION SDSort-File. 01Sort-Rec. 05Srt-NamePic X(20). 05Srt-SalaryPic 9(6). FD Sorted-File-Out. 01Sorted-Rec-Out. 05Name-OutPic X(20). 05Salary-OutPic 9(6).

14-19 Operations Performed by SORT Opens all three files Moves all records from Unsorted-File-In to Sort-File Sorts records in Sort-File in descending sequence by Srt-Salary Moves all records from Sort-File to Unsorted-File-Out Closes all three files

14-20 INPUT PROCEDURE Use in place of USING clause to process data from input file prior to sorting Assume only records with Salary-In < need to be sorted Use Input Procedure to process and select desired records before sorting

14-21 SORT with INPUT PROCEDURE Sort Sort-File On Descending Key Srt-Salary Input Procedure Select-Records Giving Sorted-File-Out Select-Records is name of paragraph written by programmer to process records before sorting

14-22 INPUT PROCEDURE Select-Records paragraph must Open input file (Unsorted-File-In) Perform processing of input records until there is no more data Close input file

14-23 Processing Input Records For each input record, if Salary-In < –Move input data to sort record –RELEASE record to sort file When INPUT PROCEDURE paragraph is completed, control returns to SORT All records released to sort file are sorted

14-24 RELEASE Statement RELEASE sort-record-name-1 [FROM identifier-1] To write a record to the sort file Like WRITE but used to output sort records Format

14-25 INPUT PROCEDURE May be used to Validate data in input records Process only records that meet certain criteria Eliminate records with blank fields Remove unneeded fields from input records Count input records

14-26 OUTPUT PROCEDURE With GIVING option, records in sort file automatically written to output file after sorting Use OUTPUT PROCEDURE to process sorted records prior to, or instead of, placing them in output file

14-27 SORT Statement Format SORT file-name-1 ONASCENDING KEY data-name-1 … … DESCENDING INPUT PROCEDURE IS procedure-name-1 USING file-name-2 … OUTPUT PROCEDURE IS procedure-name-3 GIVING file-name-3 …

14-28 SORT PROCEDURES If INPUT PROCEDURE used –SORT transfers control to paragraph or section named in INPUT PROCEDURE –When complete, sort file is sorted If OUTPUT PROCEDURE used –SORT transfers control to paragraph or section named in OUTPUT PROCEDURE –Processes all sorted records in sort file and handles transfer of records to output file

14-29 SORT PROCEDURES In INPUT PROCEDURE, records RELEASEd to sort file In OUTPUT PROCEDURE, records RETURNed from sort file

14-30 RETURN Statement RETURN sort-file-name-1 AT END imperative statement-1 [ NOT AT END imperative statement-2] [END-RETURN] To retrieve records from the sort file Similar to READ Format

14-31 OUTPUT PROCEDURE Steps Paragraph (or section) must Open output file Perform paragraph to RETURN and process records from sort file until there is no more data Close output file When OUTPUT PROCEDURE finished, control returns to SORT

14-32 Processing Sorted Records After records sorted but before they are created as output Perform any operations on sort records MOVE sort record to output area WRITE each sort record to output file

14-33 SORT Procedures Both INPUT and OUTPUT PROCEDUREs can be used in same program If used, programmer must open/close the input or output file SD (sort) file and files specified with USING or GIVING are automatically opened and closed

14-34 When to use PROCEDUREs More efficient to use INPUT PROCEDURE if many records in input file can be eliminated before sort Use OUTPUT PROCEDURE if records require further processing after sort Must use procedure if input or output file and sorted file have different-sized fields or fields in different order

14-35 SORT Options Review Option:USING GIVING Result: File is sorted No special handling

14-36 SORT Options Review Option:INPUT PROCEDURE GIVING Result: Processes unsorted input records before they are sorted Write records to sort file with RELEASE After INPUT PROCEDURE completed, records are sorted

14-37 SORT Options Review Option:USING OUTPUT PROCEDURE Result: Processes records after they have been sorted but before they are written to output file Read records from sort file with RETURN

14-38 SORT Options Review Option:INPUT PROCEDURE OUTPUT PROCEDURE Result: Processes data both before and after it is sorted

14-39 MERGE Statement To combine two or more files into one Files to be merged must each be in sequence by key field Format similar to SORT, rules for clauses are same

14-40 MERGE Statement Format MERGE file-name-1 ON ASCENDING KEY data-name-1 … … DESCENDING USING file-name-2 file-name-3 … OUTPUT PROCEDURE IS procedure-name-1 GIVING file-name-4 … To combine two or more files into one

14-41 MERGE Statement File-name-1 is work file designated as an SD Keys specified are defined within SD Data-name-1 is major key, may be followed by intermediate and minor keys USING clause names file to be merged –At least two must be included

14-42 MERGE Statement Records may be processed after merging with OUTPUT PROCEDURE, but not before Automatically handles opening, closing, and input/output associated with files

14-43 MERGE Statement Example Suppose two separate files of employees are to be combined into one Both input files and the resulting output file contain 80 characters with an Emp- No in the first nine positions File definitions and MERGE instruction follow

14-44 MERGE Statement Example Data Division. File Section. FDEmp-File-1. 01Emp-Rec-1Pic X(80). FDEmp-File-2. 01Emp-Rec-2Pic X(80).

14-45 MERGE Statement Example SDMerge-File. 01Merge-Rec. 05Mrg-Emp-NoPic X(9). 05Rest-of-RecPic X(71). FDOut-Emp-File. 01Out-Emp-RecPic X(80).

14-46 MERGE Statement Example Procedure Division. 100-Main-Module. Merge Merge-File On Ascending Key Mrg-Emp-No Using Emp-File-1, Emp-File-2 Giving Out-Emp-File Stop Run.

14-47 Chapter Summary SORT used for sorting records in either ascending or descending order SORT uses work or sort file described with an SD Key fields to be sorted are data-names defined within SD or sort file Files may be sorted using more than one key field

14-48 Chapter Summary Routines separate from SORT may be used to –Process unsorted file prior to SORT –Process sorted file after SORT

14-49 Chapter Summary Procedures that are part of SORT permit processing –Just before sort performed (INPUT PROCEDURE) –After sort finished but before writing records to sorted file (OUTPUT PROCEDURE)

14-50 Chapter Summary RELEASE statement used in INPUT PROCEDURE to make input records available for sorting RETURN statement used in OUTPUT PROCEDURE to read records from sort file

14-51 Chapter Summary MERGE statement used to merge two or more files into one

14-52 Copyright © 2003 John Wiley & Sons, Inc. All rights reserved. Reproduction or translation of this work beyond that permitted in Section 117 of the 1976 United States Copyright Act without the express written permission of the copyright owner is unlawful. Request for further information should be addressed to the Permissions Department, John Wiley & Sons, Inc. The purchaser may make back-up copies for his/her own use only and not for distribution or resale. The Publisher assumes no responsibility for errors, omissions, or damages, caused by the use of these programs or from the use of the information contained herein.