---
title: "COBOL: Indexed BY Vs USAGE Vs OCCURS"
description: "In COBOL, Index data items, OCCURS, and KEY clauses are tricky. Explained the benefits and usage of these items with examples."
url: https://srinimf.com/2015/07/20/mainframe-cobol-occurs-indexed-byusage-is-index-1-of-2/
date: 2015-07-20
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2015/07/usage-is-index.jpg?fit=1200%2C700&ssl=1
categories: ["COBOL"]
tags: ["COBOL Index", "COBOL OCCURS", "COBOL Usage"]
type: post
lang: en
---

# COBOL: Indexed BY Vs USAGE Vs OCCURS

The COBOL occurs, Usage is Index, Indexed By clause are tricky. And these are confused by many people. In this post, I have shared three key points:

1. OCCURS
2. Indexed BY
3. Usage is Index

---

### 1). COBOL Occurs

[COBOL programmers](http://www.indeed.com/jobs?q=CICS+DB2&indpubnum=6634974704162507) confused very much about [how to](https://srinimf.com/2011/05/12/cobol-multi-dimension-arrays/) use the OCCURS clause with the KEY phrase correctly. The syntax** for OCCURS clause with **Indexed BY

```
01 GROUP-ITEM.
 03 ITEM-A OCCURS 7 TIMES INDEXED BY IX.
 05 NAME PIC X(20).
 05 ADDRESS-1 PIC X(20).
 05 ADDRESS-2 PIC X(20).
 05 ADDRESS-3 PIC X(20).
 05 CITY PIC X(20).
 05 STATE PIC XX.
 05 ZIP PIC 9(5).
 …
 PERFORM VARYING IX FROM 1 BY 1 UNTIL IX > 7
 DISPLAY NAME(IX),CITY(IX),STATE(IX),SPACE,ZIP(IX)
 END-PERFORM.
```

### 2). COBOL Index

Indexed is different from the index data item (Usage is an index). [This post gives you a complete idea](https://srinimf.com/2015/07/21/5-key-differences-of-index-and-subscript-for-cobol-programmers/).

**About Index in TABLE ARRAY**

- An index name (or just index) is an item that contains a value corresponding to an occurrence number of the table with which it is associated.
- Index(IX) is not necessarily stored in memory as an integer.
- A COBOL vendor may choose to implement it as a pointer to an element of the table, an offset from the beginning of the table, or whatever representation seems convenient for a particular COBOL implementation.
- The purpose of the index is to make accessing a table as efficiently as possible.

**In simple words:**

- The index is different from the Index data item
- The index is not required to define explicitly in the COBOL program
- The index is associated with a Table on which it is mentioned
- The index is not an identifier. So, the index is not an Integer
- Index names you can use as variables in PERFORM, SET, and SEARCH Statements

You are now good with what is an index. Now, I will share the key points on what is an index data item.

### 3). Usage is Index Data Item:

```
01 INDEX-1  USAGE is INDEX.
or
77 INDEX-1  USAGE is INDEX.
```

Related[Best Example for COBOL SEARCH and WHEN Condition](https://srinimf.com/2016/01/06/best-example-for-cobol-search-and-when-condition/)

Benefits of Usage is Index Data item

1. Number one benefit is, you can pass the Usage-is-index data item to a SUBPROGRAM (the **indexed-value** you cannot pass to the sub-program)
2. The other benefit is, you can write the usage-is-index data items to a file.
3. How we use Index the same way you can use usage is an index data item.

**How to Display Usage is Index data item**

```
DISPLAY INDEX_1.
```

### 4). How to Define Key

```
Ascending/Descending Key is XYZ.
```

**Table definition with Multiple KEYS:**

```
01 MAIL-INFO.
 03 MAIL-LIST OCCURS 1000 TIMES
     ASCENDING KEY IS STATE, CITY.
     05 NAME          PIC X(20).
     05 ADDRESS       PIC X(20) OCCURS 3 TIMES.
     05 CITY          PIC X(20).
     05 STATE         PIC XX.
     05 ZIP          PIC 9(5).
```

**Interview Question on Keys:**

- By specifying ascending/descending Key IS, it doesn’t mean that the Table is in sorted order. This is only an expected order.

Also read

- [COBOL: How to Create a VB Array](https://srinimf.com/2020/04/26/cobol-how-to-create-a-vb-array/)DateApril 26, 2020
- [How to Define VB files in COBOL Sample Logic](https://srinimf.com/2012/03/29/cobol-arrays-variable-files/)DateMarch 29, 2012
- [COBOL: How to Define Key in Array](https://srinimf.com/2015/03/24/cobol-use-of-key-phrase-in-occurs-clause/)DateMarch 24, 2015

### Share this:

-
- [Tweet](https://twitter.com/share)
- [![](https://i0.wp.com/assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png)](https://www.pinterest.com/pin/create/link/?url=https%3A%2F%2Fsrinimf.com%2F2015%2F07%2F20%2Fmainframe-cobol-occurs-indexed-byusage-is-index-1-of-2%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2015%2F07%2Fusage-is-index.jpg%3Ffit%3D1200%252C700%26ssl%3D1&description=COBOL%3A%20Indexed%20BY%20Vs%20USAGE%20Vs%20OCCURS)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2015/07/20/mainframe-cobol-occurs-indexed-byusage-is-index-1-of-2/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2015/07/20/mainframe-cobol-occurs-indexed-byusage-is-index-1-of-2/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2015/07/20/mainframe-cobol-occurs-indexed-byusage-is-index-1-of-2/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2015/07/20/mainframe-cobol-occurs-indexed-byusage-is-index-1-of-2/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20COBOL%3A%20Indexed%20BY%20Vs%20USAGE%20Vs%20OCCURS&body=https%3A%2F%2Fsrinimf.com%2F2015%2F07%2F20%2Fmainframe-cobol-occurs-indexed-byusage-is-index-1-of-2%2F&share=email)
-

### Like this:

Like Loading…