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
 

 

How to find the last record in KSDS VSAM file

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

New User


Joined: 17 May 2010
Posts: 4
Location: chennai

PostPosted: Mon May 17, 2010 1:21 pm    Post subject: How to find the last record in KSDS VSAM file
Reply with quote

Hi,

I am having requirement to find the last record in the KSDS VSAM file. Below is my requirement.

In KSDS VSAM file, having the key value of 18 as (USERID(7), DATE(5) COUNT(6))

below is my input.

Code:

ABCD00110137000001
ABCD00110137000002
ABCD00110137000003
ABCD00110137000004
ABCD00110137000005

ABCD00210137000001
ABCD00210137000002
ABCD00210137000003
ABCD00210137000004

ABCD00310137000001
ABCD00310137000002
ABCD00310137000003


From this input i want to insert the record with the next count by all user ids.
Eg:

Code:

ABCD00110137000001
ABCD00110137000002
ABCD00110137000003
ABCD00110137000004
ABCD00110137000005
ABCD00110137000006 -- New One

ABCD00210137000001
ABCD00210137000002
ABCD00210137000003
ABCD00210137000004
ABCD00210137000005 -- New One
ABCD00210137000006 -- New One
ABCD00210137000007 -- New One

ABCD00310137000001
ABCD00310137000002
ABCD00310137000003
ABCD00310137000004 -- New One
ABCD00310137000005 -- New One




I want to fetch the last record count of the each user id. now i am able to fetch only for the first two user ids. but not able fetch the last count of the last user id coz of the end of file.


Please help me out and let me know for any queries.

Thanks,
Jeevitha
Back to top
View user's profile Send private message

Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Mon May 17, 2010 1:54 pm    Post subject:
Reply with quote

Quote:
but not able fetch the last count of the last user id coz of the end of file.

what is the problem you you facing?
Show the logic you are using?
Back to top
View user's profile Send private message
Jeevitha_mainframe

New User


Joined: 17 May 2010
Posts: 4
Location: chennai

PostPosted: Mon May 17, 2010 2:47 pm    Post subject:
Reply with quote

Hi,

To fetch the last count i have used the below logic.

For EG: i want to fetch the last record of ABCD001 this userid. So i have used

MOVE USER-ID TO WS-USERID.
MOVE 99999999999 TO WS-KEY(8:11).

EXEC CICS STARTBR
DATASET ('VSAM FILE')
RESP (WS-CD)
RIDFLD (WS-KEY)
KEYLENGTH (18)
GTEQ
END-EXEC.

(It will point the last record of the ABCD001 user id. After that i readnext the VSAM file until for the next userid)

EXEC CICS READNEXT
DATASET ('VSAM FILE')
INTO (WS-MAX)
RIDFLD (WS-KEY)
END-EXEC.

it will read the first record of the next user id. So i have done read prev two times for fetching the last record.

The problem is:

It working fine for the user first two userid in the above example. its not working for the third user because of the endof file.

once eof has reached its trying to read the next record. So getting the responsible code as 13(record not found).

How to find the last record count for the last user id? Please help me out.

Thanks,
Jeevitha
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8120
Location: East Dubuque, Illinois, USA

PostPosted: Mon May 17, 2010 4:44 pm    Post subject:
Reply with quote

You could (1) write a HIGH-VALUES record to your KSDS file to prevent end of file on data records (which could have other impacts if programs are not expecting this record), or (2) use the response (not responsible) code in your READNEXT command and when you get end-of-file then you have the count you need.
Back to top
View user's profile Send private message
Jeevitha_mainframe

New User


Joined: 17 May 2010
Posts: 4
Location: chennai

PostPosted: Tue May 18, 2010 12:45 pm    Post subject:
Reply with quote

Hi,

I am facing the problem in STARTBR itself, already i have moved 99999999999 to the key values. So when i tried to do the STARTBR in the endof file, getting responsible code as 13(record not found).

i have used the below logic for the endof file record

When the record is not found, i have moved the 00000000000 to the key and start to read the file until highvalues. So when i get responsible code 20(ENDFILE) moving the record count and adding 1 to count. its working fine.

But unneccesarily we need to read all the records until reach the high values. Please let me know any other way without reading all the records to reach end of file.

Thanks,
Jeevitha
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8120
Location: East Dubuque, Illinois, USA

PostPosted: Tue May 18, 2010 2:48 pm    Post subject:
Reply with quote

Is your STARTBR using GE? If not, you must have a key that matches your all '9's value to not get the 13 response code. With a HIGH-VALUES record in the file, and GE specified, the HIGH-VALUES record will be returned for the STARTBR and a READNEXT - READPREV - READPREV sequence will return the last actual record in the file.

Note that I specified a record with key of HIGH-VALUES; your post mentions a record of all '9's. These are very different records, in case you are not aware of the difference.
Back to top
View user's profile Send private message
Jeevitha_mainframe

New User


Joined: 17 May 2010
Posts: 4
Location: chennai

PostPosted: Tue May 18, 2010 3:31 pm    Post subject:
Reply with quote

Hi,

I am using GE in STARTBR. if i have used move high-values to the key with GE specified, and READNEXT - READPREV - READPREV sequence will not return the last actual record in the file. thats why i have moved '99999999999' nd READNEXT - READPREV - READPREV sequence will return the last actual record in the file.

Thanks,
Jeevitha
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Tue May 18, 2010 8:07 pm    Post subject:
Reply with quote

Hello,

Yes, because you have an all 9's record. . .

If the 9's record is removed, your code will have the same result as the non-existent high-values execution. . .
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 Extra character appears in file when ... Balu5491 All Other Mainframe Topics 1 Wed Jul 26, 2017 2:39 pm
No new posts SSH - known_hosts file configuration vasanthz All Other Mainframe Topics 2 Wed Jul 26, 2017 2:10 am
This topic is locked: you cannot edit posts or make replies. Fetching data from BAI File arunsoods JCL & VSAM 1 Wed Jul 19, 2017 4:28 pm
No new posts Write out NODUPS but just from one file Jay Villaverde DFSORT/ICETOOL 8 Fri Jul 14, 2017 12:44 am
No new posts How to add header with Date(YYMMDD) i... Rajan Moorthy DFSORT/ICETOOL 2 Thu Jul 06, 2017 11:44 pm


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