Home      Mainframe Forum      Mainfarme Tutorials      IBM Manuals      Mainframe Interview Questions      Mainframe Books      IT News     SiteMap     Downloads


     
 
MAINFRAME - TIP OF THE DAY : All available storage is assigned to the job or jobstep, If REGION is coded 0K or 0M

Google
 
Web mainframegurukul.com

2-File Match/Merge sample code - Cobol Example Program

 
Post new topic   Reply to topic    mainframegurukul.com Forum Index -> COBOL
  View previous topic :: View next topic  
Author Message
DikDude
Moderator


Joined: 22 Jul 2011
Posts: 1001
Location: usa

Answer was approved by Question owner.
Useful Post
-1 votes
Not an useful post
Greate Post!! Salute Author
0 salutes

PostPosted: Thu Dec 20, 2012 10:38 pm    Post subject: 2-File Match/Merge sample code - Cobol Example Program Reply with quote

Below is a small sample program that matches/merges 2 sequential files that have been previously put "in sequence".

Depending on your exact requirement, changes may need to be made, but the overall process works for most cases. If your files have a 1-to-1 or a 1-to-many relationship, the model should work for you. One case where additional code may be needed is when both files might have duplicate key values. The issue may be how to determine how the duplicates should "sync up".

Something to keep in mind is that to keep things more manageable you do not want to code compares for multiple keys. As you read records (before any comparing) combine the "key" fields into a ws field (one for each file) so the compare does not become other than simple.

If you find a typo or a "real" error, please let me know via PM. If you prefer a different way, fine, but this is an approach that works many, many places.

I cannot emphasize enough that it is critical that you thoroughly test your version of the code before production implementation.

