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 read a previous record VSAM KSDS file?

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

Active User


Joined: 08 Feb 2009
Posts: 116
Location: CHENNAI/NEW JERSEY - INDIA/USA

PostPosted: Tue Mar 20, 2012 4:03 am    Post subject: How to read a previous record VSAM KSDS file?
Reply with quote

Hi,

Please let me know How to read a previous record VSAM KSDS file.
Back to top
View user's profile Send private message

dbzTHEdinosauer

Global Moderator


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

PostPosted: Tue Mar 20, 2012 4:11 am    Post subject:
Reply with quote

in CICS or Batch?
Back to top
View user's profile Send private message
Elixir

Active User


Joined: 08 Feb 2009
Posts: 116
Location: CHENNAI/NEW JERSEY - INDIA/USA

PostPosted: Tue Mar 20, 2012 4:17 am    Post subject:
Reply with quote

In Batch..if possible
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Tue Mar 20, 2012 5:05 am    Post subject: Reply to: How to read a previous record VSAM KSDS file?
Reply with quote

Do you mean the record before the current one you have read? Or just any old record you have read previously in that program?

What language, or are you not concerned?

Are you processing the KSDS "sequentially", "dynamically" or "randomly"?

I suppose the worst case is that you want the record before the one you have just read, randomly. So what does your key look like, the rightmost part of it anyway? If you need to read that record, what happened at the design stage to not have a key for it?
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


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

PostPosted: Tue Mar 20, 2012 5:16 am    Post subject: Reply to: How to read a previous record VSAM KSDS file?
Reply with quote

