View previous topic :: View next topic
|
Author |
Message |
Elixir
Active User
Joined: 08 Feb 2009 Posts: 116 Location: CHENNAI/NEW JERSEY - INDIA/USA
|
|
|
|
Hi,
Please let me know How to read a previous record VSAM KSDS file. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
in CICS or Batch? |
|
Back to top |
|
|
Elixir
Active User
Joined: 08 Feb 2009 Posts: 116 Location: CHENNAI/NEW JERSEY - INDIA/USA
|
|
|
|
In Batch..if possible |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
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 |
|
|
Elixir
Active User
Joined: 08 Feb 2009 Posts: 116 Location: CHENNAI/NEW JERSEY - INDIA/USA
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Elixir
Active User
Joined: 08 Feb 2009 Posts: 116 Location: CHENNAI/NEW JERSEY - INDIA/USA
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
How about next time forget the colours, and use the Code tags. please? |
|
Back to top |
|
|
Elixir
Active User
Joined: 08 Feb 2009 Posts: 116 Location: CHENNAI/NEW JERSEY - INDIA/USA
|
|
|
|
what code tags bill? |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Elixir
Active User
Joined: 08 Feb 2009 Posts: 116 Location: CHENNAI/NEW JERSEY - INDIA/USA
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Elixir,
you were too busy posting code with the quote tag instead of code tag.
look at my previous post. |
|
Back to top |
|
|
Elixir
Active User
Joined: 08 Feb 2009 Posts: 116 Location: CHENNAI/NEW JERSEY - INDIA/USA
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
|