IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

cobol file logic required?


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
babu_hi

New User


Joined: 11 Apr 2006
Posts: 93

PostPosted: Tue Apr 20, 2010 8:40 pm
Reply with quote

I have 2 input files and i need to write a report file.At 1st step -I compare first input file with second input file,if any matched record found then set true eof flag and close and open agian.if match not found until end of file,then write 1st file record.at 2nd step- i compare 2nd input file with 1st input file and write only unmatched records from 2nd input file.my report looks like below


example :

Code:
First Input file-1
Branch      action  amt
020            1    100
020            2    200
020            3    300
036            1    200
036            2    100
036            3    200
045            1    200
045            2    400
045            3    200
055            1    200
055            2    400
055            3    200

Second Input file 2
Branch      action  amt
020           1   100
020           2   200
020           3   300
025           1   200
025           2   400
025           3   200
036           1   200
036           2   100
036           3   200
048           1   200
048           2   400
048           3   200

My output file should be like this

Code:
Brach020  file1amt  file2amt  difference
Action1       100       100        0
Action2       200       200        0
Action3       300       300        0
Branch total  600       600        0

Brach036  file1amt  file2amt  difference
Action1       200       200        0
Action2       100       100        0
Action3       200       200        0
Branch total  500       500        0

Brach045  file1amt  file2amt  difference
Action1       200         0        200
Action2       400         0        400
Action3       200         0        200
Branch total  600         0        600

Brach055  file1amt  file2amt  difference
Action1       200         0        200
Action2       400         0        400
Action3       200         0        200
Branch total  600         0        600

Brach025  file1amt  file2amt  difference
Action1       200         0        200
Action2       400         0        400
Action3       200         0        200
Branch total  600         0        600

Brach048  file1amt  file2amt  difference
Action1       200         0        200
Action2       400         0        400
Action3       200         0        200
Branch total  600         0        600


but i am not getting before last record branch toatl?

