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

1.What is the limit of linkage section?

4 Answers  


How many variables can be declared in w-s section.?

2 Answers  


given the following piece of code: CALL SUB-PGM USING A, B, C. CALL SUB-PGM USING A, C, C. (a) Both CALL statements will always produce same result. (d) Both CALL statements may produce different result. (c) Compile-time error because SUB-PGM is a dataname. (d) Compile-time error because A, B, C are used twice.

2 Answers   TCS,


consider the following PROCEDURE DIVISION entry OPEN EXTEND IN-FILE identify the correct statement a.organization of IN-FILE is sequential and records can be added in the beginning b.organization of IN-FILE is sequential and records can be added in the end c.organization of IN-FILE is indexed and records can be added in the beginning d.organization of IN-FILE is indexed and records can be added in the end

3 Answers   TCS,


soc-7 is a bad data,invalid data. when ever we are moving the alphabets in the position of numeric then we got this abend. so my question is if o1 ws-data pic 9(1) value passing the alphabet some x. then we got soc-7 or not? i want clarification ?

7 Answers   CitiGroup, IBM,






If we put three reads in COBOL in the same para one after the other, to read a PS file,will it read the same record thrice or it will read three records sequentially? For example : Input File 01 02 03 Para 900 Read infile Display Infile rec Read infile Display infile rec Read infile Display infile rec. What will be the output?

2 Answers  


Hi All, how is sign is stored in S9(17) comp-3 variable. Answer with an Example will be of great help.

5 Answers   EDS,


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

0 Answers  


how can u redefine picx(10) with pic 9(6).

3 Answers   TCS,


Have you used the sort in your project?for this type of questions any working on real time project give the eg. with real time scenario.

0 Answers   IBM,


How to recover a deleted source physical file from library?

1 Answers   HCL,


what is s013u000 for?

1 Answers   Hewitt,


Categories