MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Reading from VSAM File and Comparing record w
Goto page 1, 2  Next
 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
manojy2k
Beginner


Joined: 19 Jan 2003
Posts: 6
Topics: 3
Location: India

PostPosted: Fri Feb 07, 2003 8:53 am    Post subject: Reading from VSAM File and Comparing record w Reply with quote

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
View user's profile Send private message Send e-mail Yahoo Messenger
satjag
Beginner


Joined: 19 Dec 2002
Posts: 19
Topics: 2

PostPosted: Fri Feb 07, 2003 9:35 am    Post subject: Reply with quote

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
View user's profile Send private message
DaveyC
Moderator


Joined: 02 Dec 2002
Posts: 151
Topics: 3
Location: Perth, Western Australia

PostPosted: Fri Feb 07, 2003 9:55 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
santosh_kumar
Beginner


Joined: 04 Feb 2003
Posts: 8
Topics: 1

PostPosted: Fri Feb 07, 2003 11:27 am    Post subject: Reply with quote

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
View user's profile Send private message
Venkata Ramana Reddy
Beginner


Joined: 02 Dec 2002
Posts: 70
Topics: 19
Location: California

PostPosted: Fri Feb 07, 2003 11:29 am    Post subject: Reply with quote

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
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12370
Topics: 75
Location: San Jose

PostPosted: Fri Feb 07, 2003 3:45 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
manojy2k
Beginner


Joined: 19 Jan 2003
Posts: 6
Topics: 3
Location: India

PostPosted: Sat Feb 08, 2003 4:45 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Yahoo Messenger
Mervyn
Moderator


Joined: 02 Dec 2002
Posts: 415
Topics: 6
Location: Hove, England

PostPosted: Sat Feb 08, 2003 6:51 am    Post subject: Reply with quote

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
View user's profile Send private message
DaveyC
Moderator


Joined: 02 Dec 2002
Posts: 151
Topics: 3
Location: Perth, Western Australia

PostPosted: Sat Feb 08, 2003 9:20 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Mervyn
Moderator


Joined: 02 Dec 2002
Posts: 415
Topics: 6
Location: Hove, England

PostPosted: Sat Feb 08, 2003 3:31 pm    Post subject: Reply with quote

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
View user's profile Send private message
DaveyC
Moderator


Joined: 02 Dec 2002
Posts: 151
Topics: 3
Location: Perth, Western Australia

PostPosted: Sun Feb 09, 2003 11:53 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Abhi
Beginner


Joined: 03 Dec 2002
Posts: 21
Topics: 4
Location: India, Pune

PostPosted: Mon Feb 10, 2003 5:39 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
DaveyC
Moderator


Joined: 02 Dec 2002
Posts: 151
Topics: 3
Location: Perth, Western Australia

PostPosted: Mon Feb 10, 2003 10:16 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Mervyn
Moderator


Joined: 02 Dec 2002
Posts: 415
Topics: 6
Location: Hove, England

PostPosted: Mon Feb 10, 2003 5:19 pm    Post subject: Reply with quote

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
View user's profile Send private message
manojy2k
Beginner


Joined: 19 Jan 2003
Posts: 6
Topics: 3
Location: India

PostPosted: Tue Feb 11, 2003 3:08 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group