1 Chapter – 12 Table Lookups Table Codes –Expanded Values –Types of Codes Numeric Alphabetic Alphanumeric.

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

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 9: Searching, Sorting, and Algorithm Analysis
Chapter 15 Indexed Sequential Files. Disk File Organization File is collection of records Three major ways records stored or organized on disk - Sequential.
Processing with VSAM Files Please use speaker notes for additional information!
VSAM KSDS and COBOL Department of Computer Science Northern Illinois University August 2005 Some of the illustrations are from VSAM: Access Method Services.
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)
With Microsoft Office 2007 Intermediate© 2008 Pearson Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Office 2007 Intermediate.
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)
With Microsoft Access 2007 Volume 1© 2008 Pearson Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Access 2007 Volume 1 Chapter.
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)
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;
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.
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.
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
1 Chapter 4: Selection Structures. In this chapter, you will learn about: – Selection criteria – The if-else statement – Nested if statements – The switch.
BIS 1753 Introduction to Computer Programming 1. Computer Program A set of instructions that enables a computer to process data Also called software Two.
Chapter 7 Array processing. Objectives To introduce arrays and the uses of arrays To develop pseudocode algorithms for common operations on arrays To.
Array Processing.
1 Chapter 14 - Sorting System Concepts –Sort key Major Key (Primary) Minor Key (Secondary) –Sort sequence Ascending - Low to high Descending – High to.
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.
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.
Chapter 12 (part 2) Table Handling and Search Techniques.
Indexed and Relative File Processing
Chapter 6: Arrays: Lists and Tables
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.
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)
CPSC3111/CISM3111 COBOL Structured COBOL Programming Text: murach’s structured COBOL Authors: Murach, Prince, Menendez.
Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout.
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.
More Syntax in COBOL  Moving Data  Selection Statements  System Date  Indicators in Display files.
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 5: Hashing Part I - Hash Tables. Hashing  What is Hashing?  Direct Access Tables  Hash Tables 2.
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 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 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.
COSC 2007 Data Structures II Chapter 13 Advanced Implementation of Tables IV.
13-1 Sequential File Processing Chapter Chapter Contents Overview of Sequential File Processing Sequential File Updating - Creating a New Master.
One & Two dimensional Tables Cont.. Table of Major Codes 02ART HISTORY 04BIOLOGY 19CHEMESTRY 21CIVIL ENGINEERING 24COMP INF SYS 32ECONOMICS 39FINANCE.
1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.
Lecture 21 ENVIRONMENT DIVISION  defines files external to the program and devices.  contains two sections: 1.CONFIGURATION SECTION.  identifies computers.
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.
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)
Chapter 4 PROCEDURE DIVISION. Paragraphs PROCEDURE DIVISION divided into paragraphs Each is independent module or routine Made up of series of instructions.
Random update Please use speaker notes for additional information!
General Introduction Algorithms. Let’s write a program  A program is a collection of statements written in a language the computer understands.  A computer.
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.
Chapter 3 The DATA DIVISION.
Chapter 14 Sorting and Merging.
CHAPTER 17 The Report Writer Module
Searching and Sorting Arrays
Any Questions?.
Presentation transcript:

1 Chapter – 12 Table Lookups Table Codes –Expanded Values –Types of Codes Numeric Alphabetic Alphanumeric

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

3 TABLE 12.1 Types of Table Codes SYMBOLSNUMBER OF POSSIBLE VALUES CODE TYPEUSED 1 POSITION2 POSITIONS n POSITIONS Numeric = = n AlphabeticA - Z26 1 = = n AlphanumericA - Z, = = 1, n Characteristics of Codes Precise - each code is unique allowing only one alternative Expandable - allows for future growth Mnemonic - easy to remember meaning of the code

4 Characteristics of codes –Percise –Mnemonic –Expandable Sequential table lookup –N/2 attempts –Sequential check of table entries –Organization by frequency of occurrence 80/20 rule

5 Figure 12.2Sequential 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

6 Binary table lookup –Methodology –Speed advantages Positional Organization –Positional table Wasted space Address is the code Consecutive numeric codes Direct access to table elements

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

8 TABLE 12.2 Required Number of Comparisons for Binary Search NUMBER OF ELEMENTSMAXIMUM NUMBER OF COMPARISONS (less than 2 4 ) (less than 2 5 ) (less than 2 6 ) (less than 2 7 ) (less than 2 8 ) (less than 2 9 ) (less than 2 10 ) (less than 2 11 ) (less than 2 12 )

9 Figure 12.4Positional Organization & Direct Lookup 02ART HISTORY 04BIOLOGY 19CHEMESTRY 21CIVIL ENGINEERING 24COMP INF SYS 32ECONOMICS 39FINANCE 43MANAGEMENT 39 1st try FINANCE Match

10 Initializing a table –Hard coding VALUE, REDEFINES, OCCURS –reading from a file Dynamically defining the size of the record –Table Lookups Perform Varying Search Statement

11 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. 10 MAJOR-CODEPIC 9(2). 10 EXPANDED-MAJORPIC X(12). Figure 12.5Initialization via Hard Coding

12 Figure 12.6Table 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)

