One & Two dimensional Tables Cont.. Table of Major Codes 02ART HISTORY 04BIOLOGY 19CHEMESTRY 21CIVIL ENGINEERING 24COMP INF SYS 32ECONOMICS 39FINANCE.

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

Loops continued and coding efficiently Genome 559: Introduction to Statistical and Computational Genomics Prof. James H. Thomas.
12-1 Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout John.
Chapter 12 Array Processing and Table Handling. Defining Series of Input Fields Coding record with 24 independent hourly fields is cumbersome 01Temp-Rec.
Chapter 11 Indexing and Hashing (2) Yonsei University 2 nd Semester, 2013 Sanghyun Park.
BY: JOSHUA THOMAS IGNATIUS TOWERS COBOL. Overview What is COBOL History Design Implementations What did it do Program structure Data types Syntax Sample.
Chapter 15 Indexed Sequential Files. Disk File Organization File is collection of records Three major ways records stored or organized on disk - Sequential.
C++ for Engineers and Scientists Third Edition
Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities.
VSAM KSDS and COBOL Department of Computer Science Northern Illinois University August 2005 Some of the illustrations are from VSAM: Access Method Services.
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
Processing Arrays Lesson 8 McManusCOP Overview One-Dimensional Arrays –Entering Data into an Array –Printing an Array –Accumulating the elements.
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.
Chapter To familiarize you with  Why COBOL is a popular business-oriented language.  Programming practices and techniques  History of COBOL.
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.
History COBOL (Common Business Oriented Language) was one of the earliest high-level programming languages. COBOL was first proposed in 1959 by the Conference.
Chapter 5 Using Data and COBOL Operators. Initializing Variables When you define a variable in WORKING- STORAGE, you also can assign it an initial value.
Programming Examples to Accompany Structure Topic Please use speaker notes for additional information!
The Procedure Abstraction, Part VI: Inheritance in OOLs Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled.
Array Processing.
Array - adding to array at run time Please see speaker notes for additional information!
Chapter 12 (part 2) Table Handling and Search Techniques.
© 1999, by Que Education and Training, Chapter 8, pages of Introduction to Computer Programming with Visual Basic 6: A Problem-Solving Approach.
Indexed and Relative File Processing
Chapter 6: Arrays: Lists and Tables
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.
1 The Procedure Division Chapter 4. 2 Main Two Sections File Section –Used to define files and record formats –Field names within records Working Storage.
Searching Tables.. Creating Pre-filled Tables A B C D E F G H I J K L ABCDEFGHIJKLM NOPQRSTUVWXYZ 01 LetterTable. 02 TableValues. 03 FILLER PIC X(13)
Statement Syntax1 THE SELECT STATEMENT Purpose: designates a file and points to its physical location Syntax Definition : SELECT file-name-1 ASSIGN TO.
CSC 211 Data Structures Lecture 13
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)
Figure 9.9Duplicate Data Names 01 STUDENT-RECORD. 05 STUDENT-NAMEPIC X(20). 05 SOCIAL-SECURITY-NUMPIC 9(9). 05 STUDENT-ADDRESS. 10 STREETPIC X(15). 10.
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 
Any Questions!. Test Coming Up! Agenda Printing with Externally Described Printer Files Arrays.
1.
1 Chapter 5 – The Procedure Division File handling statements –OPEN statement Initiates processing for a file Input Output Each file opened must have been.
1 Chapter 13 - Mutlilevel Tables System Concepts –User View of tables one dimension view two dimension view three dimension view.
1 Chapter 9. To familiarize you with  Simple PERFORM  How PERFORM statements are used for iteration  Options available with PERFORM 2.
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.
Processing Arrays Lesson 9 McManusCOP Overview One-Dimensional Arrays –Entering Data into an Array –Printing an Array –Accumulating the elements.
This is It! It’s been a pleasure! Final Exam – format True / false 5 Multiple choice 5 Short answers10 Data manipulation10 SQL 3 Array’s12 File processing25.
Course Code #IDCGRF001-A 5.1: Searching and sorting concepts Programming Techniques.
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.
CHAPTER EIGHT ARRAYS © Prepared By: Razif Razali1.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
Searching Topics Sequential Search Binary Search.
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)
Chapter 4 PROCEDURE DIVISION. Paragraphs PROCEDURE DIVISION divided into paragraphs Each is independent module or routine Made up of series of instructions.
The PERFORM. The PERFORM Verb  Iteration is an important programming construct. We use iteration when we need to repeat the same instructions over and.
Random update Please use speaker notes for additional information!
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
Array Applications. Objectives Design an algorithm to load values into a table. Design an algorithm that searches a table using a sequential search. Design.
General Introduction Algorithms. Let’s write a program  A program is a collection of statements written in a language the computer understands.  A computer.
Arrays Department of Computer Science. C provides a derived data type known as ARRAYS that is used when large amounts of data has to be processed. “ an.
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)
THE SORT STATEMENT for files (chp. 14)
Tables and PERFORM..VARYING
More About COBOL Tables
Screen I/O ACCEPT DISPLAY Relevant to the Fujitsu Compiler.
Chapter 14 Sorting and Merging.
Iteration: Beyond the Basic PERFORM
Presentation transcript:

