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 Matching Logic in cobol

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

New User


Joined: 20 May 2007
Posts: 7
Location: Mumbai

PostPosted: Sat Jun 16, 2007 1:13 am    Post subject: File Matching Logic in cobol
Reply with quote

I have 3 files . 2 files have millions of records.These 2 files have one ( empnumber) common record field. i want to put those records in 3rd file , such that which records having same number in key field (empnumber)in these two files ?


How will you write a logic for this in cobol?

One way is:

Read file1 until EOF1 or EOF2
Read File2 Until EOF2 or File1-Key >File2-key
If File1-key = File2-key
Write .....
End-If
End-Read
End-Read.


But READ stmt dont have UNTIL.
So it is to be done thru PERFORM stmt.
Can anyone write a full logic in cobol? (Dont suggest ICETOOL)


Savvy
Back to top
View user's profile Send private message

expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Sat Jun 16, 2007 1:19 am    Post subject:
Reply with quote

Why use cobol when sort can do this for you ?
Back to top
View user's profile Send private message
Devzee

Active Member


Joined: 20 Jan 2007
Posts: 684
Location: Hollywood

PostPosted: Sat Jun 16, 2007 3:53 am    Post subject:
Reply with quote

See if below posts can help you...

http://www.ibmmainframes.com/viewtopic.php?t=21803
http://www.ibmmainframes.com/viewtopic.php?t=21299
http://www.ibmmainframes.com/viewtopic.php?t=19416
http://www.ibmmainframes.com/viewtopic.php?t=16924
http://www.ibmmainframes.com/viewtopic.php?t=9015
http://www.ibmmainframes.com/viewtopic.php?t=5248
Back to top
View user's profile Send private message
mandator10

New User


Joined: 20 May 2007
Posts: 7
Location: Mumbai

PostPosted: Fri Jun 22, 2007 9:19 pm    Post subject: Their requirement is to write the logic in cobol
Reply with quote

Hi expat,
Several approaches are there. But their requirement is to write the logic in cobol. I strucked up. That is why i asked the question here.

Savvy
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Fri Jun 22, 2007 9:33 pm    Post subject:
Reply with quote

Hello,

A couple of days ago i posted code that basically does what you need.

Look in COBOL for a recent topic about comparing/matching (i forget which) files that has an attachment.
Back to top
View user's profile Send private message
krisprems

Active Member


Joined: 27 Nov 2006
Posts: 649
Location: India

PostPosted: Fri Jun 22, 2007 10:46 pm    Post subject:
Reply with quote

mandator10
Check this code, where FILE1 is 1st i/p file, and IE is 2nd I/p file.
OP is O/p file
Code:
       PROCEDURE DIVISION.                                                     
           PERFORM 100-OPEN-PARA.                                               
           PERFORM 200-READ-PARA.                                               
           PERFORM 250-COMP-PARA UNTIL EOF-IE = 'Y' OR EOF-FILE1 = 'Y'.         
           PERFORM 900-CLOSE-PARA.                                             
       100-OPEN-PARA.                                                           
           OPEN OUTPUT OP.                                                     
           OPEN INPUT FILE1 IE.                                                 
                                                                               
       200-READ-PARA.                                                           
           READ IE AT END MOVE 'Y' TO EOF-IE.                                   
           READ FILE1 AT END MOVE 'Y' TO EOF-FILE1.                             
       250-COMP-PARA.                                                           
           IF(EMP-NUM-2 = EMP-NUM-1) THEN                                       
               MOVE SPACES TO OP-REC                                           
               WRITE OP-REC FROM IE-REC                                         
               PERFORM 800-CHECK-PARA                                           
               PERFORM 200-READ-PARA                                           
           END-IF.                                                             
           IF(EMP-NUM-2 > EMP-NUM-1) THEN                                       
               MOVE SPACES TO FILE1-REC                                         
               PERFORM 800-CHECK-PARA                                           
               READ FILE1 AT END MOVE 'Y' TO EOF-FILE1                         
           END-IF.                                                             
           IF(EMP-NUM-2 < EMP-NUM-1) THEN                                       
               MOVE SPACES TO IE-REC                                           
               PERFORM 800-CHECK-PARA                                           
               READ IE    AT END MOVE 'Y' TO EOF-IE                             
           END-IF.                                                             
       800-CHECK-PARA.                                                         
           IF(EOF-FILE1 = 'Y' OR  EOF-IE = 'Y')                                 
              PERFORM  900-CLOSE-PARA                                           
           END-IF.                                                             
       900-CLOSE-PARA.                                                         
           CLOSE OP IE FILE1.                                                   
           STOP RUN.                                                           
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Sat Jun 23, 2007 12:14 am    Post subject:
Reply with quote

