Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

file 1 & file 2 issue (file handling in COBOL)

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
vinu

New User


Joined: 03 Jul 2005
Posts: 9

PostPosted: Mon Aug 01, 2005 10:57 am    Post subject: file 1 & file 2 issue (file handling in COBOL)
Reply with quote

Hi All,
icon_smile.gif
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
View user's profile Send private message

shobam

New User


Joined: 18 Jul 2005
Posts: 34
Location: CN

PostPosted: Mon Aug 01, 2005 2:40 pm    Post subject:
Reply with quote

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

New User


Joined: 25 Jul 2005
Posts: 20

PostPosted: Mon Aug 01, 2005 4:01 pm    Post subject: Re: file 1 & file 2 issue (file handling in COBOL)
Reply with quote

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. icon_biggrin.gif cheers
Back to top
View user's profile Send private message
surya

New User


Joined: 19 Feb 2005
Posts: 13

PostPosted: Mon Aug 01, 2005 9:28 pm    Post subject: Re: file 1 & file 2 issue (file handling in COBOL)
Reply with quote

Hi shobam,
Can you explain clearly with some example, it will be useful for me.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Tue Aug 02, 2005 5:48 am    Post subject:
Reply with quote

This is a classic example of a file match algorithm, one of the 2 most used in batch programming.

Just sort the files as Shobam suggests and see program-id xxxx in the link below.

http://ibmmainframes.com/viewtopic.php?t=4340&highlight=file+match
Back to top
View user's profile Send private message
manjithota

New User


Joined: 09 Jun 2005
Posts: 10

PostPosted: Wed Aug 03, 2005 2:36 pm    Post subject:
Reply with quote

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

New User


Joined: 03 Jul 2005
Posts: 9

PostPosted: Wed Aug 03, 2005 2:55 pm    Post subject:
Reply with quote

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

Active User


Joined: 22 Jul 2005
Posts: 114
Location: Chennai

PostPosted: Wed Aug 03, 2005 5:19 pm    Post subject: Re: file 1 & file 2 issue (file handling in COBOL)
Reply with quote

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

http://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
View user's profile Send private message
shobam

New User


Joined: 18 Jul 2005
Posts: 34
Location: CN

PostPosted: Wed Aug 03, 2005 5:40 pm    Post subject:
Reply with quote

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

New User


Joined: 21 Nov 2005
Posts: 35
Location: chennai

PostPosted: Wed Jul 02, 2008 8:04 pm    Post subject:
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Converting Variable block file to Fix... bhavana yalavarthi DFSORT/ICETOOL 10 Tue May 16, 2017 2:20 pm
This topic is locked: you cannot edit posts or make replies. Cobol GUI (like Editor) Kala Mainframe COBOL Programming 14 Wed May 10, 2017 12:30 pm
No new posts IMS T-Pipe queue counts in a COBOL Pr... Siva NKK Kothamasu IMS DB/DC 0 Tue May 09, 2017 6:31 pm
No new posts Getting error while opening a variabl... apandey1 COBOL Programming 5 Fri May 05, 2017 12:22 pm
No new posts Issue with NDM process to transmit ES... chetanambi All Other Mainframe Topics 6 Wed May 03, 2017 10:52 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us