I have the requirement to compare the two files and pick up
the matching records.
File 1. file2

23 32
32 13
34 15
35 36
36 35
43

Get the matching records from this 2 files to out file. how
you will do this in cobol program?

Answers were Sorted based on User's Feedback



I have the requirement to compare the two files and pick up the matching records. File 1. ..

Answer / harsha

First merge bothe file.
Use sort card
//Sysin dd *
sort fields=-------
Sum fields=(none,xsum)
/*

File mentioned in SORTXSUM dd name will contain matching
records.

Is This Answer Correct ?    0 Yes 2 No

I have the requirement to compare the two files and pick up the matching records. File 1. ..

Answer / arun

IDENTIFICATION DIVISION.
PROGRAM-ID. MATCH.
DATE-COMPILED.
*-----------------------------------------------------
----------*

*
*
* THIS PROGRAM COMPARES THE CAP INFO AGAINS THE ELIG
INFO AND *
* CREATES A FILE OF MATCHED PROVIDER, PERSON, RATE
INFO. *
*-----------------------------------------------------
----------*
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.

Is This Answer Correct ?    0 Yes 2 No

I have the requirement to compare the two files and pick up the matching records. File 1. ..

Answer / anupam

EVALUATE KEY1 > KEY2 ALSO KEY2 < KEY1
WHEN FALSE ALSO FALSE
READ F1 NEXT RECORD
READ F2 NEXT RECORD
WHEN TRUE ALSO FALSE
READ FILE1 NEXT RECORD
WHEN FALSE ALSO TRUE
READ FILE2 NEXT RECORD
END-EVALUATE

Is This Answer Correct ?    3 Yes 10 No

I have the requirement to compare the two files and pick up the matching records. File 1. ..

Answer / pradeep

read all the records of file1 and load into array

read the record of second file one at a time and search for
the value in the array(table) using search

if the value of the file matches with the value in the table
then write that record to output file

Is This Answer Correct ?    1 Yes 8 No

I have the requirement to compare the two files and pick up the matching records. File 1. ..

Answer / pa

load any of the file to the table and use SEARCH.
write the matching records to the output file.

Is This Answer Correct ?    4 Yes 13 No

Post New Answer

More COBOL Interview Questions

Give some advantages of REDEFINES clause?

2 Answers   Syntel,


In COBOL CALL-CALLING,if a program A is calling 3 sub- programs, dynamically, then it is said sub-programs will always will always in Initial Mode. My question is : Do we need to code CANCEL or (IS INITIAL) for dynamically called sub-programs or it is the property of Dynamically called pgms so every time sub-pgms are called they will be in initial mode. ***This question is only Dynamic call****, Please reply. Thank you in advance.

4 Answers   Wipro,


Hi Devolopers.. i need ur help.. i have 3 years of exp in Manual testing and SQL, next month onwards i shifted in to MAINFRAME TESTING... i have ZERO Knowledge abt mainframes.... PLS SUGGEST ME WHAT I LEARN in AMEERPET? mainframe testing or mainframe total devolopment subject... AS a devoloper u know every thing tester what to do PLSSSSSSSSS help me ITS VERY URGENT...

1 Answers  


what are the steps to sort in a cobol program?

2 Answers   Patni,


How can you submit a job from COBOL programs?

2 Answers   ITC Infotech,






I need to compare two VSAM files, both having 'number' as key. If there is a matching record, write the data into another VSAM file. How will it be possible.

1 Answers   DSRC,


Did anybody attend the walkin of TCS on 31st July in Gurgaon for any technology,If u have completed 3 round i.e till the HR round,have u received the Offer letter yet? Please let me know.Thanks.

1 Answers  


What is the difference between SEARCH and SEARCH ALL? What is more efficient?

9 Answers   IBM, iFlex, Wipro,


what is Reentrancy and Quasi-reentrancy?

1 Answers  


What is amode(24), amode(31), rmode(24) and rmode(any) (applicable to only mvsesa enterprise server) ?

0 Answers  


When search all is used in cobol program without sorted input data?

6 Answers   CGI, Principal Finance,


How to define variable 9(20) in COBOL, because compiler does not allow us to declare variables with Pic 9(18). Can anyone please let me know the answer... I know one answer to this question which is to use Compiler option Arith (Extend) during Compilation. It extends the maximum limit to 9(32)..Just wanted to know if there is any other way to extend this?

4 Answers   CSC, TCS,


Categories