Keep a copy of the current (already read) KEY before you issue a READ NEXT (assuming you're reading sequentially).

Once you've determined you've read past the desired key, issue a START KEY NOT LESS THAN "Previous Key" which will reposition the VSAM file (CRP) at the previous key, then issue a READ NEXT and you're done.

You may have to define ACCESS IS DYNAMIC in the FD, so verify this beforehand by testing both DYNAMIC access and ACCESS IS SEQUENTIAL.
Back to top
View user's profile Send private message
Elixir

Active User


Joined: 08 Feb 2009
Posts: 116
Location: CHENNAI/NEW JERSEY - INDIA/USA

PostPosted: Tue Mar 20, 2012 5:40 am    Post subject:
Reply with quote

I am using Batch COBOL program to attain this objective.

VSAM Input File

KEY(1st 5 Characters)
NON KEY(Last 7 Characters)

Key 1 AAAAAA
Key 2 BBBBBB
Key 3 CCCCCC
Key 4 DDDDDD
Key 5 EEEEEE

I am getting data from another flat file, it contains Key fields. I read the key fields 1 by 1 from the flat file.

If Key 1 then write to o/p Key1 AAAAAA BBBBBB

If Key 2 then write to o/p Key2 BBBBBB CCCCCC

If Key 3 then write to o/p Key3 CCCCCC DDDDDD

If Key 4 then write to o/p Key4 DDDDDD EEEEEE

If Key 5 then write to o/p Key5 EEEEEE AAAAAA

The reason to me ask How to Read previous record in VSAM file is, if the flat file contains Key 5, then I need to get the non-key Value from Key 1 record.

The output is a Flat file only

Thanks!
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Tue Mar 20, 2012 12:14 pm    Post subject: Reply to: How to read a previous record VSAM KSDS file?
Reply with quote

Maybe a modified two-file match? The match directly gets you the first non-key part, whilst the next match gets you the second. Special case is to save the second part first time it is created, as it will be used for the second part of the final match.
Back to top
View user's profile Send private message
Elixir

Active User


Joined: 08 Feb 2009
Posts: 116
Location: CHENNAI/NEW JERSEY - INDIA/USA

PostPosted: Tue Mar 20, 2012 7:19 pm    Post subject:
Reply with quote

The method I adopted is

(Appropriate File handling has been done)

Read Flat File to get the Key value.

Start File Key is not < Key Field

If Not File Status 23
Read File Key is Key field
Read Next
If not File Status 10
Write o/p
Else Move Lowest possible value into the key field
Start File Key is Key Field
Read File Key is Key field
Write o/p
End-if
Else
Error out not exist in VSAM
End-if

The Results are coming as expected. But I am not sure if its the best/only approach to be followed.

Thank you!
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Tue Mar 20, 2012 7:33 pm    Post subject: Reply to: How to read a previous record VSAM KSDS file?
Reply with quote

How about next time forget the colours, and use the Code tags. please?
Back to top
View user's profile Send private message
Elixir

Active User


Joined: 08 Feb 2009
Posts: 116
Location: CHENNAI/NEW JERSEY - INDIA/USA

PostPosted: Tue Mar 20, 2012 7:40 pm    Post subject:
Reply with quote

what code tags bill?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Tue Mar 20, 2012 7:48 pm    Post subject:
Reply with quote

how to use bbcode, look for CODE


makes your convoluted negative, multi-tier IF easier to read.

Code:

If Not File Status 23
THEN
   Read File Key is Key field
   Read Next
   If not File Status 10
   THEN
      Write o/p
   Else
      Move Lowest possible value into the key field
      Start File Key is Key Field
      Read File Key is Key field
      Write o/p
   End-if
Else
   Error out not exist in VSAM
End-if

Back to top
View user's profile Send private message
Elixir

Active User


Joined: 08 Feb 2009
Posts: 116
Location: CHENNAI/NEW JERSEY - INDIA/USA

PostPosted: Tue Mar 20, 2012 7:48 pm    Post subject:
Reply with quote

Elixir wrote:
The method I adopted is

(Appropriate File handling has been done)

Read Flat File to get the Key value.

Start File Key is not < Key Field (Position the File at the Key Field)

If Not File Status 23
Read File Key is Key field (Read File)
Read Next (Read the next key field record)
If not File Status 10
Write o/p (write to o/p file Key Field Old Non-Key Value New Non-Key Value)
Else Move Lowest possible value into the key field
Start File Key is Key Field (Ignore this)
Start File Key > Key Field (Consider this)
Read File Key is Key field (Get the next Key Field Values)
Write o/p(write to o/p file Key Field Old Non-Key Value New Non-Key Value)
End-if
Else
Error out not exist in VSAM
End-if

The Results are coming as expected. But I am not sure if its the best/only approach to be followed.

Thank you!
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Tue Mar 20, 2012 7:50 pm    Post subject:
Reply with quote

Elixir,
you were too busy posting code with the quote tag instead of code tag.
look at my previous post.
Back to top
View user's profile Send private message
Elixir

Active User


Joined: 08 Feb 2009
Posts: 116
Location: CHENNAI/NEW JERSEY - INDIA/USA

PostPosted: Tue Mar 20, 2012 8:22 pm    Post subject:
Reply with quote

dbzTHEdinosauer

The Posting time of both are 9:18 am (EST) what I see.

Cant avoid those...

Morever

Start File Key > Key Field is the correction I suggest.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Tue Mar 20, 2012 9:00 pm    Post subject:
Reply with quote

the request was that you use bb CODE tags, not QUOTE tags (markup language)
to post your code,
because it is easier to read and understand when the indentation is perserved.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Wed Mar 21, 2012 5:32 am    Post subject:
Reply with quote

Elixir wrote:
I am using Batch COBOL program to attain this objective.

VSAM Input File

KEY(1st 5 Characters)
NON KEY(Last 7 Characters)

Key 1 AAAAAA
Key 2 BBBBBB
Key 3 CCCCCC
Key 4 DDDDDD
Key 5 EEEEEE

I am getting data from another flat file, it contains Key fields. I read the key fields 1 by 1 from the flat file.

If Key 1 then write to o/p Key1 AAAAAA BBBBBB

If Key 2 then write to o/p Key2 BBBBBB CCCCCC

If Key 3 then write to o/p Key3 CCCCCC DDDDDD

If Key 4 then write to o/p Key4 DDDDDD EEEEEE

If Key 5 then write to o/p Key5 EEEEEE AAAAAA

The reason to me ask How to Read previous record in VSAM file is, if the flat file contains Key 5, then I need to get the non-key Value from Key 1 record.

The output is a Flat file only

Thanks!


If you are saying that the first non-key portion of your first record written has to be the second non-key portion of the last record written, why don't you just save it in working-storage when you do the first read?

If this doesn't make sense, please show your flat "driver" file and a representative sample of the VSAM file and the output required from that combination.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Wed Mar 21, 2012 5:40 am    Post subject:
Reply with quote

Bill,

you should go thru a few of elixer's previous threads first,
before you start asking him to explain what the hell is going on in this thread.
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