Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tables In COBOL An Introduction

Similar presentations


Presentation on theme: "Tables In COBOL An Introduction"— Presentation transcript:

1 Tables In COBOL An Introduction
M.M. Pickard, Ph. D. Computer Science Stephen F. Austin State University Copyright, 1996 © Dale Carnegie & Associates, Inc.

2 Introduction Definition Initialization Reference

3 Definition: What is a table?
Remember arrays? “Table” is the COBOL term for an array. Can you give a bullet-proof definition of an array?

4 Definition: What is a table?
How about this? “An array is a named block of memory containing data elements of the same size and type arranged in contiguous memory locations, such that each element can be accessed by its position within the block.”

5 Definition - COBOL Tables
What is essential in order to have a COBOL table?

6 Definition - COBOL Tables
What is essential in order to have a COBOL table? Answer: The OCCURS clause! This tells how many elements are in the table.

7 Initialization - COBOL Tables
Two kinds of tables: “Compile-time” or “hard-coded” tables. “Run-time” tables. But a table is a table is a table. . .

8 How about an example? First, a “compile-time” table

9 Initialization - COBOL Tables
INITIALIZE statement Allows initialization of tables and other data items according to the class of data. MOVE of data to the table elements

10 Reference - COBOL Tables
One can reference the block of memory displaced by an entire table, e.g., MOVE SPACES TO CLASS-VALUES. One can reference the individual table elements using subscripts using indexes

11 Reference - COBOL Tables
Reference the individual table elements using subscripts: use the table element name with an occurrence number (subscript) enclosed in parentheses, e.g., DISPLAY CLASS-DESCRIPTION (5) or DISPLAY CLASS-DESCRIPTION (CLASS-NR)

12 Reference - COBOL Tables
In an example like the following DISPLAY CLASS-DESCRIPTION (CLASS-NR) the data-name serving as the subscript must be defined as an integer CLASS-NR PIC 9.

13 Reference - COBOL Tables
A table element may be referenced by an index only if it appeared in the original table definition within the DATA DIVISION. Example: 01 CLASS-TABLE CLASS-DESC PIC X(9) OCCURS INDEXED BY CLASS-IDX.

14 Reference - COBOL Tables
01 CLASS-TABLE CLASS-DESC PIC X(9) OCCURS INDEXED BY CLASS-IDX. Then a statement like DISPLAY CLASS-DESC (CLASS-IDX) is possible.

15 Reference - COBOL Tables
01 CLASS-TABLE CLASS-DESC PIC X(9) OCCURS INDEXED BY CLASS-IDX. Note that a table index has no PICTURE, but a subscript must have one.

16 Introduction to COBOL Tables Summary
Analogous to arrays in other languages Can be initialized at compile time. Can have values inserted at run time. Elements can be accessed using subscripts or indexes.


Download ppt "Tables In COBOL An Introduction"

Similar presentations


Ads by Google