Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Read VSAM file based on a partial key

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> JCL & VSAM
View previous topic :: :: View next topic  
Author Message
seahawk789

New User


Joined: 22 Feb 2010
Posts: 47
Location: Cochin

PostPosted: Tue Aug 19, 2014 10:26 am    Post subject: Read VSAM file based on a partial key
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7228

PostPosted: Tue Aug 19, 2014 12:13 pm    Post subject: Reply to: Read VSAM file based on a partial key
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: 1219
Location: Israel

PostPosted: Tue Aug 19, 2014 2:41 pm    Post subject:
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: 47
Location: Cochin

PostPosted: Tue Aug 19, 2014 6:06 pm    Post subject:
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 User


Joined: 31 Dec 2009
Posts: 437
Location: London

PostPosted: Wed Aug 20, 2014 3:26 pm    Post subject:
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

Senior Member


Joined: 21 Sep 2010
Posts: 1609
Location: NY,USA

PostPosted: Wed Aug 20, 2014 7:44 pm    Post subject:
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: 2422
Location: Netherlands, Amstelveen

PostPosted: Wed Aug 20, 2014 9:30 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> JCL & VSAM All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts File Aid to File Manager conversion murali3955 IBM Tools 4 Thu Nov 24, 2016 3:41 pm
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm
No new posts CICS Roll back partially - Need to re... dwijadas CICS 4 Wed Nov 16, 2016 4:30 pm
No new posts Problem in writing Output file vickey_dw COBOL Programming 5 Mon Nov 14, 2016 11:14 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us