Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Forum Index
 
Register
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Compare two files logic in COBOL

 
Post new topic   This topic is locked: you cannot edit posts or make replies.    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Nishant Singhal

New User


Joined: 29 Sep 2015
Posts: 2
Location: INDIA

PostPosted: Sun Aug 25, 2019 2:25 am    Post subject: Compare two files logic in COBOL
Reply with quote

Hi All,

I want to compare two sorted input files on the basis of key and need all matched and unmatched values in single output file. I have already written the code but my code is not giving expected results if number of records in input file are not same (record count may differ in any of the input file or it could be same also). I searched the forum (checked sticky notes also) before posting this query but couldn't find any solution(Pls refer the link if same query has already been discussed in past). Looking forward to your suggestions/input. Thanks!

Eg:
Input Files (Number of records are not same):
File1
1
2
3
5
7
8

File2
1
2
4
5
6


Expected Output File:
1
2
3
4
5
6
7
8

Code:

Code:


FILE SECTION.                         
FD  IN-FILE1.                         
01  IN-FILE1-REC.                     
     10 KEY-FILE1      PIC 9(1).
FD  IN-FILE2.                         
01  IN-FILE2-REC.                     
     10 KEY-FILE2      PIC 9(1).
FD  OUT-FILE3.                         
01  OUT-FILE3-REC.                     
     10 KEY-FILE3      PIC 9(1).

WORKING-STORAGE SECTION.                               
01  WS-SCRATCH-PAD.                                     
    05  WS-FILE1-EOF-FLG          PIC X(1) VALUE SPACE.
        88 WS-FILE1-SOF           VALUE 'N'.           
        88 WS-FILE1-EOF           VALUE 'Y'.           
    05  WS-FILE2-EOF-FLG          PIC X(1) VALUE SPACE.
        88  WS-FILE2-SOF          VALUE 'N'.           
        88  WS-FILE2-EOF          VALUE 'Y'.           
                                                       
PROCEDURE DIVISION.                                 
                                                     
 0000-BEGIN.                                         
     PERFORM 1000-INIT                               
     PERFORM 2000-PROCESS   THRU 2000-EXIT           
       UNTIL WS-FILE1-EOF OR  WS-FILE2-EOF           
     PERFORM 3000-TERMINATE THRU 3000-EXIT           
     GOBACK.                                         
                                                     
 1000-INIT.                                           
     OPEN INPUT  IN-FILE1                             
                 IN-FILE2                             
     OPEN OUTPUT OUT-FILE3                           
     PERFORM READ-FILE1                               
     PERFORM READ-FILE2.                             
****************************************************
 2000-PROCESS.                                   
      IF KEY-FILE1 = KEY-FILE2                   
          MOVE IN-FILE1-REC TO OUT-FILE3-REC     
          WRITE OUT-FILE3-REC                   
          PERFORM READ-FILE1                     
          PERFORM READ-FILE2                     
      ELSE                                       
                                                 
         IF KEY-FILE1 < KEY-FILE2               
          MOVE IN-FILE1-REC TO OUT-FILE3-REC     
          WRITE OUT-FILE3-REC                   
          PERFORM READ-FILE1                     
          PERFORM WRITE-FILE2                   
                                                 
         ELSE                                   
                                                 
          MOVE IN-FILE2-REC TO OUT-FILE3-REC       
          WRITE OUT-FILE3-REC                       
          PERFORM READ-FILE2                       
          PERFORM WRITE-FILE1                       
        END-IF                                     
      END-IF.                                       
****************************************************
 2000-EXIT.                                         
      EXIT.                                         
****************************************************
 READ-FILE1.                                       
     READ IN-FILE1                                 
        AT END                                     
          DISPLAY 'FILE1 FILE IS EMPTY'             
           SET WS-FILE1-EOF    TO TRUE             
     END-READ.                                                                         
****************************************************
 READ-FILE2.                                         
     READ IN-FILE2                                   
       AT END                                       
         DISPLAY 'FILE2 FILE IS EMPTY'               
         SET WS-FILE2-EOF    TO TRUE                 
     END-READ.                                       
****************************************************
 WRITE-FILE1.                                       
       IF WS-FILE2-EOF                               
          MOVE IN-FILE1-REC  TO OUT-FILE3-REC       
          WRITE OUT-FILE3-REC                       
       END-IF. 
**************************************************** 
 WRITE-FILE2.                                       
       IF WS-FILE1-EOF                               
          MOVE IN-FILE2-REC TO OUT-FILE3-REC         
          WRITE OUT-FILE3-REC                             
       END-IF.                                           
*****************************************************
 3000-TERMINATE.                                         
     CLOSE IN-FILE2                                       
               IN-FILE1                                       
               OUT-FILE3                                     
 3000-EXIT.                                               
     EXIT.                                                 
[/code]
Back to top
View user's profile Send private message

prino

Senior Member


Joined: 07 Feb 2009
Posts: 1165
Location: Vilnius, Lithuania

PostPosted: Sun Aug 25, 2019 3:20 am    Post subject:
Reply with quote

You've been on this forum for nearly four years, so logically it follows that you've been working in IT for the same time, you call yourself an analyst, yet you're too incompetent to adapt all of the code on this forum that deals with this issue?

WT(H/F) have you been doing those four years?
Back to top
View user's profile Send private message
enrico-sorichetti

Senior Member


Joined: 14 Mar 2007
Posts: 10632
Location: italy

PostPosted: Sun Aug 25, 2019 5:12 am    Post subject: Reply to: Compare two files logic in COBOL
Reply with quote

http://ibmmainframes.com/viewtopic.php?t=22649

http://www.ibmmainframeforum.com/ibm-cobol/file-match-merge-sample-code-t881.html
Back to top
View user's profile Send private message
Nishant Singhal

New User


Joined: 29 Sep 2015
Posts: 2
Location: INDIA

PostPosted: Sun Aug 25, 2019 11:20 am    Post subject:
Reply with quote

prino wrote:

WT(H/F) have you been doing those four years?


Please be respectful to others if you do not know anything about them.

Yes I joined this forum long back but it doesnt mean I am working on Mainframe only for these many years. You have no idea how these IT companies works in India. You have been asked to work on anything except your expertise.


Cheers!
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2249
Location: Hampshire, UK

PostPosted: Sun Aug 25, 2019 2:57 pm    Post subject: Reply to: Compare two files logic in COBOL
Reply with quote

In any case - you should know not to post on multiple forums at the same time.
Locked.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   This topic is locked: you cannot edit posts or make replies.    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 Substring for 2 files in Sort JCL Shubhendu Chakraborty DFSORT/ICETOOL 1 Wed Nov 20, 2019 11:07 am
No new posts Substring for 2 files in Sort JCL Shubhendu Chakraborty SYNCSORT 5 Wed Nov 20, 2019 11:04 am
No new posts File compare, where file has header a... VINAY PALLELA SYNCSORT 8 Thu Nov 07, 2019 5:05 pm
No new posts adrdssu tool to dump a files from a PDS Kannan Ramalingam JCL & VSAM 5 Fri Nov 01, 2019 6:25 pm
No new posts COBOL -DB2 SQL code to have GROUP BY ... vinu78 DB2 21 Wed Oct 23, 2019 7:00 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us