View previous topic :: View next topic
|
Author |
Message |
vinu
New User
Joined: 03 Jul 2005 Posts: 9
|
|
|
|
Hi All,
I have 2 seq. files (PS) file 1 and file 2.
for every record in file 1 I have to scan file 2 for a match. I write the output to different files based on the match.
now, when i tried this, I get S0000 U4038 abend. I find from sysout that problem occurs when I am reading file 2 for the second record from file 1.
The file 2 has already reached 'at end' and I want to know how to reset this for every read.
Please help ( If possible, a sample code)
thanks,
vinu |
|
Back to top |
|
|
shobam
New User
Joined: 18 Jul 2005 Posts: 34 Location: CN
|
|
|
|
If both the files are in sorted order based on the same key , you can restrict the number of reads using KEY_OF_FILE1 >= KEY_OF_FILE2. This avoids closing and opening the file2 for each and every record from FILE1.
And to check whether the FILE2 has reached the EOF use as usual
READ
AT END SET EOF_FILE2 TO TRUE
NOT AT END < some condition check>
END-READ.
EOF_FILE2 is an 88 level variable. Check whether this variable is set to true to find whether the FILE2 has reached its end or not.
Hope I am clear. |
|
Back to top |
|
|
SHIVAREDDY
New User
Joined: 25 Jul 2005 Posts: 20
|
|
|
|
Hi,
This solution would be simple I suppose.Use START statement to position the file pointer for the 2cnd file before u issue a READ statement.Thats important.
Here are some important points to follow and START stmt syntax.
START
Enables the positioning of the pointer at a specific point in an indexed or relative file
File should be opened in Input or I-O mode
Access mode must be Sequential or Dynamic
Does not read the record
Invalid Key arises if the record position is empty.
When KEY phrase is not specified KEY EQUAL TO primary key is implied.
File position indicator points to the first record in the file whose key field satisfies the comparison.
SYNTAX
START file-name
[ KEY IS { EQUAL TO data-name]
=
GREATER THAN
>
NOT LESS THAN
NOT < THAN }
[ INVALID KEY imperative-stmt-1 ]
[ NOT INVALID KEY imperative-stmt-2 ]
[ END-START ]
Follow above and that may solve ur problem.Reply whether ur problem is solved or not.bye. cheers |
|
Back to top |
|
|
surya
New User
Joined: 19 Feb 2005 Posts: 13
|
|
|
|
Hi shobam,
Can you explain clearly with some example, it will be useful for me. |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
Back to top |
|
|
manjithota
New User
Joined: 09 Jun 2005 Posts: 10
|
|
|
|
hi vinu,
shovam is quite right. it would be foolish to read one record and match a whole file for that n situations are even more worse when ur 2nd file is very large. so do sort the second file first acoording to ur requirement.
it will save a lot of resoures.
plz don't go the way u r following now. change the strategy.
thanking
manjit |
|
Back to top |
|
|
vinu
New User
Joined: 03 Jul 2005 Posts: 9
|
|
|
|
thanks shobam,manjithota, mmwife,
let me put the quest this way; I hav 2 huge file 1,2 & i sort them based on the key and then scan.
in this case a match is likely to come early. but, how i stop reading as soon as a match is found and go for the next scan?
vinu |
|
Back to top |
|
|
shivashunmugam Muthu
Active User
Joined: 22 Jul 2005 Posts: 114 Location: Chennai
|
|
|
|
Hi
File comparison logic is the best option.
Prerequistes
both file shd be sorted on same key either asc or desc. read one by one seq & look for key match......
jus look @ this
ibmmainframes.com/viewtopic.php?t=4540
change the logic..as match found write outfile...i feel performance wise its good...
correct me if i am wrong |
|
Back to top |
|
|
shobam
New User
Joined: 18 Jul 2005 Posts: 34 Location: CN
|
|
|
|
PERFORM 1000-READ-FILE1 UNTIL EOF-FILE1.
1000-READ-FILE1.
READ FILE1
AT END
SET EOF-FILE1 TO TRUE
NOT AT END
PERFORM 2000-READ-FILE2 UNTIL EOF-FILE2 OR FILE1-KEY >= FILE2-KEY
END-READ.
IF FILE1-KEY = FILE2-KEY
< MATCH FOUND>
ELSE IF FILE1-KEY > FILE2-KEY
<MATCH NOT FOUND>
ELSE
< MEANS EOF FILE2 IS REACHED. THEN READ THE FILE1 TILL END AND DO THE LOGIC YOU DO WHEN A MATCH IS NOT FOUND>
END-IF
2000-READ-FILE2.
READ FILE2
AT END
SET EOF-FILE2 TO TRUE
END-READ.
Humans are prone to Error. Please correct me if I am wrong. |
|
Back to top |
|
|
rskumar
New User
Joined: 21 Nov 2005 Posts: 35 Location: chennai
|
|
|
|
shobam.. i tried with your idea.
But if File-1 has 'M' records and File-2 has 'M+1' records, and the matching records count in File-1 and 2 is 'N' where N<M+1 and also the last record of File-2 does not have a match in File-1, then the program goes into a loop and File-1 does not reach EOF at all. The last record value of File-1 and File-2 are keep on being compared and the control does not comes back to read-para.
Hope I am clear. |
|
Back to top |
|
|
|