Code:
 PERFORM UNTIL END-OF-FILE-F1                               
 READ BC-GAD-TRAN-FILE                                       
 MOVE 1 TO WS-GAD-READ-CNT                                   
 MOVE 'N' TO END-OF-FILE2-SW                                 
  EVALUATE TRUE                                             
   WHEN FILE1-IN-STATUS IS EQUAL TO ZEROS                   
     PERFORM UNTIL END-OF-FILE-F2                           
     READ BC-RDC-TRAN-FILE                                   
      IF GAD-SSTACB = RDC-SSTACB  AND GAD-SSBIN = RDC-SSBIN 
      IF GAD-SSTACB = RDC-SSTACB                             
         ADD 1 TO WS-DETL-REC-CNT                           
         IF HDR-WRITE                                       
           PERFORM 4000-HDR-WRITE-PARA                       
                                 THRU 4999-EXIT             
           MOVE 'N' TO WS-HDR-MFLAG                         
         END-IF                                             
         IF GAD-SSBIN = 1                                   
           MOVE 'BIN 1 TOTALS' TO RDC-BIN                   
         ELSE                                               
            IF GAD-SSBIN = 2                                 
              MOVE 'BIN 2 TOTALS' TO RDC-BIN                 
            ELSE                                             
              MOVE 'BIN 3 TOTALS' TO RDC-BIN                 
            END-IF                                           
         END-IF                                             
         MOVE GAD-SSCAMT     TO  MF-BIN-AMT                 
         MOVE RDC-SSCAMT     TO  RDC-BIN-AMT                 
         ADD GAD-SSCAMT  TO WS-MFBIN-TOT                     
         ADD RDC-SSCAMT  TO WS-RDCBIN-TOT                   
         COMPUTE BOTH-BIN-DIF = GAD-SSCAMT - RDC-SSCAMT     
         WRITE RED-FINAL-REPROT-REC                         
         SET END-OF-FILE-F2 TO TRUE                         
         CLOSE BC-RDC-TRAN-FILE                             
         OPEN INPUT BC-RDC-TRAN-FILE                         
      END-IF   
     
      IF PARM2-EOF-IN                                   
         IF GAD-SSBIN = 1                               
               MOVE 'BIN 1 TOTALS' TO RDC-BIN           
         ELSE                                           
             IF GAD-SSBIN = 2                           
                MOVE 'BIN 2 TOTALS' TO RDC-BIN           
             ELSE                                       
               MOVE 'BIN 3 TOTALS' TO RDC-BIN           
             END-IF                                     
         END-IF                                         
         MOVE GAD-SSCAMT     TO  MF-BIN-AMT             
         MOVE RDC-SSCAMT     TO  RDC-BIN-AMT             
         ADD GAD-SSCAMT  TO WS-MFBIN-TOT                 
         ADD RDC-SSCAMT  TO WS-RDCBIN-TOT               
         COMPUTE BOTH-BIN-DIF = GAD-SSCAMT - RDC-SSCAMT 
         WRITE RED-FINAL-REPROT-REC                     
         SET END-OF-FILE-F2 TO TRUE                     
         CLOSE BC-RDC-TRAN-FILE                         
         OPEN INPUT BC-RDC-TRAN-FILE                     
      END-IF                                             
      IF BRANCH-FLAG                                     
         MOVE GAD-SSTACB TO WS-SSTACB                   
         MOVE 'N' TO WS-BRACH-FLAG                       
      END-IF                                             
          IF WS-SSTACB NOT= GAD-SSTACB                           
    IF WS-SSTACB NOT= WS-RDC-SSTACB                       
       MOVE WS-MFBIN-TOT  TO MF-BIN-AMT                   
       MOVE WS-RDCBIN-TOT TO RDC-BIN-AMT                   
       COMPUTE BOTH-BIN-DIF = MF-BIN-AMT - RDC-BIN-AMT     
       MOVE 'BRANCH TOTAL' TO RDC-BIN                     
       WRITE RED-FINAL-REPROT-REC                         
       MOVE ZEROS TO WS-MFBIN-TOT                         
       MOVE ZEROS TO WS-RDCBIN-TOT                         
       MOVE ZEROS TO WS-SSTACB                             
       MOVE GAD-SSTACB TO BRNACH-NUM                       
       WRITE RED-FINAL-REPROT-REC  FROM WS-BLANK-LINE     
       WRITE RED-FINAL-REPROT-REC  FROM WS-HDER-REC       
       SET END-OF-FILE-F2 TO TRUE                         
       IF END-OF-FILE-F2                                   
          IF GAD-SSBIN = 1                                 
             MOVE 'BIN 1 TOTALS' TO RDC-BIN               
          ELSE                                             
             IF GAD-SSBIN = 2                             
                MOVE 'BIN 2 TOTALS' TO RDC-BIN             
             ELSE                                         
                MOVE 'BIN 3 TOTALS' TO RDC-BIN             
             END-IF                                       
          END-IF                                           
       MOVE GAD-SSCAMT     TO  MF-BIN-AMT                 
       MOVE RDC-SSCAMT     TO  RDC-BIN-AMT                 
       ADD GAD-SSCAMT  TO WS-MFBIN-TOT                     
       ADD RDC-SSCAMT  TO WS-RDCBIN-TOT                   
       COMPUTE BOTH-BIN-DIF = GAD-SSCAMT - RDC-SSCAMT     
       WRITE RED-FINAL-REPROT-REC                         
       END-IF                                             
       CLOSE BC-RDC-TRAN-FILE                             
       OPEN INPUT BC-RDC-TRAN-FILE                         
    END-IF                                                 
    MOVE GAD-SSTACB TO WS-SSTACB                           
   END-PERFORM                                             
        WHEN PARM1-EOF-IN                                         
          DISPLAY ' ******************************************'   
          DISPLAY ' * END OF BC-GAD-TRAN-FILE                *'   
          DISPLAY ' * STATUS WAS', FILE1-IN-STATUS               
          DISPLAY ' ******************************************'   
          SET END-OF-FILE-F1 TO TRUE                             
          CLOSE BC-GAD-TRAN-FILE                                 
          PERFORM 5000-HDR-WRITE-PARA  THRU 5999-EXIT             
          GO TO 2999-EXIT                                         
        WHEN OTHER                                               
          DISPLAY ' ******************************************'   
          DISPLAY ' * ERROR ON READ FOR BC-GAD-TRAN-FILE      *' 
          DISPLAY ' * STATUS WAS', FILE1-IN-STATUS               
          DISPLAY ' ******************************************'   
       END-EVALUATE                                               
   END-PERFORM.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Tue Apr 20, 2010 10:51 pm
Reply with quote

So, for each record in file1, you read file2 from the beginning until you find a match or until end-of file.

Oh dear... icon_oak.gif

Place your cobol program in its due place: the "Recycle Bin"
Search the forum for sort option "JOINKEYS" (read this thread for example).
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Tue Apr 20, 2010 11:10 pm
Reply with quote

Hello,

Or download the 2-file match/merge sample code provided in the "Sticky" near the top of the COBOL part of the forum. . .

What you are trying to do is the worst possible way to implement. . .
Back to top
View user's profile Send private message
icemanroh

New User


Joined: 23 Aug 2008
Posts: 25
Location: Mumbai

PostPosted: Wed May 05, 2010 9:36 am
Reply with quote

If the files are huge then the logic of Opening & Closing the files will take awful lot of time for the Job to run. It will consume a lot of MIPS. Such logic should only be implemented when files are having very few records.

Can you tell me how big these files are? I can suggest you the best possible method based on the answer.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Wed May 05, 2010 9:51 am
Reply with quote

Hello,

The match/merge is a very good choice regardless of the size. This might be accomplished by code or some utility (i.e. the sort)

The process of closing and re-opening a file over and over is not a good choice. It is not permitted on most systems - it will be rejected on review for turnover.
Back to top
View user's profile Send private message
icemanroh

New User


Joined: 23 Aug 2008
Posts: 25
Location: Mumbai

PostPosted: Wed May 05, 2010 9:58 am
Reply with quote

I saw Dicks code now. I think it is not just a good choice, in fact it is the best choice for any file comparision program. With this logic you can easily compare files having million records & it will consume least MIPS.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 8
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Replace each space in cobol string wi... COBOL Programming 3
Search our Forums:

Back to Top