Code:
       IDENTIFICATION DIVISION.
       PROGRAM-ID.  SAMPMTCH.
       DATE-COMPILED.
      *---------------------------------------------------------------*
      *                                                               *
      * THIS PROGRAM COMPARES THE CAP INFO AGAINS THE ELIG INFO AND   *
      *  CREATES A FILE OF MATCHED PROVIDER, PERSON, RATE INFO.       *
      *  THE NEW-RATE FILE IS TAB-DELIMITED FOR DOWNLOAD AND USE      *
      *  WITH A WIN-BASED SYSTEM.                                     *
      *                                                               *
      * THIS CODE IS A STRIPPED DOWN VERSION OF AN ACTUAL PRODUCTION  *
      *  PROGRAM - NEARLY ALL OF THE BUSINESS RULES LOGIC HAS BEEN    *
      *  REMOVED TO MAKE THE EXAMPLE EASIER TO READ.                  *
      *                                                               *
      * IF YOU CHOOSE TO USE THIS MODEL, PLEASE MAKE SURE YOU         *
      *  THOROUGHLY TEST YOUR VERSION BEFORE USING FOR SOME BUSINESS  *
      *  REQUIREMENT.                                                 *
      *                                                               *
      *---------------------------------------------------------------*
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
      *
           SELECT COMP-CAP      ASSIGN TO UT-S-CAP.
           SELECT COMP-ELG      ASSIGN TO UT-S-ELIG.
           SELECT NEW-RATE      ASSIGN TO UT-S-NEWRATE.
      *
       DATA DIVISION.
       FILE SECTION.
      *
       FD  COMP-CAP
           LABEL RECORDS ARE STANDARD
           RECORDING MODE IS F
           BLOCK CONTAINS 0 RECORDS.

       01  COMP-CAP-REC.
           05 CCR-PROV          PIC X(9).
           05 CCR-FILL          PIC X.
           05 CCR-RATE          PIC X(5).
           05 FILLER            PIC X(65).
      *
       FD  COMP-ELG
           RECORDING MODE IS F
           BLOCK CONTAINS 0 RECORDS
           LABEL RECORDS ARE STANDARD.

       01  COMP-ELG-REC.
           05 CER-PRSN          PIC X(12).
           05 FILLER            PIC X.
           05 CER-PROV          PIC X(9).
           05 FILLER            PIC X(58).

       FD  NEW-RATE
           RECORDING MODE IS F
           BLOCK CONTAINS 0 RECORDS
           LABEL RECORDS ARE STANDARD.

       01  NEW-RATE-REC         PIC X(80).

       WORKING-STORAGE SECTION.
       77  WKS-MESSAGE         PIC X(23) VALUE
                                   'WORKING-STORAGE SECTION'.

       77  CAP-READ               PIC 9(7) COMP-3 VALUE 0.
       77  ELG-READ               PIC 9(7) COMP-3 VALUE 0.
       77  NEW-RATE-RECS          PIC 9(7) COMP-3 VALUE 0.
       77  RATE-ZEROED            PIC 9(7) COMP-3 VALUE 0.
       77  TOT-MONEY              PIC 9(7)V99 COMP-3 VALUE 0.
      *
       01  MATCH-FILES.
           05 NEED-CAP              PIC X VALUE 'Y'.
           05 NEED-ELG              PIC X VALUE 'Y'.
           05 EOF-CAP               PIC X VALUE 'N'.
           05 EOF-ELG               PIC X VALUE 'N'.
           05 COMP-CAPP             PIC 9(9) VALUE ZEROS.
           05 COMP-ELIG             PIC 9(9) VALUE ZEROS.
      *
       01  NEW-RATE-REC-WORK.
           05 NRR-PROV          PIC X(9).
           05 FILLER            PIC X VALUE X'05'.
           05 NRR-PRSN          PIC X(12).
           05 FILLER            PIC X VALUE X'05'.
           05 NRR-RATE          PIC X(5).
           05 FILLER REDEFINES NRR-RATE.
              10 FILLER         PIC X.
              10 NRR-DLR        PIC 9.
              10 FILLER         PIC X.
              10 NRR-CENTS      PIC 99.
           05 FILLER            PIC X(52).
      *
       01  WORK-MONEY           PIC 9V99.
       01  WORK-MONEY-R REDEFINES WORK-MONEY.
           05 WM-DLR            PIC 9.
           05 WM-CENTS          PIC 99.
      *
       PROCEDURE DIVISION.
       010-OPEN-FILES.
           OPEN INPUT  COMP-CAP
                       COMP-ELG
                OUTPUT NEW-RATE.
      *
       020-READ-CAP-RECORDS.
           IF EOF-CAP = 'Y' OR
              NEED-CAP = 'N'
              GO TO 030-READ-ELG.
           READ COMP-CAP AT END
                MOVE 'Y' TO EOF-CAP
                MOVE 'N' TO NEED-CAP
                MOVE 999999999 TO COMP-CAPP
                MOVE ALL 'Z' TO COMP-CAP-REC
                GO TO 030-READ-ELG.
           IF CCR-PROV NOT NUMERIC
              DISPLAY 'CAP PROVIDER NOT NUMERIC - SKIPPED = '
                      COMP-CAP-REC
              GO TO 020-READ-CAP-RECORDS.
           MOVE CCR-PROV TO COMP-CAPP.
           ADD 1 TO CAP-READ.
           MOVE 'N' TO NEED-CAP.
      *
       030-READ-ELG.
           IF EOF-ELG = 'Y' OR
              NEED-ELG = 'N'
              GO TO 040-MATCH-FILES.
           READ COMP-ELG AT END
                MOVE 'Y' TO EOF-ELG
                MOVE 'N' TO NEED-ELG
                MOVE 999999999 TO COMP-ELIG
                MOVE ALL 'Z' TO COMP-ELG-REC
                GO TO 040-MATCH-FILES.
           IF CER-PROV NOT NUMERIC
              DISPLAY 'ELG PROVIDER NOT NUMERIc - SKIPPED'
              GO TO 030-READ-ELG.
           MOVE CER-PROV TO COMP-ELIG.
           ADD 1 TO ELG-READ.
           MOVE 'N' TO NEED-ELG.


       040-MATCH-FILES.
           IF EOF-CAP = 'Y' AND
              EOF-ELG = 'Y'
              GO TO 990-PUBLISH-STATS.
      *
           IF COMP-CAPP = COMP-ELIG GO TO 100-CAP-ELIG-MATCH.
      * these compares/comments change dependng on requirements.
           IF COMP-CAPP < COMP-ELIG GO TO 120-CAP-NOT-USED.
      *    IF COMP-CAPP < COMP-ELIG
      *       MOVE 'Y' TO NEED-CAP
      *       GO TO 020-READ-CAP-RECORDS.
           IF COMP-CAPP > COMP-ELIG GO TO 140-GET-RATE.
      *    IF COMP-CAPP > COMP-ELIG
      *       MOVE 'Y' TO NEED-ELG
      *       DISPLAY 'MISSING CLAIM DATA '
      *       GO TO 020-READ-CAP-RECORDS.

      *  WE SHOULD NOT BE ABLE TO GET HERE. . . .
           DISPLAY ' 040-MATCH-FILES FATAL ERROR'.
           DISPLAY ' CAP=' CCR-PROV ' ELIG=' CER-PROV.
           DISPLAY ' RUN TERMINATED.'.
           GOBACK.
      *
       100-CAP-ELIG-MATCH.
      * these may change depending on how duplicates are handled.
      *    MOVE 'Y' TO NEED-CAP, NEED-ELG.
           MOVE 'Y' TO NEED-ELG.
      *
           MOVE CER-PROV TO NRR-PROV.
           MOVE CER-PRSN TO NRR-PRSN.
           MOVE CCR-RATE TO NRR-RATE.
           MOVE NRR-DLR TO WM-DLR.
           MOVE NRR-CENTS TO WM-CENTS.
           COMPUTE TOT-MONEY = TOT-MONEY + WORK-MONEY.
           WRITE NEW-RATE-REC FROM NEW-RATE-REC-WORK.
           COMPUTE NEW-RATE-RECS = NEW-RATE-RECS + 1.
      *
           GO TO 020-READ-CAP-RECORDS.
      *
       120-CAP-NOT-USED.
           MOVE 'Y' TO NEED-CAP.
      *
      *    DISPLAY 'CAP RECORD NOT USED = ' COMP-CAP-REC.
      *
      *    MOVE CER-PROV TO NRR-PROV.
      *    MOVE CER-PRSN TO NRR-PRSN.
      *    MOVE CCR-RATE TO NRR-RATE.
      *    WRITE NEW-RATE-REC FROM NEW-RATE-REC-WORK.
      *    COMPUTE NEW-RATE-RECS = NEW-RATE-RECS + 1.
      *
           GO TO 020-READ-CAP-RECORDS.
      *
       140-GET-RATE.
           MOVE 'Y' TO NEED-ELG.
      *
           MOVE CER-PROV TO NRR-PROV.
           MOVE CER-PRSN TO NRR-PRSN.
           MOVE ' 0.00'  TO NRR-RATE.
           WRITE NEW-RATE-REC FROM NEW-RATE-REC-WORK.
           COMPUTE NEW-RATE-RECS = NEW-RATE-RECS + 1.
           COMPUTE RATE-ZEROED   = RATE-ZEROED   + 1.
      *
           GO TO 020-READ-CAP-RECORDS.
      *
       990-PUBLISH-STATS.
           DISPLAY 'CAP RECS READ = ' CAP-READ.
           DISPLAY 'ELG RECS READ = ' ELG-READ.
           DISPLAY 'NEW RECS      = ' NEW-RATE-RECS.
           DISPLAY 'ZEROED RATES  = ' RATE-ZEROED.
           DISPLAY 'TOTAL MONEY   = ' TOT-MONEY.
      *
       9999-STOP.
           CLOSE COMP-CAP COMP-ELG NEW-RATE.
           GOBACK.

