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?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

I have to write to a outfile where the number of records in that file should be the header of that file using IMS.. can anyone help me in this issue

2220


What are literals?

833


How arrays can be defined in COBOL?

819


Write a program that uses move corresponding.

860


What is the compute verb? How is it used?

843






How are the next sentence and continue different from each other?

994


Which mode is used to operate the sequential file?

908


How do we get current date from system with century in COBOL?

1045


What is rmode(24)

890


What are the different rules for performing sort operation?

939


What is static and dynamic call in cobol?

777


how to convert the recors form vsam file to db2 table tru file aid

2975


How do you get the data to code the BMS macro?

1681


How many sections are there in data division in COBOL?

875


Program A (Normal COBBAT) calling a B Program (DB2COBOL, COBBATDB which is using a VSAM file. its a dynamic call. How we will handle VSAM file decleration in our from JCL from where we are running A PGM. And should we have PLAN for A pGM also. if possible can some one post a sample JCL. Thanks for help in advance.

5404