13 Figure 12.7Input-Loaded Table FD MAJOR-CODE-FILE. RECORD CONTAINS 14 CHARACTERS DATA RECORD IS MAJOR-CODE-RECORD. 01 MAJOR-CODE-RECORD. 05 INCOMING-FILE-CODEPIC 9(2). 05 INCOMING-FILE-NAMEPIC X(12).... WORKING-STORAGE SECTION. 01 MAJOR-TABLE. 05 MAJORS OCCURS 1 TO 10 TIMES DEPENDING ON NUMBER-OF-MAJORS INDEXED BY MAJOR-INDEX. 10 MAJOR-CODEPIC 9(2). 10 EXPANDED-MAJORPIC X(12). 01 NUMBER-OF-MAJORSPIC 99 VALUE ZERO. 01 END-OF-MAJOR-FILE-SWPIC XVALUE SPACES. 88 END-OF-MAJOR-FILEVALUE ‘Y’. (a) Data Division entries

14 Figure 12.7Input-Loaded Table PROCEDURE DIVISION. OPEN INPUT MAJOR-CODE-FILE. PERFORM VARYING MAJOR-INDEX FROM 1 BY 1 UNTIL MAJOR-INDEX > 10 OR END-OF-MAJOR-FILE READ MAJOR-CODE-FILE AT END MOVE ‘Y’ TO END-OF-MAJOR-FILE NOT AT END ADD 1 TO NUMBER-OF-MAJORS MOVE INCOMING-FILE-CODE TO MAJOR-CODE (MAJOR-INDEX) MOVE INCOMING-FILE-NAME TO EXPANDED-MAJOR (MAJOR-INDEX) END-READ END-PERFORM. IF MAJOR-INDEX > 10 DISPLAY ‘MAJOR TABLE TOO SMALL’ END-IF. CLOSE MAJOR-CODE-FILE PERFORM 0100-PREPARE-STUDENT-TRANSCRIPT.... (b) In-Line Perform

15 How many unique codes can be developed from a 4 position numeric code, alphabetic code, 4 position alphanumeric code.

16 What’s wrong with this code? 01 MONTH-TABLE. 05 MONTH OCCURS 12 TIMES PIC X(4). 05 MONTH-VALUES REDEFINES MONTH PIC X(36) VALUE ‘JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC’.

17 Table Lookups –Using the PERFORM.. VARYING statement –Using the SEARCH statement Must use indexes –Using the SEARCH ALL statement Uses index plus codes must be in order Uses a binary search Does not use a set command –Direct lookup Positional table –Range-step tables No one-to-one correspondence

18 19CHEMISTRY Figure 12.8Input-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)

19 Figure 12.9Sequential 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(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. 10 MAJOR-CODEPIC 9(2). 10 EXPANDED-MAJORPIC X(12).

20 Figure 12.9Sequential 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.

21 Figure 12.10SEARCH Statement (Sequential Lookup) 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 INDEXED BY MAJOR-INDEX. 10 MAJOR-CODEPIC 9(2). 10 EXPANDED-MAJORPIC X(12).... INDEXED BY clause required in table definition

22 Figure 12.10SEARCH 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

23 Figure 12.11SEARCH 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)....

24 Figure 12.11SEARCH 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.

25 Figure Direct Access to Table Entries 01 MAJOR-VALUE. 05 FILLERPIC X(12) VALUE ‘UNKNOWN’. 05 FILLERPIC X(12) VALUE ‘ACCOUNTING’. 05 FILLERPIC X(12) VALUE ‘UNKNOWN’. 05 FILLERPIC X(12) VALUE ‘BIOLOGY’ FILLERPIC X(12) VALUE ‘STATISTICS’. 01 MAJOR-TABLE REDEFINES MAJOR-VALUE. 05 MAJORS OCCURS 54 TIMES PIC X(12).... PROCEDURE DIVISION.... IF ST-MAJOR-CODE > 0 AND ST-MAJOR-CODE < 55 MOVE MAJORS (ST-MAJOR-CODE) TO HDG-MAJOR ELSE MOVE ‘UNKNOWN’ TO HDG-MAJOR END-IF. Positional organization results in wasted space Check to ensure valid code

26 Figure Range-step Table Grade PointScholarship Average Percentage (a) Scholarship Table

27 Figure Range-step Table 01 SCHOLARSHIP-TABLE. 05 GPA-SCHOLARSHIP-PERCENTAGES. 10 FILLERPIC X(6) VALUE ‘375100’. 10 FILLERPIC X(6) VALUE ‘350075’. 10 FILLERPIC X(6) VALUE ‘325050’. 10 FILLERPIC X(6) VALUE ‘300033’. 10 FILLERPIC X(6) VALUE ‘275025’. 10 FILLERPIC X(6) VALUE ‘250015’. 05 GPA-TABLE REDEFINES GPA-SCHOLARSHIP-PERCENTAGES OCCURS 6 TIMES INDEXED BY GPA-INDEX. 10 GPA-MINIMUM PIC 9V SCHOLARSHIP-PCT PIC SET GPA-INDEX TO 1. SEARCH GPA-TABLE AT END MOVE ZERO TO SCHOLARSHIP-AWARD WHEN STUDENT-GPA >= GPA-MINIMUM (GPA-INDEX) MOVE SCHOLARSHIP-PCT (GPA-INDEX) TO SCHOLARSHIP-AWARD END-SEARCH. (b) COBOL Implementation

28 Summary Codes & types VALUE, OCCURS, & REDEFINES used to define and initialize a table. Table lookups – sequential, binary, direct access Range-step table Tables are initialized by hard-coding or dynamically loading at execution time SEARCH statement, requires an index SEARCH ALL statement, index & in order