To use this code, copy/paste into a text file and upload to your source library.
_________________
Have a good one
Back to top
View user's profile Send private message
Click here, If this post answer your question. <-- Click on right mark icon. If this post answer your question.

academyindia4
Guest





Answer was approved by Question owner.
Useful Post
0 votes
Not an useful post
Greate Post!! Salute Author
0 salutes

PostPosted: Fri Jan 15, 2016 8:28 pm    Post subject: Topic deleted by Admin Reply with quote

<< Content deleted By Admin >>
Back to top
Click here, If this post answer your question. <-- Click on right mark icon. If this post answer your question.
academyindia4
Guest





Answer was approved by Question owner.
Useful Post
0 votes
Not an useful post
Greate Post!! Salute Author
0 salutes

PostPosted: Sat Jan 30, 2016 11:39 pm    Post subject: Topic deleted by Admin Reply with quote

<< Content deleted By Admin >>
Back to top
Click here, If this post answer your question. <-- Click on right mark icon. If this post answer your question.
Display posts from previous:   
Post new topic   Reply to topic    mainframegurukul.com Forum Index -> COBOL All times are GMT + 5 Hours
Page 1 of 1



 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Related topics
 Topics   Replies   Author   Views   Last Post 
No new posts Query For IEBPTPCH 3 padmajeet.gaikwad 13445 Mon Feb 01, 2016 10:56 pm
academyindia4 View latest post
No new posts Unable to achieve below scenario using ICETOOL 27 sirianangel 33683 Mon Feb 01, 2016 10:01 pm
academyindia4 View latest post
No new posts Need to put records a Sorting order as mentioned below. 14 Yash1911 12634 Mon Jan 25, 2016 9:50 pm
academyindia4 View latest post
No new posts how to deal with the below scenario using iebgener 7 mainframes_6002 11170 Wed Dec 07, 2011 10:34 am
DikDude View latest post
No new posts Coulu someone explain the parameters in the below code? 1 lovely sweety 11352 Thu Jun 09, 2011 3:50 pm
dbzTHEdinosauer View latest post
 


