Reading from VSAM File and Comparing record w
Select messages from
# through # FAQ
[/[Print]\]
Goto page 1, 2  Next  :| |:
MVSFORUMS.com -> Application Programming

#1: Reading from VSAM File and Comparing record w Author: manojy2kLocation: India PostPosted: Fri Feb 07, 2003 8:53 am
    —
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

#2:  Author: satjag PostPosted: Fri Feb 07, 2003 9:35 am
    —
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.

#3:  Author: DaveyCLocation: Perth, Western Australia PostPosted: Fri Feb 07, 2003 9:55 am
    —
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.

#4:  Author: santosh_kumar PostPosted: Fri Feb 07, 2003 11:27 am
    —
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

#5:  Author: Venkata Ramana ReddyLocation: California PostPosted: Fri Feb 07, 2003 11:29 am
    —
Manoj,

1) Will there be any duplicates in your sequential file ?
2) Do you Easytrieve in your shop ?

#6:  Author: kolusuLocation: San Jose PostPosted: Fri Feb 07, 2003 3:45 pm
    —
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

#7:  Author: manojy2kLocation: India PostPosted: Sat Feb 08, 2003 4:45 am
    —
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.

#8:  Author: MervynLocation: Hove, England PostPosted: Sat Feb 08, 2003 6:51 am
    —
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

#9:  Author: DaveyCLocation: Perth, Western Australia PostPosted: Sat Feb 08, 2003 9:20 am
    —
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.

#10:  Author: MervynLocation: Hove, England PostPosted: Sat Feb 08, 2003 3:31 pm
    —
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

#11:  Author: DaveyCLocation: Perth, Western Australia PostPosted: Sun Feb 09, 2003 11:53 pm
    —
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.

#12:  Author: AbhiLocation: India, Pune PostPosted: Mon Feb 10, 2003 5:39 am
    —
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.

#13:  Author: DaveyCLocation: Perth, Western Australia PostPosted: Mon Feb 10, 2003 10:16 am
    —
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.

#14:  Author: MervynLocation: Hove, England PostPosted: Mon Feb 10, 2003 5:19 pm
    —
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

#15:  Author: manojy2kLocation: India PostPosted: Tue Feb 11, 2003 3:08 am
    —
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.



MVSFORUMS.com -> Application Programming


output generated using printer-friendly topic mod. All times are GMT - 5 Hours

Goto page 1, 2  Next  :| |:
Page 1 of 2

Powered by phpBB © 2001, 2005 phpBB Group