12-1 Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout John.

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)
Chapter 12 Array Processing and Table Handling. Defining Series of Input Fields Coding record with 24 independent hourly fields is cumbersome 01Temp-Rec.
SUPPLEMENTARY CHAPTER 2 Instruction Addressing Modes
John Wiley & Sons, Inc. Prepared by Karleen Nordquist.. The College of St. Benedict... and St. John’s University.... Managerial Accounting Weygandt, Kieso,
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)
Accounting Information Systems
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
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 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)
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)
PowerPoint Presentation for Dennis, Wixom & Tegarden Systems Analysis and Design Copyright 2001 © John Wiley & Sons, Inc. All rights reserved. Slide 1.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 6 - Arrays Outline 6.1Introduction 6.2Arrays.
Chapter 6 C Arrays Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc. Arrays are data structures.
CHAPTER 5: Floating Point Numbers
 2007 Pearson Education, Inc. All rights reserved C Arrays.
Accounting Information Systems, 1st Edition
Introduction to Databases
Systems Analysis and Design
Systems Analysis and Design
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)
PowerPoint Presentation for Dennis, Wixom, & Roth Systems Analysis and Design, 3rd Edition Copyright 2006 © John Wiley & Sons, Inc. All rights reserved..
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)
12-1 Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout John.
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)
Introduction to Databases Chapter 7: Data Access and Manipulation.
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.
12- 1 Chapter 12.  Single-Level OCCURS Clauses  Processing Data Stored in Array  Using OCCURS Clause for Table Handling  Use of SEARCH Statement 
PowerPoint Presentation for Dennis & Haley Wixom, Systems Analysis and Design, 2 nd Edition Copyright 2003 © John Wiley & Sons, Inc. All rights reserved.
Accounting Principles, Ninth Edition
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
7 - 1 Chapter 7: Data Analysis for Modeling PowerPoint Slides Prepared By: Alan Olinsky Bryant University Management Science: The Art of Modeling with.
PowerPoint Presentation for Dennis & Haley Wixom, Systems Analysis and Design Copyright 2000 © John Wiley & Sons, Inc. All rights reserved. Slide 1 Systems.
5-1 Chapter 5 The Repetition Process in VB.NET. 5-2 Learning Objectives Understand the importance of the repetition process in programming. Describe the.
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.
Chapter 12 (part 2) Table Handling and Search Techniques.
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)
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.
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.
12- 1 Chapter 12.  Single-Level OCCURS Clauses  Processing Data Stored in Array  Using OCCURS Clause for Table Handling  Use of SEARCH Statement 
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)
4-1 Chapter 4 The Selection Process in VB.NET. 4-2 Learning Objectives Understand the importance of the selection process in programming. Describe the.
6-1 Chapter 6 Working with Arrays in VB.NET. 6-2 Learning Objectives Understand the use of list and table arrays in VB.NET projects and the difference.
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)
 2007 Pearson Education, Inc. All rights reserved C Arrays.
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.
COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
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.
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)
Array Applications. Objectives Design an algorithm to load values into a table. Design an algorithm that searches a table using a sequential search. Design.
I-1. I-2 I ACCOUNTING FOR SOLE PROPRIETORSHIPS Accounting, Fifth Edition.
Chapter 2-1. Chapter 2-2 Chapter 2 The Recording Process 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)
Systems Analysis and Design
More About COBOL Tables
Chapter 3 The DATA DIVISION.
Structured COBOL Programming
Systems Analysis and Design
Presentation transcript:

12-1 Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout John Wiley & Sons, Inc. PowerPoint Winifred J. Rex Presentation Bowling Green State University 10th edition

12-2 Array Processing and Table Handling Part 2 Chapter 12

12-3 SEARCH Statement SEARCH identifier-1 [AT END imperative-statement-1] WHEN condition-1 imperative-statement-2... CONTINUE [END-SEARCH] Use in place of PERFORM to search table Explain the syntax! What is required? What is optional? Format

12-4 SEARCH Statement Example Set X1 To 1- We use the set verb. Search Table-Entries At End Move 0 To WS-Sales-Tax When Zip-In = WS-ZipCode (X1) Compute WS-Sales-Tax Rounded = WS-Tax-Rate (X1) * Unit-Price-In * Qty-In End-Search

12-5 SEARCH Statement Identifier used after SEARCH is table name specified in OCCURS entry Condition compares search argument to table argument WHEN clause indicates action to take when condition is met AT END clause specifies action to take if table searched but no match found

12-6 Once set, the index automatically advances for you until one of two things happens: –A hit is encountered, or –End of target is encountered. –YOU must test to see which one occurred.

12-7 INDEXED BY clause Special field called index must be used with SEARCH Similar to subscript but defined along with table as part of OCCURS 05Table-Entries Occurs 1000 Times Indexed By X1. Note the syntax. Compiler automatically supplies appropriate PICTURE clause for index X1 defined as index

