Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Comaprison of files

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

New User


Joined: 08 Jul 2005
Posts: 31

PostPosted: Fri Jul 15, 2005 12:55 pm    Post subject: Comaprison of files
Reply with quote

Hello
This qtn has been asked too many times i know..but i hv ne basic doubt on this.

I have 2 files master and txn. Lets say both have enormous amt of records. I would like to write a program in cobol to write into a 3rd file thos records thats there in both master and Txn.

I've seen many response prev to such qtn to use binary search, but to my knowledge we can use search all on tables/arrays and not on files. how do we do this then ...pls help me in this regard.

Thanks in advance.
Back to top
View user's profile Send private message

priyesh.agrawal

Senior Member


Joined: 28 Mar 2005
Posts: 1452
Location: Chicago, IL

PostPosted: Fri Jul 15, 2005 8:40 pm    Post subject: Re: Comaprison of files
Reply with quote

Hi t1nt1n,

Quote:
I have 2 files master and txn. Lets say both have enormous amt of records. I would like to write a program in cobol to write into a 3rd file thos records thats there in both master and Txn.


Do you really need a COBOL Prog only....Cant you do it using JCL....

Well, Here is a code which do what you want to ....

Code:
OPEN all the THREE Files & INITIALIZE STRUCTURE.   

PERFORM PROCESSING                 
   THRU PROC-EXIT UNTIL END-INFILE-YES.
STOP RUN.

PROCESSING
MOVE ZEROES TO COUNTER.                       
CLOSE WSFILE.                             
READ INFILE INTO WS-IN-REC               
            AT END SET END-INFILE-YES TO TRUE 
                    GO TO PROC-EXIT           
END-READ.                                     
                                             
OPEN INPUT WSFILE.                       
SET END-WSFILE-NO TO TRUE.                     
PERFORM MATCH THRU MATCH-EXIT                 
             UNTIL END-WSFILE-YES.             
PROC-EXIT.

MATCH
READ WSFILE INTO WS-REC                   
            AT END SET END-WSFILE-YES TO TRUE     
                    GO TO MATCH-EXIT             
END-READ.                                         
                   
IF IN-REC = WS-REC                         
MOVE IN-REC TO OUT-REC                   
WRITE ITEM-OUTREC FROM WS-OUT-REC
MOVE SPACES TO WS-OUT-REC       
MOVE SPACES TO WS-WS-REC 
GO TO PROC-EXIT                               
CLOSE WSFILE                             
END-IF                                           
MATCH-EXIT.


Try & let us know the results.......

Regards,

Priyesh.
Back to top
View user's profile Send private message
somasundaran_k

Active User


Joined: 03 Jun 2003
Posts: 134

PostPosted: Sat Jul 16, 2005 11:20 pm    Post subject:
Reply with quote

Priyesh
I don't think this is an efficient way of coding. Especially when the original poster mentioned
Quote:

I have 2 files master and txn. Lets say both have enormous amt of records.

It seems you are opening ,reading and closing the transaction file for every master record. Don't you think this would be a perfomance issue when the transaction file have enormous amt fo records?

A better way would have been

