---
title: "How to Read VSAM File Randomly in COBOL"
description: "VSAM files tips and ideas on how they will be accessed in COBOL"
url: https://srinimf.com/2020/03/29/7-quick-tips-on-mainframe-vsam-files/
date: 2020-03-29
modified: 2026-10-10
author: "Srini"
image: https://i0.wp.com/srinimf.com/wp-content/uploads/2020/03/pexels-photo-4397841.jpeg?fit=1880%2C1253&ssl=1
categories: ["VSAM"]
tags: ["VSAM FILE READ", "VSAM files"]
type: post
lang: en
---

# How to Read VSAM File Randomly in COBOL

Here’s a sample COBOL program that reads [VSAM file](https://srinimf.com/2012/03/03/vsam-error-codes/) randomly. The logic given here is helpful to use in your projects.

Related[Guide on Creating VSAM Alternate Index using IDCAMS](https://srinimf.com/2023/10/24/the-merits-of-vsam-alternate-index/)

---

## Storage of [VSAM Files](https://srinimf.com/2015/02/07/vsam-file-reading-in-cobol-program/)

1. Entries will store in Master or User catalog
2. Plainly, the Master and User-catalog both can have entries of VSAM and non-VSAM datasets.
3. Only KSDS datasets have Indexed. The ESDS and RRDS have only the data components. That means they do not have an index.
   - |**Data component**|**Index component**|
4. While working with ESDS and RRDS you need not index.
5. KSDS index is a combination of Key and Value. Also, KSDS supports an alternate index.
   - **Index key**|**Sequence value**
6. In KSDS, firstly, it locates the index, then finds corresponding sequence value. From this it gets data from control interval and area.
7. The catalog that stores information of VSAM and non-VSAM datasets is called the ICF integrated catalog facility.

*VSAM COBOL Example Program Read Today*

Related[VSAM: KSDS, ESDS, LDS, RRDS Differences and Their Uses](https://srinimf.com/2012/05/16/vsam-ksds-esds-lds-rrds-and-their-uses/)

## [How to](https://srinimf.com/2016/10/20/how-to-resolve-file-open-errors-better-way-in-vsam/) READ VSAM Files Randomly

```
SELECT TEST1 ASSIGN TO TEST1
  ORGANIZATION IS INDEXED 
  ACCESS IS RANDOM 
  RECORD-KEY IS         TS-EMPLOYEE-NUMBER 
  ALTERNATE RECORD KEY IS TS-SOCIAL-SECURITY-NO 
  ALTERNATE RECORD KEY IS TS-DEPT-NO 
                  WITH DUPLICATES.
```

Related Posts

- [COBOL VSAM Files READ with START Logic](https://srinimf.com/2015/02/07/vsam-file-reading-in-cobol-program/)DateFebruary 7, 2015
- [COBOL VSAM Return Code: Here’s Example How to Define it](https://srinimf.com/2016/10/26/the-easy-way-to-define-vsam-return-code-in-cobol/)DateOctober 26, 2016
- [The VSAM Write Error 24 Awesome Solution](https://srinimf.com/2016/12/28/the-vsam-write-error-24-awesome-solution/)DateDecember 28, 2016

### 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%2F2020%2F03%2F29%2F7-quick-tips-on-mainframe-vsam-files%2F&media=https%3A%2F%2Fi0.wp.com%2Fsrinimf.com%2Fwp-content%2Fuploads%2F2020%2F03%2Fpexels-photo-4397841.jpeg%3Ffit%3D1200%252C800%26ssl%3D1&description=How%20to%20Read%20VSAM%20File%20Randomly%20in%20COBOL)
-
- [Share on Tumblr](https://www.tumblr.com/share)
- [Share on WhatsApp (Opens in new window) WhatsApp](https://srinimf.com/2020/03/29/7-quick-tips-on-mainframe-vsam-files/?share=jetpack-whatsapp)
- [More](#)
-

- [Print (Opens in new window) Print](https://srinimf.com/2020/03/29/7-quick-tips-on-mainframe-vsam-files/?share=print)
- [Share on Reddit (Opens in new window) Reddit](https://srinimf.com/2020/03/29/7-quick-tips-on-mainframe-vsam-files/?share=reddit)
- [Share on Telegram (Opens in new window) Telegram](https://srinimf.com/2020/03/29/7-quick-tips-on-mainframe-vsam-files/?share=telegram)
- [Email a link to a friend (Opens in new window) Email](mailto:?subject=%5BShared%20Post%5D%20How%20to%20Read%20VSAM%20File%20Randomly%20in%20COBOL&body=https%3A%2F%2Fsrinimf.com%2F2020%2F03%2F29%2F7-quick-tips-on-mainframe-vsam-files%2F&share=email)
-

### Like this:

Like Loading…