One & Two dimensional Tables Cont.

Table of Major Codes 02ART HISTORY 04BIOLOGY 19CHEMESTRY 21CIVIL ENGINEERING 24COMP INF SYS 32ECONOMICS 39FINANCE 43MANAGEMENT 49MARKETING 54STATISTICS

Sequential Table Lookup 02ART HISTORY 04BIOLOGY 19CHEMESTRY 21CIVIL ENGINEERING 24COMP INF SYS 32ECONOMICS 39FINANCE 43MANAGEMENT 49MARKETING 53STATISTICS 39 1st try 2nd try 3rd try 4th try 5th try 6th try 7th try FINANCE Match

Binary Lookup 02ART HISTORY 04BIOLOGY 19CHEMESTRY 21CIVIL ENGINEERING 24COMP INF SYS 32ECONOMICS 39FINANCE 43MANAGEMENT 49MARKETING 53STATISTICS 39 1st try FINANCE Match 2nd try 3rd try

01 MAJOR-VALUE. 05 FILLERPIC X(14)VALUE ‘02ART HISTORY’. 05 FILLERPIC X(14)VALUE ‘04BIOLOGY’. 05 FILLERPIC X(14)VALUE ‘19CHEMISTRY’. 05 FILLERPIC X(14)VALUE ‘21CIVIL ENG’. 05 FILLERPIC X(14)VALUE ‘24COMP INF SYS’. 05 FILLERPIC X(14)VALUE ‘32ECONOMICS’. 05 FILLERPIC X(14)VALUE ‘39FINANCE’. 05 FILLERPIC X(14)VALUE ‘43MANAGEMENT’. 05 FILLERPIC X(14)VALUE ‘40MARKETING’. 05 FILLERPIC X(14) VALUE ‘54STATISTICS’. 01 MAJOR-TABLE REDEFINES MAJOR-VALUE. 05 MAJORS OCCURS 10 TIMES. 10 MAJOR-CODEPIC 9(2). 10 EXPANDED-MAJORPIC X(12). Initialization via Hard Coding

Table Initialization (Storage Schematic ) 02ARTHISTORY 4BIOLOGY 054STATISTI MAJOR-VALUE MAJOR-TABLE... CD (1) EXP-MAJOR (1) CD (2) EXP-MAJOR (2)EXP-MAJOR (10) CD (10)

19CHEMISTRY Input-Loaded Tables 04BIOLOGY 02ART HISTORY 02 ART HISTORY04BIOLOGY19CHEMISTRY MAJOR-CODE (1) EXPANDED-MAJOR (1) MAJOR-CODE (2) EXPANDED-MAJOR (2) MAJOR-CODE (3) EXPANDED-MAJOR (3)

Loading from an input file zFD TAX-FILE. z01 TAX-RECORD. z 05 ZIPCODE-IN PIC 9(5). z 05 TAX-RATE-IN PIC V999 COMP-3. z WORKING-STORAGE SECTION. z zREAD TAX-FILE INTO TABLE-ENTRIES (SUB) z AT END z DISPLAY 'NOT ENOUGH TABLE RECORDS' z PERFORM 300-TERMINATION-RTN z STOP RUN zEND-READ. 01 SALES-TAX-TABLE. 05 TABLE-ENTRIES OCCURS 1000 TIMES. 10 T-ZIPCODE PIC 9(5). 10 T-TAX-RATE PIC V999 COMP-3.

