Read VSAM with partial key



Help for IBM's record-oriented filesystem VSAM, ESDS, KSDS, RRDS, LDS and Storage management Subsystems

Read VSAM with partial key

Postby socker_dad » Fri Jan 22, 2021 4:47 am

OK, I have been knocking my head about for two days and just can't figure out the answer.

This really should be easy, but my mind is in "I hate you" mode.

My VSAM file key is:

Record Code      PIC X(2)          '51'
Appl Code        PIC X(1)           unknown, set to space
Procedure Code   PIC X(5)          '0910V'
 

Only the Appl Code is unknown. I can view the records on the VSAM file and know the existing keys are 51, C, 0910V and 51, V, 0910V.

I don't know if the file read codes are generic or unique to my installation, but here are the read methods I have tried:

1. START (F), then READ-NEXT (G) Return code from START is 23
2. START-GREATER-THAN (N), then READ-NEXT (G) Return code from S-G-T is 00, return code from READ-NEXT is also 00, but the record retrieved was the first record in the VSAM, not the key requested
3. READ-KEY (H), then READ-NEXT (G) Return from READ-KEY is 23

I just don't what do to with this. #2 seems to be correct, but it is not returning the correct record! And I double-checked the key before the READ-NEXT and it is populated with the original partial key - and the called module that actually performs the VSAM access does have my key values in it before the READ-NEXT.

What expect to see is the first read pointing to the first entry that is immediately one record greater than my supplied key |51| |0910V|, which should be |51|C|0910V|. Instead I get |51|C|A0010|.

Can anyone see what I am doing wrong?
socker_dad
 
Posts: 4
Joined: Tue Sep 22, 2020 5:37 am
Has thanked: 0 time
Been thanked: 0 time

Re: Read VSAM with partial key

Postby Robert Sample » Sat Jan 23, 2021 9:50 pm

What expect to see is the first read pointing to the first entry that is immediately one record greater than my supplied key |51| |0910V|, which should be |51|C|0910V|. Instead I get |51|C|A0010|.
Your problem is that you do not understand how partial key reads work in VSAM. Partial key reads start with the first byte of the key and continue byte-by-byte through the length of the key. The 0910V part of the key will not be used unless the first 3 bytes all match what you've provided. The only way to retrieve the 51C0910V record would be to use that value in the key read (or at least use 51C0 which would return the first record whose key value exceeds 51C0).
Robert Sample
Global moderator
 
Posts: 3657
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 270 times

Re: Read VSAM with partial key

Postby chaat » Wed Jan 27, 2021 11:59 pm

What you are attempting to do would be easier with an alternate index on Record Code, Procedure Code, Appl Code. Check the VSAM manuals on how to build an ALTERNATE INDEX.
chaat
 
Posts: 26
Joined: Sun Aug 16, 2009 11:07 pm
Location: St. Cloud, Minnesota
Has thanked: 0 time
Been thanked: 1 time

Re: Read VSAM with partial key

Postby socker_dad » Thu Jan 28, 2021 4:13 am

Robert, you are correct as always: I didn't realize that was how VSAM partial keys work. I just assumed (foolishly) that it was similar to DB2.

Chaat- this file has 9 indices. I'll dig into that.

Thank you for pointing me in the right direction!
socker_dad
 
Posts: 4
Joined: Tue Sep 22, 2020 5:37 am
Has thanked: 0 time
Been thanked: 0 time


Return to VSAM/SMS

 


  • Related topics
    Replies
    Views
    Last post