12-8 Index with SEARCH Must initialize index before SEARCH SEARCH performs table look-up, automatically incrementing index VERY MUCH TRUE: Internally, computer can use faster method to access table entries with an index than with a subscript, even when SEARCH not used Both can have values from 1 to number of table elements

12-9 Modifying Index PERFORM … VARYING can modify subscript or index SET is only other statement that can modify index TO SET index-name-1 UP BY integer-1 DOWN BY Format You cannot say, Add 1 to index-name-1.

12-10 SET Statement Examples SET options used to initialize, increment or decrement index value Assume X1 = 3 before each statement StatementValue of X1 after SET Set X1 To 11 Set X1 Up By 25 Set X1 Down By 12 Recognize, that once an index is set, the SEARCH will automatically adjust its value. If you are restarting a SEARCH, you must reset the index via a SET statement.

12-11 Subscripts vs Indexes Subscript –Represents occurrence of array or table element Index –Represents value used internally to actually access table entry (a displacement from first address in array or table) Now, while more complex, the index is the MUCH more efficient way to process tables! Will explain in class.

12-12 Subscripts vs Indexes Subscript –Defined in separate WORKING- STORAGE entry –May be used any where field with its PICTURE is allowed Index –Defined along with OCCURS –May be used only with table for which it was defined

12-13 Subscripts vs Indexes Subscript –Value may be changed using PERFORM … VARYING –Also by MOVE or arithmetic statements Index –Value may be changed using PERFORM … VARYING –SET only other statement to modify index –But the Search will automatically adjust it for you as part of how the SEARCH runs.

12-14 Serial Search Each entry (usually starting with first) checked in order until either: Condition is met Table completely searched

12-15 Serial Search Best used when Entries not in order by table argument value (not in numerical or alphabetical order) Entries can be organized so first values are ones searched for most frequently, minimizing search time, but this is often not the case.

12-16 Binary Search Most efficient type of look-up when table entries in sequence by some table field On average, takes far fewer comparisons to find match than serial search, if table is ordered and sufficiently large. (will discuss) Called binary search because each comparison eliminates half of entries under consideration

12-17 Binary Search Example Assume a table contains 50 customer numbers in ascending sequence Search table to find match for customer number 5000 stored in input field Cust- No-In

12-18 Binary Search Example ComparisonEntry #T-Customer-No …... 1st …... 3rd …... 4th …... 2nd …...

12-19 Binary Search Method Compare Cust-No-In to middle table argument for T-Customer-In (25th element) Cust-No-In > T-Customer-No (25) or 5000 > 4300 –First half of table eliminated from search since entries are in ascending order

12-20 Binary Search Method Compare Cust-No-In to middle table argument in top of table –Entry 37 is middle of remaining entries Continue until –Match is found –Table search complete and no match found

12-21 Binary Search Method  Serial search would require 34 comparisons in this example  Binary search requires only four Use binary search for large table (50 or more entries) (50 is probably too small and represents older technology. I’d offer at least size = 100). Table entries must be arranged in sequence by some table field Yes, that is, SORTED.

12-22 Binary Search Statement SEARCH ALL identifier-1 [AT END imperative-statement-1] WHEN data-name-1 = identifier-2 literal-1 condition-1 arithmetic- expression-1 imperative-statement-2 CONTINUE [END-SEARCH] Format (partial) Explain this syntax!!

12-23 SEARCH ALL Limitations Condition in WHEN can test only for equality between table and search argument Condition following WHEN may be compound; that is, –Only ANDs permitted, not ORs –Each relational test can test only for equality

12-24 SEARCH ALL Limitations Only one WHEN clause can be used VARYING option may not be used Table argument and its index must appear to left of equal sign –Valid: When T-Customer-No (X1) = Cust-No-In –Invalid: When Cust-No-In = T-Customer-No (X1) Do you understand???

12-25 Key Field – Required in Search ALL Must include clause to indicate which table entry serves as key field Must specify whether KEY is –ASCENDING KEY - entries in sequence, increasing in value –DESCENDING KEY - entries in sequence, decreasing in value

12-26 COBOL Changes Can assign every element in table same initial value with single VALUE clause INDEXED BY and KEY phrases permitted in any sequence SORT verb can be used to sort table entries as well as files

12-27 Multiple-Level OCCURS Up to seven levels of OCCURS permitted in COBOL For example, define an array to store hourly temperature readings for each day during a given week –Need two-dimensional array with 7 rows, each with 24 columns

12-28 Multiple-Level OCCURS Define array as follows: 01Temperature-Array. 05Day-In-Week Occurs 7 Times. 10Hour Occurs 24 Times. 15 TempPic S9(3). For each Day-In-Week there are 24 Hour figures, each consisting of a Temp three integers long Can you draw this??

