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

How to read a previous record VSAM KSDS file?


IBM Mainframe Forums -> JCL & VSAM
Post new topic   Reply to topic
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
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
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
Reply with quote

In Batch..if possible
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 Mar 20, 2012 5:05 am
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Tue Mar 20, 2012 5:16 am
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
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

Moderator Emeritus


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

PostPosted: Tue Mar 20, 2012 12:14 pm
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
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

Moderator Emeritus


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

PostPosted: Tue Mar 20, 2012 7:33 pm
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
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
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
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
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
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
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

Moderator Emeritus


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

PostPosted: Wed Mar 21, 2012 5:32 am
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
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 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