View previous topic :: View next topic |
Author |
Message |
manojy2k Beginner
Joined: 19 Jan 2003 Posts: 6 Topics: 3 Location: India
|
Posted: Fri Feb 07, 2003 8:53 am Post subject: Reading from VSAM File and Comparing record w |
|
|
Hi,
I am reading records sequentially from a VSAM KSDS File and finding a match in the sequential file. If there is no matching record in the sequential file I am displaying a error message in the job output.
In the cobol program , for each record of VSAM File, I am opening and closing the seq. file . Though it is working fine, I am thinking am I doing right by each time opening & closing this seq. file for each record of VSAM file ?
If I don't do it then it's abending with File-status 46 .
To clarify more here is in detail...
Let's say I am reading the first record from the VSAM file and need to find a match in the seq. file because we don't know at what particular position this matching record will be there ...if it won't be there then display a error message...
If matching found then do other processing. now for the first record let's say there is no match, so it read seq. file from top till end of the file.
now for the 2nd record of vsam file again the seq. file has to be started from the begining isn't it ? Here If I don't open & close the seq. file the problem is the pointer is at last record hence so getting abend...
If anybody has faced similar problem or anybody has any alternate solution , I will appriciate for the suggesation.
Looking forward for a response. A very good site well done Kolusu!!!
Thanks,
Manoj.
manojy2k@yahoo.com |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
satjag Beginner
![](images/avatars/gallery/cartoons/WB88.gif)
Joined: 19 Dec 2002 Posts: 19 Topics: 2
|
Posted: Fri Feb 07, 2003 9:35 am Post subject: |
|
|
Hello ,
Are you comparing the key fields of the VSAM file with corresponding fields in the sequential file ? If this is the case and if your sequential file will not have duplicate values in these fields, then you can convert the seqeuntial file in to a VSAM file and do random reads.
The file status 46 happens when you try to read a file beyond the end of the file. _________________ Regards,
satjag |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
DaveyC Moderator
![](images/avatars/gallery/starwars/swars041.gif)
Joined: 02 Dec 2002 Posts: 151 Topics: 3 Location: Perth, Western Australia
|
Posted: Fri Feb 07, 2003 9:55 am Post subject: |
|
|
This sounds crazy, the overhead of opening and closing and searching a sequential file for every KSDS record is madness!
You have a major design flaw. How big is the sequential file ?
You have to design a process where the sequential file is buffered in-storage where you can look-up the values quickly. Otherwise, copy it to another VSAM file to do the compares. _________________ Dave Crayford |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
santosh_kumar Beginner
Joined: 04 Feb 2003 Posts: 8 Topics: 1
|
Posted: Fri Feb 07, 2003 11:27 am Post subject: |
|
|
Much simpler way is to sort the sequential file (on the key u compare with vsam file) and then do the search as follows:
1.Read VSAM key.
2.Compare the VSAM key with the sequential(sort) key.
If VSAM Key = Seq key
Do ur activity.
Advance both the sequential file and VSAM file.(and check for duplicates in sequential file)
Else if VSAM > Seq (sort) key
Advance Seq file.
Else if VSAM key < Seq (sort) Key
Advance VSAM file.
Repeat the process until one of the file ends.
This way u need to open and close the sequential file only once.
Hope this helps.
(Check for duplicate (sort)key values in the Seqfile).
Regards,Santosh |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Venkata Ramana Reddy Beginner
![](images/avatars/gallery/members/VenkataRamanaReddy.jpg)
Joined: 02 Dec 2002 Posts: 70 Topics: 19 Location: California
|
Posted: Fri Feb 07, 2003 11:29 am Post subject: |
|
|
Manoj,
1) Will there be any duplicates in your sequential file ?
2) Do you Easytrieve in your shop ? _________________ Venkataramana
-- Good judgement comes from experience, and often experience comes from bad judgement. |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
kolusu Site Admin
![Site Admin Site Admin](images/ranks/adminpic.jpg)
Joined: 26 Nov 2002 Posts: 12370 Topics: 75 Location: San Jose
|
Posted: Fri Feb 07, 2003 3:45 pm Post subject: |
|
|
Manoj,
The method suggested by santhosh kumar is an ideal method for file comparision. But the only and must pre requiste of that method is you need to have both the files SORTED on the key. If the vsam file is not sorted , then you may need to sort the sequential file and load into an internal table and do a SEARCH ALL for every vsam key read.
Hope this helps...
cheers
kolusu |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
manojy2k Beginner
Joined: 19 Jan 2003 Posts: 6 Topics: 3 Location: India
|
Posted: Sat Feb 08, 2003 4:45 am Post subject: |
|
|
santosh & Kolusu,
The main problem of this seq. file is that the values will be provided by the business people from time to time and it's the client's requirement is that the file should be seq. .
Kolusu, you suggested me about the internal table , but I don't have any idea abut the number of records in the seq. file. can I declare a dynamic table in cobol programming where the size will depend upon the no. of records of this seq. file.
Santosh you suggested me that comparing the keys and to sort the seq. file . I would like to mention that in the vsam file the key length is X(5) and the vsam file key structure is like this
Code: |
01 vsam-key.
05 state-code pic 9.
05 lending-type pic 9.
05 interest-grp pic 9.
05 interest-catg pic x(2).
|
where is in my seq. file I have to check based on only interest-grp and interest-catg only. so I think this option will not work out.
Dave even your suggesation will not workout in this case. |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Mervyn Moderator
![](images/avatars/gallery/members/merv.jpg)
Joined: 02 Dec 2002 Posts: 415 Topics: 6 Location: Hove, England
|
Posted: Sat Feb 08, 2003 6:51 am Post subject: |
|
|
I'm still in favour of Santosh's method, you just need to sort the VSAM file as well. You will probably end up comparing two temporary files, but that's not a problem if your only output is an error message.
Cheers,
Merv _________________ The day you stop learning the dinosaur becomes extinct |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
DaveyC Moderator
![](images/avatars/gallery/starwars/swars041.gif)
Joined: 02 Dec 2002 Posts: 151 Topics: 3 Location: Perth, Western Australia
|
Posted: Sat Feb 08, 2003 9:20 am Post subject: |
|
|
My prefered method will fall on deaf ears. I would read the sequential file into memory (using Santosh's test method) in the form of a skip list. Then I wouldn't have to worry about the maximum size of an array and would have the same worst case lookup performance as a binary search... also, no need to sort the sequential file. _________________ Dave Crayford |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Mervyn Moderator
![](images/avatars/gallery/members/merv.jpg)
Joined: 02 Dec 2002 Posts: 415 Topics: 6 Location: Hove, England
|
Posted: Sat Feb 08, 2003 3:31 pm Post subject: |
|
|
Dave, just to show I'm not deaf, I've downloaded and printed William Pugh's paper on Skip Lists from ftp://ftp.cs.umd.edu/pub/skipLists/skiplists.pdf
It looks a lot of fun, but I can't help feeling I could code the above solution quicker!
Cheers,
Merv _________________ The day you stop learning the dinosaur becomes extinct |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
DaveyC Moderator
![](images/avatars/gallery/starwars/swars041.gif)
Joined: 02 Dec 2002 Posts: 151 Topics: 3 Location: Perth, Western Australia
|
Posted: Sun Feb 09, 2003 11:53 pm Post subject: |
|
|
Merv,
I would be interested to see your quicker solution. (Do you mean you can code a solution quicker or make it run quicker ?)
SkipLists are my fav data structure at the moment. Quick as a binary search and a snip to code. Doug Nadel gave me a good tip about sorting linked lists (ISPF tables are copied to an AVL tree and then back again). I've used this method using SkipLists instead of AVL trees and it's works great. _________________ Dave Crayford |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Abhi Beginner
![](images/avatars/gallery/cartoons/WB116.gif)
Joined: 03 Dec 2002 Posts: 21 Topics: 4 Location: India, Pune
|
Posted: Mon Feb 10, 2003 5:39 am Post subject: |
|
|
This is just a suggestion. I am not sure Manoj if this works in ur case. Just wanted u to have another opinion.
Can u read the Sequential file first and then build the VSAM file key with which do a random read on the VSAM file?
Now, I realize that the key for comparison is only the last 2 fields of the VSAM file key i.e.
Code: | 05 interest-grp pic 9.
05 interest-catg pic x(2). |
But since...
Code: | 05 state-code pic 9.
05 lending-type pic 9. |
appear before ur comparison key there is a chance that the same INTEREST-GRP & INTEREST-CATG can occur for some other State code. So, I would guess that u have some sort of logic that breaks up "activity/processing" depending on the State which would enable u to build a key for the VSAM file. |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
DaveyC Moderator
![](images/avatars/gallery/starwars/swars041.gif)
Joined: 02 Dec 2002 Posts: 151 Topics: 3 Location: Perth, Western Australia
|
Posted: Mon Feb 10, 2003 10:16 am Post subject: |
|
|
manojy2k,
Abhi has a good point. Why can't you read the sequential file and use the VSAM file for lookups? You can create an alternate index on the KSDS for the alternate key.
Unless the sequential file is massive, it must the best solution. _________________ Dave Crayford |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
Mervyn Moderator
![](images/avatars/gallery/members/merv.jpg)
Joined: 02 Dec 2002 Posts: 415 Topics: 6 Location: Hove, England
|
Posted: Mon Feb 10, 2003 5:19 pm Post subject: |
|
|
Dave, I was only talking about coding time. I'm sure the second such program would be quite a bit quicker to code than the first, but right now I wouldn't have the time to give it the thought necessary. I can code a couple of sorts and a simple file match in about fifteen minutes.
The theory looks great, and I've used linked lists before with success. I'll give it a try when I get a break from shovelling stupendous volumes of data into a warehouse and can think about proper programming again! Have you developed a Cobol solution, or are we talking C here? That could be a major problem for many of us.
Cheers,
Merv _________________ The day you stop learning the dinosaur becomes extinct |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
manojy2k Beginner
Joined: 19 Jan 2003 Posts: 6 Topics: 3 Location: India
|
Posted: Tue Feb 11, 2003 3:08 am Post subject: |
|
|
abhi,
For me there is no need to create the vsam file or creating a alternate index for the vsam file as the file is already existing and I should not alter this vsam file.
I will paste the cobol source code some time later so that all we have a clear idea about this problem.
Thanks,
Manoj. |
|
Back to top |
|
![](templates/subSilver/images/spacer.gif) |
|
|