# Reading VSAM file

**URL:** <https://techcommunity.softwareag.com/t/reading-vsam-file/95797>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Mainframes, Natural-Database-and-TP-Monitor-Interfaces-on-Mainframes\
**Created:** [December 31, 2010, 2:15pm UTC](https://techcommunity.softwareag.com/t/reading-vsam-file/95797 "2010-12-31T14:15:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kugh](https://avatars.discourse-cdn.com/v4/letter/k/f475e1/32.png) [@Kugh](https://techcommunity.softwareag.com/u/Kugh)\
**Post date:** [December 31, 2010, 2:15pm UTC](https://techcommunity.softwareag.com/t/reading-vsam-file/95797/1 "2010-12-31T14:15:38Z")

</div>

Hi all,

We are reading a VSAM file for the record where PRIM-KEY consists of account-nr P17 + serial of P5.  
Layout:  
1 PRIM-KEY B12 /\* This is the index

This matches the underlying copybook as indicated below:

01 :ACNT:-LOCT-REC.  
– 03 :ACNT:-LOCT-MAIN-REC.  
-------05 :ACNT:-NUMBER-KEY.  
----------10 :ACNT:-NUMBER PIC S9(17) COMP-3.  
----------10 :ACNT:-SERIAL PIC S9(5) COMP-3.

The issue we find is that no exact match seems possible:

For us to locate account 209072970 with serial number 0, we actually have to read starting at 209072969 (one less than value we are looking for). I have never come across this (but have not dealt with VSAM much).

Any help would be much appreciated.

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [December 31, 2010, 5:29pm UTC](https://techcommunity.softwareag.com/t/reading-vsam-file/95797/2 "2010-12-31T17:29:16Z")

</div>

When you read the account 209072970 (after starting from one less), write out the value in Hex.

Also, write out the starting value (have you specified it as a constant, or a variable?) in hex.

steve

---

<div class="post-metadata">

**Author:** ![Douglas\_Kelly](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/douglas_kelly/32/102_2.png) [@Douglas\_Kelly](https://techcommunity.softwareag.com/u/Douglas_Kelly)\
**Post date:** [January 2, 2011, 12:10am UTC](https://techcommunity.softwareag.com/t/reading-vsam-file/95797/3 "2011-01-02T00:10:48Z")

</div>

you have two packed numbers in that binary field. In Natural, redefine the B12 to match your copy book:

01 PRIM-KEY (B12)  
01 REDEFINE PRIM-KEY  
02 ACCT-NUMBER (P17)  
02 SERIAL-NUMBER (P5)

This will allow you do do exact searches on the VSAM file key. You may also have a mismatch of packed sign fields. If you do as Steve suggests (print the hex values of the PRIM-KEY), you can see if the sign is F or C and set the PSIGNF parameter accordingly (default is H’C’).

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [April 2, 2021, 2:59pm UTC](https://techcommunity.softwareag.com/t/reading-vsam-file/95797/4 "2021-04-02T14:59:35Z")

</div>