Cobol Tutorial
This cobol tutorial covers most of the important topics like STRING, UNSTRING, COMP, COMP-3.....
DB2 Tutorial
DB2 Tutorial focuses on DB2 COBOL Programming. Explains in simple language. Some Chapters are locked, Forum members have free access to these chapters
CICS Tutorial
This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming...
JCL Tutorial
This is most popular JCL tutorial from mainframegurukul. It does contain important jcl ....
SORT Tutorial
This Tutorial covers all important aspects of DFSORT. Has more SORT examples
INTERVIEW Questions
This page covers important interview questions
Mainframe Jobs
Mainframe Jobs posted by members of mainframegurukul forum
FaceBook Page
MainframeGurukul FaceBook Page
LinkedIn Page
MainframeGurkul Linkedin Page

This widget requires Flash Player 9 or better







Go to top of the page
 

Online ABEND Reference ||  JCL References ||  COBOL References ||  VSAM References ||  Tutorials by Drona Series ||  SQL tutorial ||  BOOKS  ||  DB2 INTERVIEW QUESTIONS ||  COBOL INTERVIEW QUESTIONS  ||  JCL INTERVIEW QUESTIONS ||  JCL2 INTERVIEW QUESTIONS ||  VSAM INTERVIEW QUESTIONS ||  CICS INTERVIEW QUESTIONS  ||  Online tutorials ||  Online ABEND Reference ||  JCL References ||  COBOL References ||  VSAM References ||  Tutorials by Drona Series ||  SQL tutorial ||  BOOKS  ||  SiteMap  ||  Expeditor Tutorial  ||  FILE-AID Tutorial  ||  Changeman Tutorial  ||  COBOL   ||  DB2   ||  JCL  ||  CICS  ||  VSAM  ||  DB2 Interview Questions ( 110 )   || Simple JCL Tutorials  || JCL Tutorial from MainframeGurukul.com   || Simple JCL Tutorial - Chapter1 ;|| Mainframe Forum - Tutorials  || Mainframe Tutorials || Mainframe CICS tutorial|| Mainframe COBOL Tutorial

Drona Educational Forums - Mainframe Cobol DB2 CICS Board
Powered by phpBB

mainframetopic-6940.html