COBOL Tables
COBOL Tables
COBOL TABLES
COBOL TABLES
USE of TABLES
Name(10) is Valid
Class(5) is Valid
Hours(15) is Valid
Business-Table(2) is not Valid!
Student-Data(30) is valid
http://www-personal.k-state.edu/~mchaney/mn670/tables.htm 1/5
3/24/2018 COBOL Tables
Name(10) is Valid
Class(5) is Valid
Hours(15) is Valid
Business-Table(2) is not Valid!
Perform Varying
Example
PERFORM PARA-1 VARYING INDX FROM 1 BY 1
UNTIL INDX > 10.
STEPS:
1. INDX is initialized to 1.
2. If condition (INDX > 10) is NOT met, PARA-1 is executed.
3. After PARA-1 is executed, 1 is added to INDX.
4. Return to step 2 and check the condition.
Loading Tables
01 Business-Table.
05 Student-Data OCCURS 50 TIMES.
10 Name PIC X(20).
10 Class PIC X.
10 Hours PIC 9(3).
01 Num-In PIC 99 VALUE ZERO.
02 ERROR-FLAG PIC X(3) VALUE “NO”.
.
.
Init-Table.
MOVE ZEROS TO Hours(Num-In).
MOVE SPACES TO Name(Num-In)
Class(Num-In).
100-Load-Table.
ADD 1 to Num-In.
IF Num-In > 50 MOVE “YES” TO Error-Flag
ELSE MOVE Name-In to Name(Num-In)
MOVE Class-In to Class(Num-In)
MOVE Hours-In to Hours(Num-In)
READ Student-File INTO Student-Detail
AT END MOVE “YES” to EOF-FLAG.
REDEFINES
General Format:
The level-number on the REDEFINES entry must be the same as the level-number on dataname-2, which is being
redefined.
FreshmanbSophomoreJuniorbbbSeniorbbb
http://www-personal.k-state.edu/~mchaney/mn670/tables.htm 3/5
3/24/2018 COBOL Tables
CLASS(3) = Junior
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:
Example:
01 Class-Names.
05 Filler Pic X(9) Value “Freshman”.
05 Filler Pic X(9) Value “Sophomore”.
05 Filler Pic X(9) Value “Junior”.
05 Filler Pic X(9) Value “Senior”.
When an index-name is specified, the compiler automatically provides for the index. It is not
necessary to define a separate data item in Working-Storage as is done for a variable subscript.
Indexes are displacement values with subscript represent occurrence numbers
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
http://www-personal.k-state.edu/~mchaney/mn670/tables.htm 4/5
3/24/2018 COBOL Tables
SET Class-Index to 1.
SET Class-Index to Class-In.
To INCREMENT OR DECREMENT
SET Class-Index UP BY 1.
SET Class-Index Down By 2.
http://www-personal.k-state.edu/~mchaney/mn670/tables.htm 5/5