Suppose, file A has 100 records and file B has 500 records. We
want to write records common to both A and B into file C and
records which are present only in either A or B into another file D.
What should be the logic of Cobol program to achieve this?

Answers were Sorted based on User's Feedback



Suppose, file A has 100 records and file B has 500 records. We want to write records common to both..

Answer / m

correction to #3
sort files Asc

if f1 = f2
move file1-rec to file3-rec. write file3-rec
read f1 & f2.
if f1 < f2
move file1-rec to file4-rec. write file4-rec.
read f1.
if f1 > f2
move file2-rec to file4-rec. write file4-rec
read f2.

Is This Answer Correct ?    11 Yes 1 No

Suppose, file A has 100 records and file B has 500 records. We want to write records common to both..

Answer / karan

If we do not want to go with cobol then it can be easily
done with SORT, ICETOOL( Splice option) which i feel is
faster and simpler instead of writing a compare program.
If there is a compultion to use a cobol pgm then soln will
be -
PERFORM untill (EOF A and EOF B)
if f1 = f2
move file1-rec to file3-rec. write file3-rec
read f1 & f2.
if f1 < f2
move file1-rec to file4-rec. write file4-rec.
read f1.
if f1 > f2
move file2-rec to file4-rec. write file4-rec
read f2.
END PERFORM

IF EOF A and not EOF B
PERFORM until EOF B
move move file2-rec to file4-rec.
write file4-rec
read f2.
END PERFORM
ElSE
IF EOF B and not EOF A
PERFORM until EOF A
move move file1-rec to file4-rec.
write file4-rec
read f1.
END PERFORM
END

note: files should be in sorted order ASC before program
runs.
This is a generic solution to al such compare programs.

Is This Answer Correct ?    5 Yes 1 No

Suppose, file A has 100 records and file B has 500 records. We want to write records common to both..

Answer / suresh

sort the file by using key...and perform matching logic

Is This Answer Correct ?    0 Yes 0 No

Suppose, file A has 100 records and file B has 500 records. We want to write records common to both..

Answer / shrik

Sort both file A and B using the Key in ascending order..
Then read File A and B..
Compare records read frm A and B
If found Equal write into File C (common records)
If NOT write into file D

Is This Answer Correct ?    6 Yes 8 No

Suppose, file A has 100 records and file B has 500 records. We want to write records common to both..

Answer / hardik dave

Use SYNCSORT and you will get all matching records in one
file and all those non matching records in another. Just
read more on SYNCSORT and you will be clear.

Is This Answer Correct ?    3 Yes 6 No

Suppose, file A has 100 records and file B has 500 records. We want to write records common to both..

Answer / anji

I think this is partially right. after accessing 100 records
program is abended. And how to send remaining B file records
into file D.. send me ans plz..

Is This Answer Correct ?    0 Yes 3 No

Suppose, file A has 100 records and file B has 500 records. We want to write records common to both..

Answer / vinod

if f1 = f2
move file1-rec to file3-rec
write file3-rec
if f1 < f2
move file2-rec to file4-rec
write file4-rec.
if f1 > f2
move file1rec to file4-rec
write file4-rec

Is This Answer Correct ?    2 Yes 6 No

Post New Answer

More COBOL Interview Questions

WE HAVE 5 DIFFERENT RECORDING MODE IN COBOL.FIXED, FIXEDBLOCK, VARIABLE, VARIABLEBLOCK AND UNDEFINED. WHAT IS THE DIFFERENCE AMONG ALL AND WHICH TYPE OF FORMAT SHOULD BE USED WHEN

3 Answers   Infosys,


how do u list the abended jobs?

1 Answers   IBM,


In which area will you utilize 88 level items in cobol?

0 Answers  


How to get the last record in vsam file in cluster? And how can you get the ksds file records into cobol program?

0 Answers  


in real time what is the suitable exp where in-stream procedure is better then catalog procedure.

1 Answers  






i Want All cobol ERROR codes?

4 Answers   HCL, IBM,


I have a variable account-number declared as comp-3, s9(10) comp-3 in a file. How do i find a particular account number say 123456 in that file?

3 Answers  


How to remove the spaces at end of each record in the output file Via COBOL program? note: The file has a VB length

3 Answers   TCS,


What is the difference between working storage copybook and linkage section copybook?

5 Answers   TCS,


How do you set a return code to the JCL from a COBOL program?

4 Answers  


WHAT IS SOC3?HOW IT CAN BE RESOLVED?

1 Answers  


Determine the total no of bytes in the following. 01 rec1. 02 a pic x(6) 02 b redefines a. 03 c occus 6 times pic 9. 02 d occurs 6 times pic 9. 03 e pic x(5) 03 f pic 999.

12 Answers  


Categories