Sequential Lookup with PERFORM VARYING WORKING-STORAGE SECTION. 01 TABLE-PROCESSING-ELEMENTS. 05 WS-MAJOR-SUBPIC S9(4)COMP. 05 WS-FOUND-MAJOR-SWITCHPIC X(3)VALUE ‘NO’. 05 WS-END-OF-TABLE-SWITCHPIC X(3)VALUE ‘NO’. 01 MAJOR-VALUE. 05 FILLERPIC X(14)VALUE ‘02ART HISTORY’. 05 FILLERPIC X(14)VALUE ‘04BIOLOGY’. 05 FILLERPIC X(14)VALUE ‘19CHEMISTRY’. 05 FILLERPIC X(14)VALUE ‘21CIVIL ENG’. 05 FILLERPIC X(14)VALUE ‘24COMP INF SYS’. 05 FILLERPIC X(14)VALUE ‘32ECONOMICS’. 05 FILLERPIC X(14)VALUE ‘39FINANCE’. 05 FILLERPIC X(14)VALUE ‘43MANAGEMENT’. 05 FILLERPIC X(14)VALUE ‘40MARKETING’. 05 FILLERPIC X(14) VALUE ‘54STATISTICS’. 01 MAJOR-TABLE REDEFINES MAJOR-VALUE. 05 MAJORS OCCURS 10 TIMES. 10 MAJOR-CODEPIC 9(2). 10 EXPANDED-MAJORPIC X(12).

Sequential Lookup with PERFORM VARYING PROCEDURE DIVISION PREPARE-STUDENT-REPORT. MOVE ‘NO’ TO WS-FOUND-SWITCH WS-END-OF-TABLE-SWITCH. PERFORM 1000-FIND-MAJOR VARYING WS-MAJOR-SUB FROM 1 BY 1 UNTIL WS-END-OF-TABLE-SWITCH = ‘YES’ OR WS-FOUND-MAJOR-SWITCH = ‘YES’ FIND-MAJOR. IF WS-MAJOR-SUB > 10 MOVE ‘YES’ TO WS-END-OF-TABLE-SWITCH MOVE ‘UNKNOWN’ TO HDG-MAJOR ELSE IF ST-MAJ0R-CODE = MAJOR-CODE (WS-MAJOR-SUB) MOVE ‘YES’ TO WS-FOUND-MAJOR-SWITCH MOVE EXP-MAJOR (WS-MAJOR-SUB) TO HDG-MAJOR END-IF END-IF.

SEARCH Statement (Sequential Lookup) 01 MAJOR-VALUE. 05 FILLERPIC X(14)VALUE ‘02ART HISTORY’. 05 FILLERPIC X(14)VALUE ‘04BIOLOGY’. 05 FILLERPIC X(14)VALUE ‘19CHEMISTRY’. 05 FILLERPIC X(14)VALUE ‘21CIVIL ENG’. 05 FILLERPIC X(14)VALUE ‘24COMP INF SYS’. 05 FILLERPIC X(14)VALUE ‘32ECONOMICS’. 05 FILLERPIC X(14)VALUE ‘39FINANCE’. 05 FILLERPIC X(14)VALUE ‘43MANAGEMENT’. 05 FILLERPIC X(14)VALUE ‘40MARKETING’. 05 FILLERPIC X(14) VALUE ‘54STATISTICS’. 01 MAJOR-TABLE REDEFINES MAJOR-VALUE. 05 MAJORS OCCURS 10 TIMES INDEXED BY MAJOR-INDEX. 10 MAJOR-CODEPIC 9(2). 10 EXPANDED-MAJORPIC X(12).... INDEXED BY clause required in table definition

SEARCH Statement (Sequential Lookup) PROCEDURE DIVISION.... SET MAJOR-INDEX TO 1. SEARCH MAJORS AT END MOVE ‘UNKNOWN’ TO HDG-MAJOR WHEN ST-MAJOR-CODE = MAJOR-CODE (MAJOR-INDEX) MOVE EXP-MAJOR (MAJOR-INDEX) TO HDG-MAJOR END-SEARCH. SET statement establishes starting point

Indexes versus Subscripts INDEXESSUBSCRIPTS Defined with a specific table; can be used Defined in Working-Storage; the samesubscript only with the table with which they are defined can be used with multiple tables although this is not recommended Initialized and incremented via the SET May not be used with SET statements (MOVE and can also be manipulated by PERFORM ADD are used instead); can also be manipulated in PERFORM statements Provide more efficient object code than USAGE IS COMPUTATIONAL makes subscripts subscripts more efficient, although indexes are still faster To change: Use PERFORM.. VARYINGor To Change: Use PERFORM … VARYING SET or MOVE, ADD, SUBTRACT 1

