This article discusses the COBOL "Occurs...Depending On" clause. We explain how it works, and how mainframe files which use it can be handled on a PC, when converting mainframe files to PC files.


Problems with COBOL Occurs? Request a COBOL quote
We know how to handle them!

COBOL files can have "tables".  A table is a field or group (group of fields) that occurs multiple times.  The number of times it repeats is specified by the OCCURS clause, like this:


This creates 12 fields in the record, each with a PIC S9(5)V99.

OCCURS can also be applied to a group, such as this example:

       10  QUANTITY           PIC 9999.
       10  DESCRIPTION        PIC X(30).
       10  UNIT-PRICE         PIC S9(5)V99.

This creates 25 groups, each of which contains the three fields QUANTITY, DESCRIPTION, and UNIT-PRICE, for a total of 75 fields.


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.

The invoice record fragment from above could be modified as follows:

   05  LINE-ITEM-COUNT                  PIC 99.
       10  QUANTITY                     PIC 9999.
       10  DESCRIPTION                  PIC X(30).
       10  UNIT-PRICE                   PIC S9(5)V99.

The table LINE-ITEMS contains three fields (QUANTITY,  DESCRIPTION,  UNIT-PRICE) which make up one line on an invoice.  Each invoice can have from 0 to 25 line items.  The actual number of line items on a particular invoice, and therefore in the record, is given by the field LINE-ITEM-COUNT.

One instance of the table occupies 41 bytes, and the table may occur from 0 to 25 times, so the total space occupied by the table LINE-ITEMS in the record varies from 0 bytes to 1025 bytes.  If there are any fields after this table, their position in the record will shift, depending on the number of occurrences of the table.

There is a more complete description of OCCURS and OCCURS DEPENDING ON in the "Tables and Occurs" section of our Reading COBOL Layouts tutorial.

The PC File

Most PC databases cannot handle this concept. There are three potential solutions. In order of complexity, and using this example, they are:

1. If the OCCURS...DEPENDING ON is at the end of the record, as it commonly is, and DISC appends a CR-LF to the records,  some databases can deal with this and will import as many occurrences as contained in the record, then advance to the next record when they encounter the CR-LF delimiter. You should define all 25 occurrences (75 fields) in your database.

2. If the size of the table is not too large, in both bytes and number of fields, DISC can convert ALL records so they have 25 occurrences of the table. When we expand the number of occurrences in a particular record, say from 3 to 25, we fill the added character fields with spaces, and the added numeric fields with zeros.  Be careful to calculate the final size before choosing this method. A table with, say, ten fields of ten bytes each that occurs from 1 to 100 times would contain 1,000 fields and 10,000 bytes when expanded to the maximum size.  Expanding every record to the maximum possible size can make the file very large, which is why the occurs...depending on was used in the first place.

3. The last solution is to extract the table from the COBOL record and write each occurrence as a separate record in a new file, then add a key to relate those records to the main file, thus creating a relational database.

Additional Information

For a complete discussion of COBOL layouts, please see our Reading COBOL Layouts tutorial.

For more articles on data conversion, see our TechTalk Index.

Our COBOL Conversion Services

Disc Interchange Service Company's primary business is converting mainframe COBOL files.  We have the tools to properly convert both fixed-length tables and variable-length tables, including nested tables, in either EBCDIC or ASCII.
With over 32 years of experience with thousands of files, we have the knowledge to do your job right the first time.
Mainframe & AS/400 Conversions
Mainframe & AS/400 Conversion to PC

With 32 years experience, we are the experts at transferring mainframe data to PCs.
Get more information on IBM Mainframe conversions
Request a COBOL quote

Disc Interchange Service Company, Inc.
15 Stony Brook Road
Westford, MA 01886