There are 2 files. These 2 files contains some common (duplicate) records. How do you copy these common (matching) records into third file. Suggest the answer using COBOL as well as through JCL.

Questions by sekhargupta   answers by sekhargupta

Showing Answers 1 - 43 of 43 Answers

Using JCL : 
Step 1: using pgm SORT, sort and merge the two files
             SORTIN    DD file 1 (i/p file 1)

             SORTIN    DD file 2 (i/p file 2)

             SORTOUT DD file 3 (o/p file containing the sorted and merged recs of both the i/p files)

Step 2: Using SUM FIELDS = NONE,XSUM : the duplicates will be eliminated and written in to the file defined in the SORTXSUM DD step

Using COBOL :
Use the MERGE verb along with the OUTPUT PROCEDURE. In the OUTPUT PROCEDURE, code the logic for eliminating the duplicates and writing them in to an output file.

  Was this answer useful?  Yes

venkatesh

  • Sep 6th, 2007
 

You can use IEBCOMPR utility to solve this.

  Was this answer useful?  Yes

talluri

  • Jul 27th, 2011
 

//sortin dd dsn=a.b.file1,dsn=shr
// dd dsn=a.b.file2,dsn=shr
//sortout dd dsn=a.d.file3,dsn=old
//sysin dd *
sort fields=(1,3,ch,a)
sum fields=none,xsum
/*

is't write

  Was this answer useful?  Yes

Madhavi Chava

  • Jan 21st, 2012
 

Code
  1. //SORT1 EXEC PGM=SORT

  2. //SORTJNF1 DD *

  3. 00000111111 000001234567 LOCAL =====

  4. 00000333333 000003456789 LOCAL =====

  5. 00000555555 000005678901 EXTRN =====

  6. 00000666666 000006789012 EXTRN =====

  7. 00000777777 000007890123 LOCAL =====

  8. //SORTJNF2 DD *

  9. 00000222222 000002345678 ===== BCDEF

  10. 00000444444 000004567890 ===== DEFGH                                                                   00000666666 000006789012 ===== FGHIJ

  11. 00000888888 000008901234 ===== HIJKL

  12. 00000999999 000009012345 ===== JKLMN

  13. //SORTOUT DD SYSOUT=*

  14. //SYSOUT DD SYSOUT=*

  15. //SYSIN DD *

  16. JOINKEYS FILES=F1,FIELDS=(1,11,A,13,12,A)

  17. JOINKEYS FILES=F2,FIELDS=(1,11,A,13,12,A)

  18. REFORMAT FIELDS=(F1:1,31,F2:32,5)

  19. SORT FIELDS=COPY


output of the file3
00000666666 000006789012 EXTRN FGHIJ

  Was this answer useful?  Yes

Praful

  • Jan 31st, 2012
 

In COBOL :=>

Before execution get both the files in sorted order say Ascending.

In PGM use Evaluate statement as

Evaluate
when Rec_key_ file_1 = Rec_key_ file_2
Write rec.
read file1.
Read file2.
when Rec_key_ file_1 > Rec_key_ file_2
Read file2.
when Rec_key_ file_1 < Rec_key_ file_2
Read file 1.
End evalute.

  Was this answer useful?  Yes

Mallikarjun

  • Jul 24th, 2015
 

There is no KEY both are PS files.

  Was this answer useful?  Yes

gvk

  • Aug 5th, 2015
 

Merge both the files and then use SORT FIELDS=NONE,XSUM. Now, the SORTXSUM file would be containing the Matched records of both the files(Before merging).

  Was this answer useful?  Yes

chamundeswari

  • Dec 17th, 2015
 

How does join keys work internally?

  Was this answer useful?  Yes

gyanendra singh

  • Jul 7th, 2016
 

There are two ways:
First one, will be Join keys. In this case when you compare two file on keys (unique Identifier), it will create three files. Match records, Unmatched of F1 and Unmatched of F2. Your answer file will be match
Second method: Use ezytrieve program which has inbuilt MATCH and NO-MATCH control verb
Third Method: Cobol program using file matching logic.
F1= f2
F1 F1>F2 ( F1 and F2 are two files keys)
Only thing you need worry is cardinality between F1 and F2 ( 1:1,1:n,N:1 and M:N)

  Was this answer useful?  Yes

Raghava Pasupuleti

  • Jan 5th, 2017
 

Combination of internal and external sort in COBOL Program:

Step 1 : In COBOL program with simple sort logic using input file giving output file

Step 2 : Code the sort filter condition in control card to get non duplicate records

Step 3 : Add that control card in COBOL programs run JCL with control DD name (i am not able to recollect the Exact DD name)

  Was this answer useful?  Yes

Ramya

  • Feb 17th, 2017
 

This is a great answer.. But will you elaborate on how the code works here. This is simple merging right... Where does it check for the common records?

  Was this answer useful?  Yes

Arbazali

  • May 24th, 2017
 

JCL: We can use Sort Utility for doing this.
Sort fields = NONE,XSUM
In JCL you need to mention a file name with SORTXSUM as DD name.
This will copy the duplicate records from the input file and put it into SortXsum

  Was this answer useful?  Yes

raman gupta

  • May 26th, 2017
 

//STEP010 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SORTIN DD DSN=TEST.XSUM.INPUT,DISP=SHR
//SORTOUT DD DSN=TEST.XSUM.OUTPUT,DISP=SHR
//SORTXSUM DD DSN=TEST.XSUM.OUTPUT.XSUM,DISP=SHR
//SYSIN DD *
SORT FIELDS=(2,10,CH,A)
SUM FIELDS=NONE,XSUM

  Was this answer useful?  Yes

Lagnesh prithiviraj

  • Nov 21st, 2017
 

using ICETOOL, Below syntax will get just all duplicates if duplicates are decided based first eight charactes
SELECT FROM(SORTIN) TO(SORTOUT) ON(1,8,CH) ALLDUPS DISCARD(SORTXSUM)

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions