Download presentation
Presentation is loading. Please wait.
1
More About COBOL Tables
SFASU M. M. Pickard, PhD Copyright, 1996 © Dale Carnegie & Associates, Inc.
2
Introduction Beyond the basics: indexes versus subscripts the SET verb
the SEARCH verb
3
Indexes versus Subscripts
Definition (declaration). Modification. Reference. Lookup
4
Indexes versus Subscripts ----------Definition--------------
Appearance in ‘INDEXED BY’ clause 01 A-TABLE. 05 A-MESS PIC X(20) OCCURS INDEXED BY A-INDEX. Definition as an integer data item 01 MISC. 05 XAMPL-SUB PIC 99.
5
Indexes versus Subscripts ----------modification------------
PERFORM…VARYING SET statement SEARCH statement PERFORM…VARYING arithmetic statements MOVE statement INITIALIZE statement
6
The SET statement Format 1:
SET index-name TO index-name or or identifier-1 identifier or integer-1
7
The SET statement Format 2:
SET index-name-1 UP BY identifier or or DOWN BY integer-1
8
SEARCH verb Allows search of an indexed table Two search methods
serial search binary search Table being searched MUST have a KEY clause and an INDEXED BY clause
9
SEARCH verb Serial search: SEARCH table-entry AT END executable-statement WHEN condition executable-statement(s) [END-SEARCH]
10
SEARCH verb Binary search: SEARCH ALL table-entry AT END executable-statement WHEN equality condition executable-statement(s) [AND equality condition executable-statement(s)] [END-SEARCH]
11
SEARCH verb Binary search SEARCH ALL (serial search doesn’t use ALL)
Requires use of KEY clause on table in addition to INDEXED BY clause Elements of table must be in the specified order
12
Advantages of Indexed Tables
Because indexes are stored in a format that is optimized for address calculation, table references for indexed tables are faster. An “automatic” binary search of an indexed table is possible.
13
Advantages of Subscripted Tables
Subscripts are somewhat easier for beginners to understand.
14
Advantages of Subscripted Tables
Debugging of code that uses subscripts is slightly easier. A subscript can be used with any table; an index can only be used with the table in which it is defined.
15
Summary - 1 Both subscripts and indexes can be used with tables having the INDEXED BY clause. Only subscripts may be used with non- indexed tables.
16
Summary - 2 Indexes have no PICTURE clause.
Index values are kept in an internal format that is ideal for address computation. Indexes can not be adjusted with ordinary mathematical operations.
17
Summary - 3 Indexes are much faster Subscripts are slightly easier
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.