Professional Documents
Culture Documents
USE of TABLES
General Format
PIC X(20).
PIC X.
PIC 9(3).
Name(10) is Valid
Class(5) is Valid
Hours(15) is Valid
Business-Table(2) is not Valid!
Perform Varying
General Format:
Example
PERFORM PARA-1 VARYING INDX FROM 1 BY 1
UNTIL INDX > 10.
STEPS:
1.
INDX is initialized to 1.
2.
3.
4.
Loading Tables
Init-Table.
MOVE ZEROS TO Hours(Num-In).
MOVE SPACES TO Name(Num-In)
Class(Num-In).
3. Load data into the table:
MOVE ZERO TO Num-In.
READ Student-File INTO Student-Detail
REDEFINES
General Format:
Level-Number
The level-number on the REDEFINES entry must be the same as the level-number on
dataname-2, which is being redefined.
Pic X(9)
Pic X(9)
Pic X(9)
Pic X(9)
Value Freshman.
Value Sophomore.
Value Junior.
Value Senior.
Redefines Rules
1. Level-Numbers on the REDEFINES entry must be the same as the level-number
on the dataname that is being redefined.
2. A dataname with a lower level-number may NOT occur between the
REDEFINES entry and the dataname being redefined. However, datanames with
higher level-numbers are acceptable here.
3. The length of the item being REDEFINED must be exactly the same length as the
item it is redefining.
Indexed by Clause
General Format:
OCCURS integer TIMES INDEXED BY index-name
Example:
01 Class-Names.
05 Filler
05 Filler
05 Filler
05 Filler
Pic X(9)
Pic X(9)
Pic X(9)
Pic X(9)
Value Freshman.
Value Sophomore.
Value Junior.
Value Senior.
Table Value
Occurrence (subscript)
Displacement (Index)
Freshman
Sophomore
Junior
18
Senior
27
Since Index values are displacement values, an index cannot be initialized with a
MOVE statement like a subscript can. Similiarly, we cannot ADD to or
SUBTRACT from an index. Instead, the SET verb must be used.
SET VERB
Used to initialize or change the value of a Table index
To Initialize a table index:
SET index-name TO integer (or numeric variable).
Examples (in procedure division)
SET Class-Index to 1.
SET Class-Index to Class-In.
To INCREMENT OR DECREMENT
SET index-name UP BY (or DOWN BY)
Integer (or numeric variable).
Examples (In Procedure Division)
SET Class-Index UP BY 1.
SET Class-Index Down By 2.
Reference:
www.tutorialspoint.com/cobol/cobol_table_processing.