12-29 Double-Level Subscripts To access temperatures, use data- name on lowest OCCURS level or any data-name subordinate to it –Either Temp or Hour could be used Since Temp defined with two OCCURS, two subscripts must be used to access each hourly temperature For example, Temp (3, 5) refers to the temperature for the third day, fifth hour

12-30 Table with Subscripts Temperature Array Hour1 AM2 AM3 AM4 AM…12 Mid Day-In- Week Day 1 (Sun)(1,1)(1,2)(1,3)(1,4)…(1,24) Day 2 (Mon)(2,1)(2,2)(2,3)(2,4)…(2,24) Day 3 (Tue)(3,1)(3,2)(3,3)(3,4)…(3,24) Day 4 (Wed)(4,1)(4,2)(4,3)(4,4)…(4,24) ………………… Day 7 (Sat)(7,1)(7,2)(7,3)(7,4)…(7,24)

12-31 Two Dimensional Arrays Are extremely common. So very many tables are 2d tables –Pay tables –Buying tires? Size and across top: options (makes of tires)…

12-32 Consider: (Hint!!!) 01 Big-Grade-Table. (in Working-Storage???) 05 Grade-Table Occurs 46 Times. 10 T-Name PIC X(16). 10 T-Grades Occurs 5 Times PIC 999. (Have done initial read of input file and not at end.) Perform Varying X from 1 by 1 until EOF = 1 Move Name-In to T-Name(X) Perform Varying Y from 1 by 1 until Y > 5 Move Grade-In(y) to T-Grades(X,Y) End-Perform Read next record from input file at end Move 1 to F-EOF end-READ End-Perform What do you think??? We will discuss!!

12-33 Accessing Double-Level Array Find average temperature for entire week Add all array entries and divide by 168 (7 x 24) Use nested PERFORMs –First PERFORM varies major (row) subscript from 1 to 7 –Second PERFORM varies minor (column) subscript from 1 to 24

12-34 Accessing Double-Level Array Move 0 To Total Perform Varying Day-Sub From 1 By 1 Until Day-Sub > 7 Perform Varying Hour-Sub From 1 By 1 Until Hour-Sub > 24 Add Temp (Day-Sub, Hour-Sub) To Total End-Perform Compute Weekly-Average = Total / 168 Go through this. Indentation; which Perform is ‘in charge?’ Values of subscripts varying?...

12-35 PERFORM … VARYING … AFTER Use in place of multiple nested PERFORM … VARYING statements VARYING clause varies major subscript AFTER clause varies minor subscript Requires procedure name after PERFORM Let’s you do two performs in ‘one.’ Can be convenient, if you wish…

12-36 PERFORM … VARYING … AFTER Move 0 To Total Example Perform 700-Loop1 Varying Day-Sub From 1 By 1 Until Day-Sub > 7 After Hour-Sub From 1 By 1 Until Hour-Sub > 24 Compute Weekly-Average = Total / Loop1. Add Temp (Day-Sub, Hour-Sub) To Total. How many times is the 700 paragraph executed? What are the values of the subscripts upon termination?

12-37 PERFORM … VARYING … AFTER Sequence of values for subscripts is (1, 1), (1, 2) … (1, 24), (2, 1), (2, 2) … (2, 24) … (7, 1)... (7, 24) Day-Sub initialized to 1 and Hour-Sub varied from 1 to 24 Then Day-Sub incremented to 2 and Hour-Sub varied from 1 to 24 and so on

12-38 Chapter Summary OCCURS clause used to specify repeated occurrence of items with same format –Use in level entries –May use with elementary or group item –COBOL permits seven levels of OCCURS OCCURS defines –Array: area used for storing data or totals –Table: set of fields used in table look-up

12-39 Chapter Summary SEARCH statement used for table handling –Identifier used with SEARCH is data-name used on OCCURS level –AT END clause specifies action if table searched but condition not met –WHEN clause indicates what to do when condition met

12-40 Chapter Summary SEARCH statement –Index defined along with OCCURS and used by SEARCH –Use SET or PERFORM … VARYING to change value of index –SET index to 1 before using SEARCH

12-41 Chapter Summary SEARCH ALL statement –Used to perform binary search –Can test only an equal condition –Can use compound condition with ANDs –Only one WHEN clause can be used –Define index to use in searching table –Include ASCENDING or DESCENDING KEY clause in table definition

12-42 Chapter Summary Multiple-Level OCCURS –Used with array or table –Lowest-level OCCURS data-name or item subordinate to it used to access table entry –INDEXED BY must be included on all OCURRS levels if SEARCH used –Identifier used with SEARCH typically one on lowest OCCURS level –Only index on same level incremented

12-43 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.