A group of data consisting of similar items are called a table.
OCCURS CLAUSE AND SUBSCRIPTING:
Let us consider the following example. Suppose there are five different direct tax rates which are to be stored in the form of a table named DIRECT-TAX-RATE. In order to handle this table in a COBOL program, we must know how to describe the table in the DATA DIVISION, how to put the tax rates into the table and how to refer to the individual tax rates in the PROCEDURE DIVISION.
One way of describing the said table could be as follows:
01 DIRECT-TAX-RATE.
02 TAX-RATE-1 PIC 99.
02 TAX-RATE-2 PIC 99.
02 TAX-RATE-3 PIC 99.
02 TAX-RATE-4 PIC 99.
02 TAX-RATE-5 PIC 99.
This is accomplished by the occurs clause as illustrated below.
01 DIRECT-TAX-RATE.
02 TAX-RATE PIC 99 OCCURS 5 TIMES.
This latter description has some advantages over the former one. First of all, the description is shorter than the previous one (Imagine, if there were more tax rates!). Secondly, the elements in the latter case, can be referred to in the PROCEDURE DIVISION by means of a technique known as subscripting.
For example, the first element is referred to as TAX-RATE(1), the second one as TAX-RATE(2) and so on. The value (1,2 etc.) enclosing within parenthesis is called a subscript and the name along with the subscript is known as subscripted data name. The main advantage of subscripting is due to the fact that if desired, a data name can also be used as a subscript.
The format of occurs clause is as follows:
OCCURS integer TIMES.
The following rules apply for the OCCURS clause and the 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. When a data name is described with the OCCURS clause, the data name as well as any of its subordinate items cannot be referred to in the PROCEDURE DIVISION without a subscript.
- 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 implicity 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.
- If a data name with OCCURS clause requires any qualification, the subscript should be written after the last qualification.
- 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 as OCCURS clause.
- The OCCURS clause can appear in the data description entry in any position after the level number and the data name.
TWO-DIMENSIONAL TABLE:
A table that each of its elements in turn is a table of one dimension, it is called a two-dimensional table.
Example
01 SALES-TABLE.
02 BRANCH-FIGURES OCCURS 18 TIMES.
03 MONTHLY-SALES PIC 9(60V99 OCCURS 12 TIMES.
MULTI-DIMENSIONAL TABLE:
Multi-dimensional tables are to be defined as records with OCCURS clauses at various levels. We go down the hierarchy, each lower level item with an OCCURS clause specifies an additional dimension. For example, consider the following table.
01 TABLE-EXAMPLE.
02 A PIC 9(5) OCCURS 50 TIMES.
02 B OCCURS 20 TIMES.
03 C PIC 9(3).
03 D OCCURS 10 TIMES.
04 E OCCURS 15 TIMES PIC 9(4)V99.
04 F PIC X(4).
A and C are one-dimensional, F is a two-dimensional table and E is a three-dimensional table. B and D are group items which can be referred to as one-dimensional and two-dimensional tables respectively.
No comments:
Post a Comment