TSO-ISPF JCL COBOL VSAM DB2 CICS Tools Articles Job Portal Forum Quiz Interview Q&A

COBOL - Table Introduction


Sometimes it becomes necessary to handle group of data consisting of similar items. Such a group is called a Table or Array. An array is used to store similar items or elements. For example, a series of totals in the working storage with the same format.

A table is a list of stored fields that are looked up or referenced by the program. It also eliminates the need for separate entries for repeated data items. The usage of tables can be illustrated by the following example

For example when you need to list the months in normal way of representing it is:

01 MONTH-TABLE.
    02 MONTH-1	   PIC	X(9)	VALUE	'JANUARY  '.
    02 MONTH-2	   PIC	X(9)	VALUE	'FEBRAURY '.
    02 MONTH-3	   PIC	X(9)	VALUE	'MARCH    '.
    02 MONTH-4	   PIC	X(9)	VALUE	'APRIL    '.
    02 MONTH-5	   PIC	X(9)	VALUE	'MAY      '.
    02 MONTH-6	   PIC	X(9)	VALUE	'JUNE     '.
    02 MONTH-7	   PIC	X(9)	VALUE	'JULY     '.
    02 MONTH-8	   PIC	X(9)	VALUE	'AUGUST   '.
    02 MONTH-9	   PIC	X(9)	VALUE	'SEPTEMBER'.
    02 MONTH-10    PIC  X(9)	VALUE	'OCTOBER  '.
    02 MONTH-11    PIC  X(9)	VALUE	'NOVEMBER '.
    02 MONTH-12    PIC  X(9)	VALUE	'DECEMBER '.

In the above example, the same data month name is being repeated 12 times. Instead of defining the elements like this we can define it as a table with 12 elements.

Each element of the table can be referred using a Subscript or an index. Now lets us look at how the table can be defined in COBOL.

01 MONTH-TABLE.
    02 MONTH-NAME PIC	X(9)	OCCURS 12 TIMES.

This table can be fixed length tables and Variable length tables. The tables or Arrays are define using OCCURS in COBOL.

Now let us look at Occurs clause in next chapter.

If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!

Are you looking for Job Change? Job Portal