Hello Krisprems,

Did you test this before posting?

At a quick glance, i believe this code will not work as needed in all cases.
Back to top
View user's profile Send private message
krisprems

Active Member


Joined: 27 Nov 2006
Posts: 649
Location: India

PostPosted: Mon Jun 25, 2007 1:20 pm    Post subject:
Reply with quote

Hi dick,

The code that i have pasted is tested one, and have used it many a times.

Am too feeling that, it may not work in all cases as you said!

So, the constraint to use this code would be:
1. I/p's should be sorted.
2. I/P from one file should not have more than one matching records with second file.
Back to top
View user's profile Send private message
cvadlamudi

New User


Joined: 19 Apr 2007
Posts: 68
Location: India

PostPosted: Mon Jun 25, 2007 4:11 pm    Post subject:
Reply with quote

Hi Kris

can u please chk this

Define a flag :

ws-acct-match pic x.
match-fnd value 'y'
match-nfnd value 'n'


1)SORT SORT-FILE1 ASCENDING SORT-KEY(empnumber) USING INPUT1-FILE GIVING INP1-FILE.
2)SORT SORT-FILE2 ASCENDING SORT-KEY(empnumber) USING INPUT1-FILE GIVING INP2-FILE.


PERFORM 100-OPEN-PARA. (do same as u mention)
PERFORM 200-READ-PARA. (do same as u mention)
PERFORM 250-COMP-PARA UNTIL EOF-IE = 'Y' OR EOF-FILE1 = 'Y'.
PERFORM 900-CLOSE-PARA.

250-COMP-PARA.

EVALUATE TRUE

WHEN INPFILED1 = INPFIELD2

move 'y' to ws-acct-match
WRITE OUTREC FROM INPUT1 OR INPUT2

READ 2ND FILE at end set flag to 'Y' end-read

perform until MATCH-NFND
if INPFILED1 not = INPFIELD2
move 'N' TO ws-acct-match
end-if
end-perform

WHEN INPFILED1 < INPFIELD2
READ 1ST FILE at end set flag to 'y' end-read

WHEN INPFILED1 > INPFIELD2
READ 2ND FILE at end set flag to 'y' end-read

END-EVALUATE.


Regards,
Mouli
Back to top
View user's profile Send private message
tosaurabh20

New User


Joined: 08 Jun 2007
Posts: 26
Location: Noida

PostPosted: Mon Jun 25, 2007 4:29 pm    Post subject:
Reply with quote

krisprems wrote:
Hi dick,

The code that i have pasted is tested one, and have used it many a times.

Am too feeling that, it may not work in all cases as you said!

So, the constraint to use this code would be:
1. I/p's should be sorted.
2. I/P from one file should not have more than one matching records with second file.


Hi Krisprems,

The above two constraints can be avoided if we incorporate nested loops in the above logic.

Though it will be bit time consuming but will cover up all constraints and provide you a perfect output as desired.

Let me know in case of any issues.

Thanks and Regards
Saurabh
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Mon Jun 25, 2007 6:12 pm    Post subject:
Reply with quote

Hello,

Anything can be made more difficult than it is. . . .

Please find and review the code i posted previously (a different topic) and suggested earlier in this topic. Later this week, i'll try to make it a "sticky" or somehow get it to the "downloads" area.

There is no need to nave nested loops and convoluted logic to accomplish reading the files.

Do not do 2 sort using/givings an a program - actually, 1 using/giving is poor coding practice. . . If there is work to be done in an input or output procedure, the internal sort is often an excellent choice. To merely put some data in a sequence, the external sort is a better choice.

As was mentioned by someone earlier, if there may be duplicates in both files, that condition needs a bit of extra consideration - not because of code (if done correctly), but because of business rules. When this happens, there needs to be a clear definition of how things should be processed. Fortunately, mnost of the time, there will be duplicates in only one (or neither) input file.
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 Changing of LRECL of a file abdulrafi DFSORT/ICETOOL 1 Fri Mar 24, 2017 3:25 pm
No new posts splitting a file abdulrafi DFSORT/ICETOOL 3 Fri Mar 24, 2017 11:51 am
No new posts Receive a file using PCOMM macro Harald.v.K IBM Tools 0 Thu Mar 23, 2017 6:50 pm
No new posts Export flat file data into excel sheet murali.andaluri DFSORT/ICETOOL 2 Mon Mar 20, 2017 5:39 pm
No new posts Formatting VB File Learncoholic DFSORT/ICETOOL 3 Mon Mar 20, 2017 12:29 pm


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