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

Write a program to enter and display the names of students in a class using the occurs clause.

0 Answers  


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

9 Answers   IBM, iFlex, Wipro,


i have a sequencial file contains multiple records, i want to extract one row which contains various fields like order number,date,warehouse,.ect.. in to the another file by accepting the order number from jcl. how can i do it. pls help me..

4 Answers   CGI,


How do you define a sort file in JCL that runs the COBOL program?

6 Answers   Syntel,


When is a scope terminator mandatory?

3 Answers  






State the various causes of s0c1, s0c5 and s0c7.

0 Answers  


What R 2 of the common forms of the EVALUATE STATEMENT ?

1 Answers   Cap Gemini,


I hv ten records in ps file and i hv say some 15 records in vsam file .i hv empno and age in ps file n empno,empname,dept n desig in vsam file. i hv 2 read the ps file n check wid matching empno in vsam file and then insert all fields from ps and vsam into db2 table....plz help in writin the procedure division

1 Answers  


What are options have been removed in COBOL 11?

1 Answers  


What is the default value of DISP for temp datasets

5 Answers   IBM,


Explain the difference between an internal and an external sort, the pros and cons, internal sort syntax etc.

3 Answers  


How to recover a deleted source physical file from library?

1 Answers   HCL,


Categories