SEARCH ALL Statement (Binary Lookup) KEY required for binary search (ASCENDING or DESCENDING) 01 MAJOR-VALUE. 05 FILLERPIC X(10)VALUE ‘02ART HISTORY’. 05 FILLERPIC X(10)VALUE ‘04BIOLOGY’. 05 FILLERPIC X(10)VALUE ‘19CHEMISTRY’. 05 FILLERPIC X(10)VALUE ‘21CIVIL ENG’. 05 FILLERPIC X(10)VALUE ‘24COMP INF SYS’. 05 FILLERPIC X(10)VALUE ‘32ECONOMICS’. 05 FILLERPIC X(10)VALUE ‘39FINANCE’. 05 FILLERPIC X(10)VALUE ‘43MANAGEMENT’. 05 FILLERPIC X(10)VALUE ‘40MARKETING’. 05 FILLERPIC X(10) VALUE ‘54STATISTICS’. 01 MAJOR-TABLE REDEFINES MAJOR-VALUE. 05 MAJORS OCCURS 10 TIMES ASCENDING KEY IS MAJOR-CODE INDEXED BY MAJOR-INDEX. 10 MAJOR-CODEPIC 9(2). 10 EXPANDED-MAJORPIC X(12)....

SEARCH ALL Statement (Binary Lookup) PROCEDURE DIVISION.... SEARCH ALL MAJORS AT END MOVE ‘UNKNOWN’ TO HDG-MAJOR WHEN MAJOR-CODE (MAJOR-INDEX) = ST-MAJOR-CODE MOVE EXP-MAJOR (MAJOR-INDEX) TO HDG-MAJOR END-SEARCH.

