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

COBOL - Occurs Clause


  • OCCURS clause is used to define a table.

  • OCCURS clause indicates the repetition of data name definition.

  • OCCURS clause specifies tables whose elements can be referred to by indexing or subscripting.

  • OCCURS clause can be specified for elementary or group item. It can be used only with level numbers starting from 02 to 49.

  • Occurs can’t be defined for a data item which:

    1. Has a level number of 01, 66, 77, or 88.

    2. Describes a redefined data item

  • REDEFINES and OCCURS clause cannot appear for the same data item. However REDEFINES clause can appear for a group item whose sub item contains occurs clause.

  • VALUE clause cannot be specified for associated data name defined with OCCURS clause or any sub item to the occurs clause.

  • Tables can be Fixed Length or Variable Length.


Example for one-dimensional and two-dimensional table is as follows:
  1. One-Dimensional Table

    01 WS-TABLE.
       05 WS-A PIC A(12) VALUE 'GOODMORNING' OCCURS 5 TIMES.

    WS-TABLE holds the value of

    "GOODMORNING GOODMORNING GOODMORNING GOODMORNING GOODMORNING "

  2. Two-Dimensional Table

    01 WS-TABLE.
       05 WS-A OCCURS 2 TIMES.
    	  10 WS-B PIC A(05) VALUE 'GOOD '.
    	  10 WS-C OCCURS 2 TIMES.
    	     15 WS-D PIC X(8) VALUE 'MORNING '.
    

    WS-TABLE holds the value of

    "GOOD MORNING MORNING GOOD MORNING MORNING "

COBOL also permits tables that occur a variable number of times, depending on the value in some other field. This is similar to the COBOL OCCURS clause, except the number of times it occurs varies from record to record.

This causes the records to vary in size depending on the number of occurrences in any given record. Consequently, data within the table, and any data following the table will appear in varying locations in different records.

We will discuss variable length table 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