1. Sort both the files based on the key.
2. Open all the files.
3. Read both the files.
4. Perform the match para until end of master file(or you can check for the end of file condition for both files.like eof-master OR eof-txn.depending on your requirement.
Match para:
-----------
EVALUATE TRUE
WHEN MASTER-KEY = TRANSACT-KEY
PERFORM write-match-file
PERFORM read-master-file
PERFORM read-trasaction-file
WHEN MASTER-KEY < TRANSACT-KEY
PERFORM read-master-file
WHEN MASTER-KEY > TRANSACT-KEY
PERFORM read-trasaction-file
END-EVALUATE
5. Close all the files

Regds
-Som
Back to top
View user's profile Send private message
t1nt1n

New User


Joined: 08 Jul 2005
Posts: 31

PostPosted: Wed Jul 20, 2005 12:13 pm    Post subject:
Reply with quote

Thanks Som, Priyesh.....for the replies. It helps.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sun Jul 24, 2005 10:12 pm    Post subject:
Reply with quote

Here's a real world solution.

Just ignore what you don't need.

HTH
Code:

00001  IDENTIFICATION DIVISION.
00002  PROGRAM-ID.    XXXX.
00003 *AUTHOR.        JACK SLEIGHT
00004 *DATE-WRITTEN   JANUARY  1997.
00005 *REMARKS.
00006 *
00007 *        THIS PROGRAM USES THE DAILY ACCRETION RECORDS TO ACCUM-
00008 *        ULATE MTD AND YTD ACCRETION AMOUNTS AND CREATES A NEW
00009 *        MASTER ACCRETION FILE.
00009 * NOTE!! AT NEW YEAR, A FALSE EOF ON THE MASTER FILE IS CREATED,
00009 *        DELETING ALL EXISTING MASTER RECS THEN ALL DAILY RECS
00009 *        ARE ADDED AS-IS TO THE MASTER FILE. THIS RESETS THE
00009 *        MASTER FILE FOR THE COMMING YEAR.
00010 **
00011 ******************************************************************
00012 *                           CHANGE LOG
00013 ******************************************************************
00014 *
00015 * 01/15/97 J.S. - CREATED.
00016 *
00017 ******************************************************************
00018
00019
00020  ENVIRONMENT DIVISION.
00021  INPUT-OUTPUT SECTION.
00022
00023  FILE-CONTROL.
00024      SELECT  DAILY-ACCRET-FILE-IP ASSIGN TO XXXX1.
00025      SELECT MASTER-ACCRET-FILE-IP ASSIGN TO XXXX2.
00026      SELECT MASTER-ACCRET-FILE-OP ASSIGN TO XXXX3.
00027
00028  DATA DIVISION.
00029  FILE SECTION.
00030  FD  DAILY-ACCRET-FILE-IP.
00031  01  DAILY-ACCRET-REC-IP         PIC  X(150).
00032
00033  FD  MASTER-ACCRET-FILE-IP.
00034  01  MASTER-ACCRET-REC-IP        PIC  X(150).
00035
00036  FD  MASTER-ACCRET-FILE-OP
00037      RECORD CONTAINS 150 CHARACTERS
00038      BLOCK  CONTAINS 000 RECORDS.
00039  01  MASTER-ACCRET-REC-OP        PIC  X(150).
00040
00041  WORKING-STORAGE SECTION.
00042  77  FILLER                      PIC  X(035) VALUE
00043          '****WORKING STORAGE STARTS HERE****'.
00044
00045  01  WS-DAILY-HDR.
00046  ++INCLUDE xxxx
00047  01  WS-DAILY-DTL.
00048  ++INCLUDE xxxx
00049
00050  01  WS-MASTER-HDR.
00051  ++INCLUDE xxxx
00052  01  WS-MASTER-DTL.
00053  ++INCLUDE xxxx
00054
00055  01  WS-WORK-AREAS.
00056      05  WS-INFLAT-IDX-TODAY     PIC S9(003)V9(6) COMP-3.
00057      05  WS-INFLAT-IDX-NBDAY     PIC S9(003)V9(6) COMP-3.
00058      05  WS-ACCRET-REC-CNT       PIC S9(007) VALUE +0 COMP-3.
00059      05  WS-INFLAT-IDX-PGM       PIC  X(008) VALUE 'xxxxa'.
00060
00061      05  WS-CURR-DATE-CYMD.
00062          10  WCD-CC              PIC  X(002).
00063          10  WS-CURR-DATE-YMD.
00064              15  WCD-YY          PIC  X(002).
00065              15  WCD-MM          PIC  X(002).
00066              15  WCD-DD          PIC  X(002).
00067
00068  01  WS-SWITCHES-AND-COUNTERS.
00069
00070      05  WS-BOTH-FILES-EOF.
00071          88  BOTH-FILES-EOF                       VALUE 'YY'.
00072          10  FILLER              PIC  X(001) VALUE 'N'.
00073              88  DAILY-FILE-EOF                   VALUE 'Y'.
00074          10  FILLER              PIC  X(001) VALUE 'N'.
00075              88  MASTER-FILE-EOF                  VALUE 'Y'.
00076
00077      05  FILLER                  PIC  X(001) VALUE 'A'.
00078          88  NOT-AN-ACCRET-FILE                   VALUE 'N'.
00079
00080      05  WS-DAILY-REC-CNT        PIC S9(008) VALUE +0 COMP.
00081      05  WS-NO-DAILY-CNT         PIC S9(008) VALUE +0 COMP.
00082      05  WS-MASTER-REC-CNT       PIC S9(008) VALUE +0 COMP.
00083      05  WS-NO-MASTER-CNT        PIC S9(008) VALUE +0 COMP.
00084      05  WS-MATCH-CNT            PIC S9(008) VALUE +0 COMP.
00085      05  WS-MIS-MATCH-CNT        PIC S9(008) VALUE +0 COMP.
00086
00087  01  WS-WORK-FIELDS.
00088
00089      05  WS-BOTH-COMPARE-KEYS.
00090          10  WS-DAILY-COMPARE-KEY.
00091              15  WDC-USR-CDE     PIC  X(002).
00092              15  WDC-ACCT-NBR    PIC  X(008).
00093              15  WDC-SEC-NBR     PIC  X(005).
00094
00095          10  WS-MASTER-COMPARE-KEY.
00096              15  WMC-USR-CDE     PIC  X(002).
00097              15  WMC-ACCT-NBR    PIC  X(008).
00098              15  WMC-SEC-NBR     PIC  X(005).
00099
00100      05  WS-PROJ-START-DATE      PIC  X(008) VALUE
00101          '19970126'.
00102
00103
00104  PROCEDURE DIVISION.
00105 ***************
00106  000-MAIN-LINE.
           DISPLAY 'DEBUG-  000-MAIN-LINE.'
00107 ***************
00108      PERFORM 810-DISP-MSG-AND-OPEN-FILES
00109      PERFORM 820-VERIFY-HEADERS
00110      PERFORM 830-SET-GO-NOGO
00111      PERFORM 840-CHECK-FOR-NEW-YEAR
00112      PERFORM 850-GET-CURR-DATE
00113      WRITE MASTER-ACCRET-REC-OP  FROM WS-DAILY-HDR
00114      PERFORM 200-MATCH-DAILY-MASTER-RECS
00115        UNTIL BOTH-FILES-EOF
00116      PERFORM 900-END-IT
00117      STOP RUN
00118      .
00119 *****************************
00120  200-MATCH-DAILY-MASTER-RECS.
           DISPLAY 'DEBUG-  200-MATCH-DAILY-MASTER-RECS.'
00121 *****************************
00122      EVALUATE TRUE
00123      WHEN WS-DAILY-COMPARE-KEY = WS-MASTER-COMPARE-KEY
00124           PERFORM 210-UPDATE-MASTER-REC
00125           PERFORM 700-GET-BOTH-COMPARE-KEYS THRU 700-EXIT
00126      WHEN WS-DAILY-COMPARE-KEY > WS-MASTER-COMPARE-KEY
00127 *===> I.E., NO DAILY ACCRETION RECORD
00129           PERFORM 220-REWRITE-MASTER-REC
00130           PERFORM 700-GET-MASTER-COMPARE-KEY
00131      WHEN OTHER
00132 *===> I.E., NEW DAILY ACCRETION RECORD, ADD TO MASTER FILE
00134           WRITE MASTER-ACCRET-REC-OP        FROM WS-DAILY-DTL
00135           ADD  +1                             TO WS-NO-MASTER-CNT
00136           PERFORM 700-GET-DAILY-COMPARE-KEY
00137      END-EVALUATE
00138      .
00139 ***********************
00140  210-UPDATE-MASTER-REC.
           DISPLAY 'DEBUG-  210-UPDATE-MASTER-REC.'
00141 ***********************
00142      IF NEW-MONTH  IN WS-DAILY-HDR
00143         MOVE ZEROS TO PAD-MTD-ACCRET-AMT OF WS-MASTER-DTL
00144      END-IF
00145      COMPUTE PAD-MTD-ACCRET-AMT   OF WS-DAILY-DTL
00146              =
00147              PAD-MTD-ACCRET-AMT   OF WS-MASTER-DTL
00148              +
00149              PAD-DAY-ACCRET-AMT   OF WS-DAILY-DTL
00150      COMPUTE PAD-YTD-ACCRET-AMT   OF WS-DAILY-DTL
00151              =
00152              PAD-YTD-ACCRET-AMT   OF WS-MASTER-DTL
00153              +
00154              PAD-DAY-ACCRET-AMT   OF WS-DAILY-DTL
00155      WRITE MASTER-ACCRET-REC-OP FROM WS-DAILY-DTL
00156      .
00157 ************************
00158  220-REWRITE-MASTER-REC.
           DISPLAY 'DEBUG-  220-REWRITE-MASTER-REC.'
00159 ************************
00160      IF NEW-MONTH                        IN WS-DAILY-HDR
00161         MOVE ZEROS TO PAD-MTD-ACCRET-AMT OF WS-MASTER-DTL
00162      END-IF
00163      MOVE ZEROS TO PAD-DAY-ACCRET-AMT    OF WS-MASTER-DTL
00164      WRITE MASTER-ACCRET-REC-OP        FROM WS-MASTER-DTL
00165      ADD  +1                             TO WS-NO-DAILY-CNT
00166      .
00167 ***************************
00168  700-GET-BOTH-COMPARE-KEYS.
           DISPLAY 'DEBUG-  700-GET-BOTH-COMPARE-KEYS.'
00169 ***************************
00170      .
00171 ***************************
00172  700-GET-DAILY-COMPARE-KEY.
           DISPLAY 'DEBUG-  700-GET-DAILY-COMPARE-KEY.'
00173 ***************************
00174      IF NOT DAILY-FILE-EOF
00175         READ DAILY-ACCRET-FILE-IP  INTO WS-DAILY-DTL
00176         AT END
00177              SET DAILY-FILE-EOF TO TRUE
00178              MOVE HIGH-VALUES   TO WS-DAILY-COMPARE-KEY
00179         NOT AT END
00180              ADD  +1            TO WS-DAILY-REC-CNT
00181              MOVE PAD-USR-CDE   OF WS-DAILY-DTL
00182                   TO
00183                   WDC-USR-CDE
00184              MOVE PAD-ACCT-NBR  OF WS-DAILY-DTL
00185                   TO
00186                   WDC-ACCT-NBR
00187              MOVE PAD-SEC-NBR   OF WS-DAILY-DTL
00188                   TO
00189                   WDC-SEC-NBR
00190         END-READ
00191      END-IF
00192      .
00193 ****************************
00194  700-GET-MASTER-COMPARE-KEY.
           DISPLAY 'DEBUG-  700-GET-MASTER-COMPARE-KEY.'
00195 ****************************
00196      IF NOT MASTER-FILE-EOF
00197         READ MASTER-ACCRET-FILE-IP  INTO WS-MASTER-DTL
00198         AT END
00199              MOVE HIGH-VALUES    TO WS-MASTER-COMPARE-KEY
00200              SET MASTER-FILE-EOF TO TRUE
00201         NOT AT END
00202              ADD +1              TO WS-MASTER-REC-CNT
00203              MOVE PAD-USR-CDE    OF WS-MASTER-DTL
00204                   TO
00205                   WMC-USR-CDE
00206              MOVE PAD-ACCT-NBR   OF WS-MASTER-DTL
00207                   TO
00208                   WMC-ACCT-NBR
00209              MOVE PAD-SEC-NBR    OF WS-MASTER-DTL
00210                   TO
00211                   WMC-SEC-NBR
00212         END-READ
00213      END-IF
00214      .
00215  700-EXIT. EXIT.
00216
00217 *****************************
00218  810-DISP-MSG-AND-OPEN-FILES.
           DISPLAY 'DEBUG-  810-DISP-MSG-AND-OPEN-FILES.'
00219 *****************************
00220      DISPLAY '*****************************************'
00221      DISPLAY '             XXXX STARTED                '
00222      DISPLAY '*****************************************'
00223      OPEN  INPUT MASTER-ACCRET-FILE-IP
00224                   DAILY-ACCRET-FILE-IP
00225           OUTPUT MASTER-ACCRET-FILE-OP
00226      .
00227 ********************
00228  820-VERIFY-HEADERS.
           DISPLAY 'DEBUG-  820-VERIFY-HEADERS.'
00229 ********************
00230 *===>    VERIFY DAILY HEADER
00231 *
00232      READ DAILY-ACCRET-FILE-IP    INTO WS-DAILY-HDR
00233      AT END
00234          SET NOT-AN-ACCRET-FILE     TO TRUE
00235      NOT AT END
00236          IF PAH-HDR-ID OF WS-DAILY-HDR NOT = 'HDR'
00237             SET NOT-AN-ACCRET-FILE  TO TRUE
00238          END-IF
00239      END-READ
00240      IF NOT-AN-ACCRET-FILE
00241         DISPLAY 'ERROR!!!! '
00242                 'INPUT FILE NOT A DAILY ACCRETION FILE'
00243         MOVE +2  TO RETURN-CODE
00244         STOP RUN
00245      END-IF
00246
00247 *===>    VERIFY MASTER HEADER
00248 *
00249      READ MASTER-ACCRET-FILE-IP    INTO WS-MASTER-HDR
00250      AT END
00251          SET MASTER-FILE-EOF         TO TRUE
00252          MOVE HIGH-VALUES            TO WS-MASTER-COMPARE-KEY
00253      NOT AT END
00254          IF PAH-HDR-ID OF WS-MASTER-HDR NOT = 'HDR'
00255             DISPLAY 'ERROR!!!! '
00256                     'INPUT FILE NOT A MASTER ACCRETION FILE'
00257             MOVE +2  TO RETURN-CODE
00258             STOP RUN
00259          END-IF
00260      END-READ
00261      .
00262 *****************
00263  830-SET-GO-NOGO.
           DISPLAY 'DEBUG-  830-SET-GO-NOGO.'
00264 *****************
00265 *===>  IF THE DAILY FILE CONTAINS NO ACCRETION DATA AND
00266 *===>     THE MASTER FILE IS A NULL FILE THE PROJECT HAS
00267 *===>     HAS NOT PRODUCED DATA YET. SET RC=2 TO NOT EXECUTE
00268 *===>     REPORT PROGRAM(XXXX).
00269 *
00270      PERFORM 700-GET-DAILY-COMPARE-KEY
00271      IF DAILY-FILE-EOF
00272         AND
00273         MASTER-FILE-EOF
00274         DISPLAY 'NOTE!!!! '
00275                 'NO INPUT FOR INFLATION BONDS YET'
00276         MOVE +2  TO RETURN-CODE
00277         STOP RUN
00278      END-IF
00279      PERFORM 700-GET-MASTER-COMPARE-KEY
00280      .
00281 ************************
00282  840-CHECK-FOR-NEW-YEAR.
           DISPLAY 'DEBUG-  840-CHECK-FOR-NEW-YEAR.'
00283 ************************
00284 *===>     AT NEW YEAR FORCE NEW MASTER TO BE CREATED
00285 *
00286      IF NEW-YEAR            IN WS-DAILY-HDR
00287         MOVE HIGH-VALUES    TO WS-MASTER-COMPARE-KEY
00288         SET MASTER-FILE-EOF TO TRUE
00289      END-IF
00290      .
00291 *******************
00292  850-GET-CURR-DATE.
           DISPLAY 'DEBUG-  850-GET-CURR-DATE.'
00293 *******************
00294      ACCEPT WS-CURR-DATE-YMD       FROM DATE
00295      IF WCD-YY                        < '96'
00296         MOVE '20'                    TO WCD-CC
00297      ELSE
00298         MOVE '19'                    TO WCD-CC
00299      END-IF
00300      .
00301 ************
00302  900-END-IT.
           DISPLAY 'DEBUG-  900-END-IT.'
00303 ************
00304      CLOSE        DAILY-ACCRET-FILE-IP
00305                  MASTER-ACCRET-FILE-IP
00306                  MASTER-ACCRET-FILE-OP
00307      DISPLAY ' '
00308      EVALUATE TRUE
00309      WHEN NEW-YEAR IN WS-DAILY-HDR
00310           DISPLAY 'NOTE!!!! MTD AND YTD ACCRETION $ TOTALS '
00311                   'RESET FOR NEW YEAR'
00312           DISPLAY ' '
00313      WHEN NEW-YEAR IN WS-DAILY-HDR
00314           DISPLAY 'NOTE!!!! MTD ACCRETION $ TOTALS '
00315                   'RESET FOR NEW MONTH'
00316           DISPLAY ' '
00317      END-EVALUATE
00318      DISPLAY WS-DAILY-REC-CNT  '  DAILY RECORDS READ'
00319      DISPLAY WS-MASTER-REC-CNT ' MASTER RECORDS READ'
00320      DISPLAY ' '
00321      DISPLAY WS-MATCH-CNT      ' MASTER RECORDS UPDATED'
00322      DISPLAY WS-NO-DAILY-CNT   ' MASTER RECORDS UNCHANGED'
00323      DISPLAY WS-NO-MASTER-CNT  ' MASTER RECORDS ADDED'
00324      DISPLAY ' '
00325      DISPLAY '*****************************************'
00326      DISPLAY '        XXXX ENDED RETURN CODE = ' RETURN-CODE
00327      DISPLAY '*****************************************'
00328      .
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 FTP Skip or ignore error and process ... AJAYREDDY All Other Mainframe Topics 3 Wed Sep 27, 2017 8:12 pm
No new posts Comparing 2 Files using Current time arunsoods SYNCSORT 9 Fri Sep 22, 2017 6:00 pm
No new posts Split 1 file into 10 output Files - S... Prasanth Kumar SYNCSORT 5 Sat Sep 16, 2017 12:02 am
No new posts Join records from 2 files with No Dup... Poha Eater DFSORT/ICETOOL 22 Sun Aug 27, 2017 10:35 pm
No new posts Match two files using multiple keys a... santoshks1987 SYNCSORT 11 Fri Aug 18, 2017 10:50 am

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