Chapter 12 Array Processing and Table Handling. Defining Series of Input Fields Coding record with 24 independent hourly fields is cumbersome 01Temp-Rec.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

DT266/2 Information Systems COBOL Revision. Chapters 1 & 2 Hutty & Spence Divisions of a Cobol Program Identification Division Program-ID. Environment.
Tables1 TABLES (chp. 12) group of storage locations (i.e. elements) with the same name accessed by name and subscript ex. var-name (sub) similar to arrays.
Chapter 10 Linking and Loading. Separate assembly creates “.mob” files.
12-1 Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout John.
Chapter 7 Introduction to Procedures. So far, all programs written in such way that all subtasks are integrated in one single large program. There is.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Eight Sub and Function Procedures.
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)
Arrays. Topics Tables of Data Arrays – Single Dimensional Parsing a String into Multiple Tokens Arrays - Multi-dimensional.
An Introduction to Programming with C++ Fifth Edition
Understanding Arrays and Pointers Object-Oriented Programming Using C++ Second Edition 3.
C++ for Engineers and Scientists Third Edition
An Object-Oriented Approach to Programming Logic and Design Chapter 7 Arrays.
Chapter 11 Structure. 2 Objectives You should be able to describe: Structures Arrays of Structures Structures as Function Arguments Dynamic Structure.
Part II: Addressing Modes
Xin  Syntax ◦ SELECT field1 AS title1, field2 AS title2,... ◦ FROM table1, table2 ◦ WHERE conditions  Make a query that returns all records.
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
4-1 Coding Complete COBOL Programs: The PROCEDURE DIVISION Chapter 4.
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
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)
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)
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.
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 
Array Processing Simple Program Design Third Edition A Step-by-Step Approach 7.
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.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 9 Arrays.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
BUILDING JAVA PROGRAMS CHAPTER 7 Arrays. Exam #2: Chapters 1-6 Thursday Dec. 4th.
7-1 Chapter 7.  Basic Arithmetic Verbs  Options Available with Arithmetic Verbs  COMPUTE Statement  Signed Numbers in Arithmetic Operations  Intrinsic.
Chapter 12 (part 2) Table Handling and Search Techniques.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 5 Arrays.
Indexed and Relative File Processing
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
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.
Oracle 11g: SQL Chapter 4 Constraints.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
Computer Programming TCP1224 Chapter 11 Arrays. Objectives Using Arrays Declare and initialize a one-dimensional array Manipulate a one-dimensional array.
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)
1 Review for test 2 Chapters 7, 8, 9, 11, What is wrong with the following paragraphs? PARA-A. PARA-B. ADD A TO B MOVE 0 TO X PERFROM PARA-A PERFORM.
13-1 Sequential File Processing Chapter Chapter Contents Overview of Sequential File Processing Sequential File Updating - Creating a New Master.
13- 1 Chapter 13.  Overview of Sequential File Processing  Sequential File Updating - Creating a New Master File  Validity Checking in Update Procedures.
Copyright © 2002 W. A. Tucker1 Chapter 9 Lecture Notes Bill Tucker Austin Community College COSC 1315.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
Chapter 8 Arrays. A First Book of ANSI C, Fourth Edition2 Introduction Atomic variable: variable whose value cannot be further subdivided into a built-in.
An Introduction to Programming with C++ Sixth Edition Chapter 13 Strings.
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.
Higher Computing Science 2016 Prelim Revision. Topics to revise Computational Constructs parameter passing (value and reference, formal and actual) sub-programs/routines,
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)
Arrays Chapter 7. MIS Object Oriented Systems Arrays UTD, SOM 2 Objectives Nature and purpose of an array Using arrays in Java programs Methods.
Chapter 4 PROCEDURE DIVISION. Paragraphs PROCEDURE DIVISION divided into paragraphs Each is independent module or routine Made up of series of instructions.
Array Applications. Objectives Design an algorithm to load values into a table. Design an algorithm that searches a table using a sequential search. Design.
CHAPTER 6 ARRAYS IN C 1 st semester King Saud University College of Applied studies and Community Service Csc 1101 F. Alakeel.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Data Structures & Algorithms CHAPTER 2 Arrays Ms. Manal Al-Asmari.
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)
More About COBOL Tables
Screen I/O ACCEPT DISPLAY Relevant to the Fujitsu Compiler.
The Selection Structure
Cohesion and Coupling Chapter 5, Pfleeger 01/01/10.
Chapter 3 The DATA DIVISION.
Main Memory Background Swapping Contiguous Allocation Paging
Chapter 14 Sorting and Merging.
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
CHAPTER 17 The Report Writer Module
Presentation transcript:

Chapter 12 Array Processing and Table Handling

Defining Series of Input Fields Coding record with 24 independent hourly fields is cumbersome 01Temp-Rec. 05One-AMPic S9(3). 05Two-AMPic S9(3).... … … 05MidnightPic S9(3). 24 entries

Defining Series of Input Fields To obtain average temperature requires summing 24 fields Compute Avg-Temp = (One-AM + Two-AM + … + Midnight) / 24

OCCURS Clause Defining series of input or output fields, each with same format Defining series of totals to which amounts added Defining a table to be accessed using contents of input field to 'look up' required data

Defining Fields with OCCURS Since all 24 fields have same PICTURE –Can define entire 72-position area as array –Array divided into 24 three-position fields, called elements 01 Temp-Rec. 05Temperature Occurs 24 Times Pic S9(3).

Accessing Elements in Array Identifier Temperature is array name Use array name along with a subscript to access fields or elements within array Subscript indicates which of the 24 elements to access StatementOutput Display Temperature (2) 2 AM value Display Temperature (23) 11 PM value

Subscripts Using a data-name as a subscript enables its contents to be varied Each time the value of a data-name changes, Temperature (Sub) refers to a different element in the array Then a single routine can be used to process all elements in array

Valid Subscripts Valid values are 1 to number of elements in array For array Temperature valid subscripts are 1 to 24 Invalid use of subscripts –Display Temperature (0) –Display Temperature (25) –Display Temperature(8) –Display Temperature ( 2 )

Tables Table is list of stored fields Stored same way as array but used for different purpose Used with table look-ups, a procedure to find specific entry in a table E.g., A record with two fields, zip code and sales taxes. Read-in records, storing each zip code-tax rate combination in a table.

Table Look-Up Table entries in WORKING-STORAGE Table Argument Table Function Zip Code Sales Tax Rate Input Record ^ ^ 075 Zip Code ^ 065 (search ^ 080 argument) ^ 070 …... Rate for Zip of 12344

Table Look-up with PERFORM Move 0 To WS-Sales-Tax Perform Varying X1 From 1 By 1 Until X1 > 1000 If Zip-In = WS-ZipCode (X1) Compute WS-Sales-Tax Rounded = WS-Tax-Rate (X1) * Unit-Price-In * Qty-In End-If End-Perform

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 Format

SEARCH Statement Example Set X1 To 1 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

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. Compiler automatically supplies appropriate PICTURE clause for index X1 defined as index

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)

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

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