sign in
 
   
 
 
 
   
  COBOL TUTORIAL FOR BCA STUDENTS OF M G UNIVERSITY  
  UNIT 4: PROCEDURE DIVISION . . .  
   
  TABLE HANDLING  
   
 

A group of data consisting of similar items is called a table. A table consists of homogeneous elements. The elements of a table must be ordered in a way such that there is a first element, a second element, a third element and so on. The kind of table described above is known as one-dimensional table. It is also possible to have higher dimensional table where an element in turn may be another table.

 
   
  OCCURS CLAUSE AND SUBSCRIPTING  
   
 


OCCURS clause is used to define tables in WORKING-STORAGE SECTION. With an OCCURS clause, we specify the number of items being defined in the array and the PICTURE of each items.

An OCCURS clause is defined in the DATA DIVISION to indicate the repeated occurrence of items in an array that have the same format and a subscript is used in the PROCEDURE DIVISION to indicate which specific item within the array we wish to access
.

The format of OCCURS clause is as follows:

OCCURS integer TIMES


The following rules apply for the OCCURS clause and subscripts.

 
 
The integer in the OCCURS clause must be a positive integer.
The OCCURS clause can be specified for an elementary item or for a group item. The clause causes contiguous area holding the elements to be set up internally. The clause causes contiguous area holding the elements to be setup internally. The number elements is equal to the integer in the OCCURS clause. The OCCURS clause cannot be specified for an item whose level number is 01, 66, 77 or 88.
When a data name is described with the OCCURS clause, the data name as well as any of its subordinate items can not be referred to in the PROCEDURE DIVISION without a subscript. Subscript can be either a positive integer or a data name denoting a positive integral value or it can be an arithmetic expression.
The highest value that a subscript can take is the one specified by the integer in the OCCURS clause. The lowest value of a subscript is implicitly assumed to be 1.
The subscript must be enclosed within a pair of parentheses.
A data name used as a subscript cannot be another subscripted data name. However, it can be qualified.
eg:-
TAX-RATE (A OF NEW-GROUP) is valid.
TAX-RATE (A (K)) is invalid.
If a data name with OCCURS cluase requires any qualification, the subscript should be written after the last qualification.
eg:-
TAX-RATE OF DIRECT-TAX-RATE (I) is valid.
TAX-RATE (I) OF DIRECT-TAX-RATE is invalid.
When an entry is defined with OCCURS clause, the VALUE clause cannot be specified for the associated data name or any data name subordinate to it.
The REDEFINES clause cannot appear in the same data description entry which contains an OCCURS clause. However, REDEFINES clause can appear for a group item whose subordinate items are defined with the OCCURS clause.
The OCCURS clause can appear in the data description entry in any position after the level number and the data name.
 
Eg:-
 
01 NAME-TABLE.
  02 NAME PIC X(30) OCCURS 10 TIMES.
 
01 STUDENT-TABLE.
  02 STUDENT OCCURS 100 TIMES.
    03 ROLL-NO PIC 999.
    03 ST-NAME PIC X(30).
 
01 MATRIX-TABLE.
  02 MATRIXA OCCURS 10 TIMES.
    03 A OCCURS 10 TIMES PIC 999.