How to compare two fields used in dataset and check for dup

In this Mainframe Forum - You can post your queries on JCL, OS/390 JCL, MVS JCL, z/OS JCL, JES2 & JES3

Moderators: Frank Yaeger, DikDude, Moderator Group

Post Reply
balaryan
Member
Posts: 7
Joined: Thu Aug 14, 2014 9:41 am
Location: Chennai

How to compare two fields used in dataset and check for dup

Post by balaryan » Thu Aug 14, 2014 9:48 am

Hi All,

Good day. I am having an input file whose records are listed below.

811886,831910
811885,831911
811888,831913
811887,831914
811896,811896 -> both same
811895,811895 -> both same
811894,811894 -> both same
811893,811893 -> both same

Is there any way in JCL sort to compare two fields used in the data set and if both matches, we can treat that as duplicate and remove from the file or exclude in new SORTED file.

Kindly advice and need expert opinion on this.[/b]
B@L@

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Thu Aug 14, 2014 11:23 am

Not exactly expert advice, but have you looked at INCLUDE/OMIT COND=?
Last edited by William Collins on Sat Aug 23, 2014 2:13 pm, edited 1 time in total.

User avatar
Vamsi99
Active Member
Posts: 183
Joined: Wed Nov 05, 2008 11:20 am

Sort matching two files - slice or joinkeys

Post by Vamsi99 » Sat Aug 23, 2014 1:40 pm

This was discussed multiple times in the forum (Check DFSORT forum).
you may need to use slice or joinkeys.

Sample Requirement
------------------------
If any of the records from the input1 dataset (start pos 14 for 20) match ANY of the records from the input2 dataset (start pos 61 for 20) then I want to output from start pos 1 for 33 from the input1 dataset record and start pos 82 for 80 from the input2 dataset record to an output dataset called 'matched' (a single output record, not two output records).

Any unmatched/unpaired records from the input1 dataset (start pos 14 for 20) need to be output from start pos 1 for 33 from the input1 dataset record to an output dataset called 'nomatch1'

Any unmatched/unpaired records from the input2 dataset (start pos 61 for 20) need to be output from start pos 82 for 80 from the input2 dataset record to an output dataset called 'nomatch2'

Code: Select all

//S1  EXEC  PGM=SORT
//SYSOUT    DD  SYSOUT=*
//IN1 DD DSN=...  input file1 (FB/266)
//IN2 DD DSN=...  input file2 (FB/266)
//MATCHED DD DSN=...  output file1 (FB/266)
//NOMATCH1 DD DSN=...  output file2 (FB/266)
//NOMATCH2 DD DSN=...  output file3 (FB/266)
//SYSIN    DD    *
  JOINKEYS F1=IN1,FIELDS=(14,20,A)
  JOINKEYS F2=IN2,FIELDS=(61,20,A)
  JOIN UNPAIRED,F1,F2
  REFORMAT FIELDS=(F1:1,33,F2:82,80,?)
  OPTION COPY
  OUTFIL FNAMES=MATCHED,INCLUDE=(114,1,CH,EQ,C'B'),
    BUILD=(1,114,266:X)
  OUTFIL FNAMES=NOMATCH1,INCLUDE=(114,1,CH,EQ,C'1'),
    BUILD=(1,33,266:X)
  OUTFIL FNAMES=NOMATCH2,INCLUDE=(114,1,CH,EQ,C'2'),
    BUILD=(34,80,266:X)
/* 



other discussion topics in this forum....

http://www.mainframegurukul.com/ibmmain ... t6020.html


Regards,
Vamsi

p.s --> if you like my answer , please vote for my post.

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Sat Aug 23, 2014 2:29 pm

I think you've misunderstood the question (or I have). There is only one file involved, with two different fields which may contain the same value.

User avatar
Vamsi99
Active Member
Posts: 183
Joined: Wed Nov 05, 2008 11:20 am

INCLUDE OMIT COND

Post by Vamsi99 » Sat Aug 23, 2014 2:50 pm

Thanks William. It was my bad.

INCLUDE/OMIT COND might be the right way to go.

Still, he can use above solution (provided in my post) by providing same file as input file1 and input file2.

William Collins
Active Member
Posts: 732
Joined: Thu May 24, 2012 4:07 am

Post by William Collins » Sat Aug 23, 2014 3:46 pm

Yes, but it would use many more resources, so should be avoided for this example.

Gouti
Member
Posts: 1
Joined: Tue Nov 15, 2016 8:11 am

Post by Gouti » Tue Nov 15, 2016 8:15 am

Hi balaryan , Though the post is too old as 4years :P thought of replying for others who seek the same answer,, ;) I hope below logic can work for you :)

//SYSIN DD *
OPTION COPY
INCLUDE COND=(1,6,CH,NE,8,6,CH)
/*

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others