Page 1 of 1

Read VSAM with partial key

PostPosted: Fri Jan 22, 2021 4:47 am
by socker_dad
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?

Re: Read VSAM with partial key

PostPosted: Sat Jan 23, 2021 9:50 pm
by Robert Sample
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).

Re: Read VSAM with partial key

PostPosted: Wed Jan 27, 2021 11:59 pm
by chaat
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.

Re: Read VSAM with partial key

PostPosted: Thu Jan 28, 2021 4:13 am
by socker_dad
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!