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 / nnn

First sort the both files through JCL or internal sort.
Then follow below logic in the program.

Read file1
Read file2

perform until end-of file1 OR end-of file2
if file1 = file2
write a matched record to output
read file1
read file2
end-if
if file1 < file2
read file1
end-if
if file1 > file2
read file2
end-if
End-perform.

Is This Answer Correct ?    117 Yes 8 No

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

Answer / soumya santosini patnaik

first load the files in shorted order after that code a
matching program. in the procedure division check the file1
entry with file2 entry if file1 entry = file2 entry then
then write to o/p file end-evaluate esle check for file1<
file2 (if yes then the pointer is brought down to the 2nd
rec of file1 and checked with 1st rec of file2 when the
para is performed for 2nd time),if the above condition is
false then it checks if file1>file2 if yes then pointer is
brought down to the next entry of file2 and checked with
1st entry of file1 with 2nd entry of file2 in next perform
and the process is done till the end of records.

Is This Answer Correct ?    11 Yes 1 No

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

Answer / siri

IN COBOL
IF FILE1>FILE2
READ FILE2
IF FILE1<FILE2
READ FILE1
IF FILE1=FILE2
WRITE FILE3
READ FILE1
READ FILE2.......
IN JCL
//XSUM DD DSN=XSUM.MATCH
//SYSIN DD *
SORT FIELDS=COPY
SUM FIELDS=NONE,XSUM
/*

Is This Answer Correct ?    6 Yes 0 No

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

Answer / sreejith

firt read file1 move each record to table. at the end of
file1 start read file2. for each record read from file2
compare that record with all the elements from table. if it
match write that record to the output file. same procedure
follow for all the records from file2

Is This Answer Correct ?    16 Yes 12 No

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

Answer / kalone

First load both the files into 2 arrays and then sort them
on say ASC criteria and then take the first element from 1
file and compare with the element of other file , if
matches write into Outfile ,like wise we can keep on
reading & comparing till we get all the matching values in
the outfile.

Is This Answer Correct ?    6 Yes 5 No

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

Answer / bala

FILE SECTION.
FD OLD-MASTER
LABEL RECORDS ARE STANDARD.
01 OLD-MASTER-REC.
05 M-ACCT-NO PIC X(5).
05 AMOUNT-DUE PIC 9(4)V99.
05 PIC X(89).
FD TRANS-FILE
LABEL RECORDS ARE STANDARD.
01 TRANS-REC.
05 T-ACCT-NO PIC X(5).
05 AMT-TRANS-IN-CURRENT-PER PIC 9(4)V99.
05 PIC X(89).
FD NEW-MASTER
LABEL RECORDS ARE STANDARD.
01 NEW-MASTER-REC.
05 ACCT-NO-OUT PIC X(5).
05 AMOUNT-DUE-OUT PIC 9(4)V99.
05 PIC X(89).
WORKING-STORAGE SECTION.
PROCEDURE DIVISION.
100-MAIN-MODULE.
PERFORM 800-INITIALIZATION-RTN.
PERFORM 600-READ-MASTER.
PERFORM 700-READ-TRANS.
PERFORM 200-COMP-RTN
UNTIL M-ACCT-NO = HIGH-VALUES
AND
T-ACCT-NO = HIGH-VALUES
PERFORM 900-END-OF-JOB-RTN.
STOP RUN.
200-COMP-RTN.
EVALUATE TRUE
WHEN T-ACCT-NO = M-ACCT-NO
PERFORM 300-REGULAR-UPDATE
WHEN T-ACCT-NO < M-ACCT-NO
PERFORM 400-NEW-ACCOUNT
WHEN OTHER
PERFORM 500-NO-UPDATE
END-EVALUATE.
300-REGULAR-UPDATE.
MOVE OLD-MASTER-REC TO NEW-MASTER-REC
COMPUTE AMOUNT-DUE-OUT = AMT-TRANS-IN-CURRENT-PER
+ AMOUNT-DUE
WRITE NEW-MASTER-REC
PERFORM 600-READ-MASTER
PERFORM 700-READ-TRANS.
400-NEW-ACCOUNT.
MOVE SPACES TO NEW-MASTER-REC.
MOVE T-ACCT-NO TO ACCT-NO-OUT.
MOVE AMT-TRANS-IN-CURRENT-PER TO AMOUNT-DUE-OUT.
WRITE NEW-MASTER-REC.
PERFORM 700-READ-TRANS.
500-NO-UPDATE.
WRITE NEW-MASTER-REC FROM OLD-MASTER-REC.
PERFORM 600-READ-MASTER.
600-READ-MASTER.
READ OLD-MASTER
AT END
MOVE HIGH-VALUES TO M-ACCT-NO
END-READ.
700-READ-TRANS.
READ TRANS-FILE
AT END
MOVE HIGH-VALUES TO T-ACCT-NO
END-READ.
800-INITIALIZATION-RTN.
OPEN INPUT OLD-MASTER
TRANS-FILE.
OPEN OUTPUT NEW-MASTER.
900-END-OF-JOB-RTN.
CLOSE OLD-MASTER
TRANS-FILE
NEW-MASTER.

Hope this is useful.

Is This Answer Correct ?    2 Yes 2 No

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

Answer / ajay kumar ande

OPEN INPUT FILE1
OPEN INPUT FILE2
OPEN OUTPUT FILE3

MOVE 'N' TO EOF
PERFORM UNTIL EOF='S'
READ FILE1 AT END MOVE 'S' TO EOF
READ FILE2 AT END MOVE 'S' TO EOF

IF EMPNO1 = EMPNO2
MOVE
REC2 TO REC3
WRITE REC3
END-PERFORM.

CLOSE FILE1, FILE2, FILE3.

Is This Answer Correct ?    10 Yes 11 No

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

Answer / richa

from these evaluate i am able to get the matched records in
one file but if i want to write the unmatched record in the
spool area then how to track those unmatched records from
here

Is This Answer Correct ?    1 Yes 2 No

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

Answer / michar de papachuil

This might help you here but you have to Sort the two files
first before doing the match.

IF File1 = File2
PERFORM 2400-MATCH-BOTH-FILES THRU 2400-EXIT
PERFORM 2100-READ-FILE1 THRU 2100-EXIT
PERFORM 2200-READ-FILE2 THRU 2200-EXIT

ELSE

IF I-GROUP-SUBSYSTEM LESS THAN I-MODULE-SUBSYSTEM
PERFORM 2600-UNKNOWN-FILE1-VALUES THRU 2600-EXIT
PERFORM 2100-READ-FILE1 THRU 2100-EXIT
ELSE
PERFORM 2500-UNKNOWN-FILE2-VALUES THRU 2500-EXIT
PERFORM 2200-READ-FILE2 THRU 2200-EXIT
END-IF

Is This Answer Correct ?    0 Yes 1 No

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

Answer / anil t.

Using Merge

Is This Answer Correct ?    1 Yes 3 No

Post New Answer

More COBOL Interview Questions

2 input fles: 2 flat files, with different number of records. both are having unique key for each record and already sorted in ascending order . match these files using unique key and in output only matching key value has to be written. please procide cobol logic

0 Answers  


How to open and see copy book ?

3 Answers  


COMP-3 field occupy ?

8 Answers  


is it possible to declare index in cobol program? if it is not why its tell me pls

3 Answers  


can we display comp-3 variables. if we want to display what we have to do . give me one example

6 Answers   CGI, Deloitte,






can we declare occurs in 01 level?

2 Answers   Temenos,


COBOL Snippet: Tell where the control will when the below code execute IF (A=B) CONTINUE ELSE NEXT SENTENCE PERFORM <IMP-STMT> END-IF.

7 Answers   HCL,


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

9 Answers   IBM, iFlex, Wipro,


Which is not true about evaluate statement

0 Answers  


Can we move X(9) to 9(9). If yes what are the ways for doing this?

3 Answers  


Can we change the password using ALTER? anyone tried and changed?

0 Answers   IBM,


can anybody post me about file-aid and changemen tools pls and give me reference if any mainframe guys are there

0 Answers  


Categories