IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Read VSAM file based on a partial key


IBM Mainframe Forums -> JCL & VSAM
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
seahawk789

New User


Joined: 22 Feb 2010
Posts: 56
Location: Cochin

PostPosted: Tue Aug 19, 2014 10:26 am
Reply with quote

I have a VSAM file with key as 2 fields of 5 bytes each

Code:

KEYFIELD1 - 5 BYTES
KEYFIELD2 - 5 BYTES
...
Other data fields


However in my program I know the value for only 1 key - KEYFIELD1. Also I know that even if I retrieve data using KEYFIELD1 still it will return only 1 record. As a result in my program I have declared only KEYFIELD1 as the attribute

Code:

01 KEY-VSAM
    05 KEYFIELD1   PIC X(05)


and using that I am executing CICS read statement

Code:

EXEC CICS READ
DATASET  (TVSAM-FILE)
RIDFIELD (KEY-VSAM)
KEY LENGTH (LENGTH OF KEYVSAM)
INTO (WS-REC)
RESP (WS-RESPONSE)
EQUAL
END-EXEC


Now since the key attribute of the actual VSAM file differs from what I have in my code will the above statement be successful ? or if not is it possible to handle the error condition in WS-RESPONSE ?

Or the only option is to use STARTBR AND THEN READNEXT ?

Please help.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Aug 19, 2014 12:13 pm
Reply with quote

If your VSAM key is 10 bytes, it is 10 bytes. It is not made of two parts, or one part or 10 - or, to put it another way. VSAM doesn't know or care.

Reading a VSAM file with a key only returns a record for an exact match.

If you only know a partial, leading, part of the key, then the rest of the key you set to a value lower than can be reasonably expected (binary zeros is the most effective) and use whatever is provided to "start" from that particular point in the file, and then use one or more sequential "reads".
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Tue Aug 19, 2014 2:41 pm
Reply with quote

As you have only a partial key, you have to use the GENERIC option in your EXEC CICS READ statement.
Back to top
View user's profile Send private message
seahawk789

New User


Joined: 22 Feb 2010
Posts: 56
Location: Cochin

PostPosted: Tue Aug 19, 2014 6:06 pm
Reply with quote

Thanks. So the below code should work.

Code:
EXEC CICS READ
DATASET  (TVSAM-FILE)
RIDFIELD (KEY-VSAM)
KEY LENGTH (LENGTH OF KEYVSAM)
INTO (WS-REC)
RESP (WS-RESPONSE)
GENERIC
END-EXEC
Back to top
View user's profile Send private message
Pete Wilson

Active Member


Joined: 31 Dec 2009
Posts: 580
Location: London

PostPosted: Wed Aug 20, 2014 3:26 pm
Reply with quote

Are the 2 keys of the records contiguous? If not you'd have to be looking at using an alternate index to access the file based on the second key value.
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 3049
Location: NYC,USA

PostPosted: Wed Aug 20, 2014 7:44 pm
Reply with quote

As suggested by Pete , I would also suggest to use alternate index. However, when you use GENERIC you should be able to get the data.
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2481
Location: Netherlands, Amstelveen

PostPosted: Wed Aug 20, 2014 9:30 pm
Reply with quote

Quote:

I have a VSAM file with key as 2 fields of 5 bytes each


That is NOT possible (like Mr. Woodger stated), and if you want to do a generic read, supply the total length (10 bytes) and the keyfield as a 10 byte field.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> JCL & VSAM

 


Similar Topics
Topic Forum Replies
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Error to read log with rexx CLIST & REXX 11
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts Access to non cataloged VSAM file JCL & VSAM 18
Search our Forums:

Back to Top