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

Reading Last Record in KSDS VSAM File


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

New User


Joined: 25 Jul 2008
Posts: 15
Location: Chennai

PostPosted: Wed May 23, 2012 8:02 pm
Reply with quote

Hi,

I have data in the below format in a KSDS VSAM file,

Cust No Cust Dept Exp

1 1 322
1 1 412
1 1 721
2 2 233

I am using STARTBR option to point the record in above file (all 3 fields are key fields). I will be getting Cust No and Cust Dept as input, so I am passing 999 to Exp so that STARTBR will point to record 2 2 233.

I am then doing a READNEXT and then READPREV to read all matchung records.

I am facing problem for the below data setup,

Cust No Cust Dept Exp

1 1 322
1 1 412
1 1 721

The Key is 1 1 999, the STARTBR gives an EIBRESP 13, which is record not found, since no record greated than Exp 999 is found. After STARTBR if I do a READPREV it gives EIBRESP 16.

Is there a way to read in reverse direction for the above scenario?

Code:

 EXEC CICS STARTBR                           
           DATASET   (CUST-INFO)   
           RIDFLD    (CUST-INFO-KEY)           
           KEYLENGTH (LENGTH OF CUST-INFO-KEY)
           GTEQ                               
           RESP      (RESP-CODE)           
 END-EXEC                                     
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed May 23, 2012 8:07 pm
Reply with quote

maybe add a control record, 9 9 999, to the file?
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Wed May 23, 2012 8:20 pm
Reply with quote

Move all HIGH-VALUES to the Key (RIDFLD), issue a STARTBR then followed by single READPREV (maybe two, can't recall) and this will be the last record on the file. The RIDFLD will contain the last record's Key value.

You can test this using CECI, providing you have Authority.
Back to top
View user's profile Send private message
Thagun

New User


Joined: 25 Jul 2008
Posts: 15
Location: Chennai

PostPosted: Wed May 23, 2012 8:20 pm
Reply with quote

Its an existing file and cannot be changed to include header n trailer.
Back to top
View user's profile Send private message
Thagun

New User


Joined: 25 Jul 2008
Posts: 15
Location: Chennai

PostPosted: Wed May 23, 2012 8:24 pm
Reply with quote

Bill,

The file can have thousands of records and the records in which I am interested might be in the middle, so moving high values to Key fields will result in reading back from 1000th record, which is not desirable.

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

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed May 23, 2012 8:46 pm
Reply with quote

I think you are EXTREMELY confused on what you want. The topic title "Reading Last Record in KSDS VSAM File" conflicts with the statement you just made:
Quote:
The file can have thousands of records and the records in which I am interested might be in the middle

The last record in a VSAM file will not be in the middle -- it will be the LAST RECORD.

So why don't you start all over, and attempt to explain what you have and what you want to achieve, and where your problem is?
Back to top
View user's profile Send private message
Thagun

New User


Joined: 25 Jul 2008
Posts: 15
Location: Chennai

PostPosted: Thu May 24, 2012 10:22 am
Reply with quote

Rob, apologies for the confusion. The problem statement is, if the records which are matching my keys are in middle of KSDS file I am able to read the records in reverse direction successfully by moving 999 to Exp.

But if the record that matches my key is the last record in my KSDS file, then moving 999 to Exp and doing a STARTBR gives EIBRESP 13. Hence not able to read it in reverse direction.

Hope it clarifies.
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

PostPosted: Thu May 24, 2012 11:33 am
Reply with quote

Hi Senthil,

Thagun wrote:

I am then doing a READNEXT and then READPREV to read all matchung records.



What happens if you do READPREV and READPREV here?

Also if you need to read all records for a particular customer why you cant move '000' instead of '999' and start forward browsing ?

Regards,
Chandan
Back to top
View user's profile Send private message
Thagun

New User


Joined: 25 Jul 2008
Posts: 15
Location: Chennai

PostPosted: Thu May 24, 2012 1:14 pm
Reply with quote

Hi Chandan,

When I do a READPREV it gives EIBRESP 16. Reading forward is the last option if reading backward isnt working.

Regards,
Senthil
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: Thu May 24, 2012 1:23 pm
Reply with quote

When you look at the documentation of the start browse, does that give you any clues?

If you can't get a "dummy" high-record as dbz suggested and you can't follow Mr Bill's suggestion...

Why is it so necessary to read backwards?
Back to top
View user's profile Send private message
Peter cobolskolan

Active User


Joined: 06 Feb 2012
Posts: 104
Location: Sweden

PostPosted: Thu May 24, 2012 1:51 pm
Reply with quote

When you are using Browsing you should use partial key in your Startbr.
When you look for the last occurance of Cust/Dept 11, use keyvalue 11, keylength(2) GENERIC GT to position at the next available record which has a Cust/Dept greater than 11, any number of exp. Then your Readprev will get the previous Cust/Dept with the highest exp-value.
The last problem you mention, Eibresp=16, Invalid Request (?), indicates that the request is invalid! Perhaps no previous Startbr that has response normal.
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: Thu May 24, 2012 2:05 pm
Reply with quote

To save TS some reading, what does starting the browse beyond the last recod on the file give, your way, Peter?
Back to top
View user's profile Send private message
Thagun

New User


Joined: 25 Jul 2008
Posts: 15
Location: Chennai

PostPosted: Thu May 24, 2012 2:13 pm
Reply with quote

Thanks Bill, I just wanted to get it confirmed in the forum that it cannot be done without a trailer record.

There is an existing code which says i reads the file in reverse direction, but when I tested it, it wasnt working for the scenario i had explained.

Thanks again for yor response.
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: Thu May 24, 2012 2:21 pm
Reply with quote

Good for being thorough.

Not so good for being unclear and lacking the full detail in the first place. It would have helpd. Next time, you'll give it all up front?
Back to top
View user's profile Send private message
Thagun

New User


Joined: 25 Jul 2008
Posts: 15
Location: Chennai

PostPosted: Thu May 24, 2012 2:27 pm
Reply with quote

Sure Bill. Having clarity and all required details in the question is one of the things i have learnt today icon_biggrin.gif.
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 FTP VB File from Mainframe retaining ... JCL & VSAM 1
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
Search our Forums:

Back to Top