zImplements a sequential lookup zRequires a SET statement prior to SEARCH to establish the initial position in the table zDoes not require codes in the table to be in any special sequence zContains an optional VARYING clause zMay specify more than one WHEN clause z Implements a binary lookup z Does not require an initial SET statement (calculates its own starting position z Requires the codes to be in ascending or descending sequence on the associated KEY clause in the table definition z Does not contain a VARYING clause z Restricted to a single WHEN clause SEARCH versus SEARCH ALL SEARCH SEARCH ALL

Multilevel Tables Responsibility ,000 27,000 28,000 30,000 32,000 34,000 36,000 39,000 42,000 46,000 Responsibility level = 4 (a) One-Level Table

Multilevel Tables Responsibility level = 1 Experience level = 4 Responsibility ,000 27,000 28,000 30,000 32,000 34,000 36,000 39,000 42,000 46,000 27,000 28,000 29,000 32,000 34,000 36,000 39,000 42,000 45,000 50,000 28,000 29,000 30,000 34,000 36,000 38,000 42,000 45,000 48,000 54,000 29,000 30,000 31,000 36,000 38,000 40,000 45,000 48,000 51,000 58,000 30,000 31,000 32,000 38,000 40,000 42,000 48,000 51,000 54,000 62, Experience Responsibility level = 4 Experience level = 1 (b) Two-Level Table

One-Level Table Responsibility ,000 27,000 28,000 30,000 32,000 34,000 36,000 39,000 42,000 46,000 Responsibility level = 4 (a) User’s View 01 SALARY-VALUES. 05 FILLERPIC X(5)VALUE ‘26000’. 05 FILLERPIC X(5)VALUE ‘27000’. 05 FILLERPIC X(5)VALUE ‘28000’. 05 FILLERPIC X(5)VALUE ‘30000’. 05 FILLERPIC X(5)VALUE ‘32000’. 05 FILLERPIC X(5)VALUE ‘34000’. 05 FILLERPIC X(5)VALUE ‘36000’. 05 FILLERPIC X(5)VALUE ‘39000’. 05 FILLERPIC X(5)VALUE ‘42000’. 05 FILLERPIC X(5)VALUE ‘46000’. 01 SALARY-TABLE REDEFINES SALARY-VALUES. 05 SALARY OCCURS 10 TIMESPIC 9(5). (b) Initialization via the REDEFINES and VALUES Clauses SALARY-TABLE SALARY (1) SALARY (2) SALARY (3) SALARY (4) SALARY (5) SALARY (6) SALARY (10) (c) Storage Schematic

Responsibility ,000 29,000 30,000 32,000 34,000 36,000 39,000 42,000 46,000 29,000 30,000 31,000 34,000 36,000 39,000 42,000 45,000 50,000 30,000 31,000 32,000 36,000 38,000 42,000 45,000 48,000 54,000 31,000 32,000 33,000 38,000 40,000 45,000 48,000 51,000 58,000 32,000 33,000 34,000 40,000 42,000 44, ,000 56,000 64, Experience Multilevel Tables (c) Three-Level Table Responsibility ,000 27,000 28,000 30,000 32,000 34,000 36,000 39,000 42,000 46,000 27,000 28,000 29,000 32,000 34,000 36,000 39,000 42,000 45,000 50,000 28,000 29,000 30,000 34,000 36,000 38,000 42,000 45,000 48,000 54,000 29,000 30,000 31,000 36,000 38,000 40,000 45,000 48,000 51,000 58,000 30,000 31,000 32,000 38,000 40,000 42,000 48,000 51,000 54,000 62, Experience Region 1 Region 2 Region = 1 Responsibility level = 1 Experience level = 4 Region = 2 Responsibility level = 4 Experience level = 1 Region = 1 Responsibility level = 4 Experience level = 1

SALARY-TABLE EXP (1) EXP (2) EXP (3) EXP (4) EXP (5) SALARY (1) SALARY (2) RESPONSIBILITY (1)RESPONSIBILITY (10)... SALARY-VALUES (c) Storage Schematic Two-Level Table 01 SALARY-VALUES. 05 FILLERPIC X(5)VALUE ‘ ’. 05 FILLERPIC X(5)VALUE ‘ ’. 05 FILLERPIC X(5)VALUE ‘ ’. 05 FILLERPIC X(5)VALUE ‘ ’. 05 FILLERPIC X(5)VALUE ‘ ’. 05 FILLERPIC X(5)VALUE ‘ ’. 05 FILLERPIC X(5)VALUE ‘ ’. 05 FILLERPIC X(5)VALUE ‘ ’. 05 FILLERPIC X(5)VALUE ‘ ’. 05 FILLERPIC X(5)VALUE ‘ ’. 01 SALARY-TABLE REDEFINES SALARY-VALUES. 05 RESPONSIBILITY OCCURS 10 TIMES. 10 EXPERIENCE OCCURS 5 TIMES. 15 SALARYPIC 9(5). (b) Initialization via the REDEFINES and VALUES Clauses

Two-Level Table Responsibility level = 1 Experience level = 4 Responsibility ,000 27,000 28,000 30,000 32,000 34,000 36,000 39,000 42,000 46,000 27,000 28,000 29,000 32,000 34,000 36,000 39,000 42,000 45,000 50,000 28,000 29,000 30,000 34,000 36,000 38,000 42,000 45,000 48,000 54,000 29,000 30,000 31,000 36,000 38,000 40,000 45,000 48,000 51,000 58,000 30,000 31,000 32,000 38,000 40,000 42,000 48,000 51,000 54,000 62, Experience Responsibility level = 4 Experience level = 1 (a) User’s View

PERFORM VARYING with Two Subscripts PERFORM INITIALIZE-SALARIES VARYING RESPONSIBILITY-SUB FROM 1 BY 1 UNTIL RESPONSIBILITY-SUB > 10 AFTER EXPERIENCE-SUB FROM 1 BY 1 UNTIL EXPERIENCE-SUB > INITIALIZE-SALARIES. MOVE ZERO TO SALARY (RESPONSIBILITY-SUB, EXPERIENCE-SUB). PERFORM VARYING RESPONSIBILITY-SUB FROM 1 BY 1 UNTIL RESPONSIBILITY-SUB > 10 AFTER EXPERIENCE-SUB FROM 1 BY 1 UNTIL EXPERIENCE-SUB > 5 MOVE ZERO TO SALARY (RESPONSIBILITY-SUB, EXPERIENCE-SUB) END-PERFORM (a) Performing a Paragraph (b) In-Line Perform

2-level Table continued (c) Variation of Subscripts Responsibility Subscript Experience Subscript RESPONSIBILITY-SUB is set to 1 while EXPERIENCE-SUB varies from 1 to 5 RESPONSIBILITY-SUB is set to 2 while EXPERIENCE-SUB varies from 1 to 5 RESPONSIBILITY-SUB reaches 10 and EXPERIENCE-SUB varies from 1 to 5