IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Compare two records in the same ps file


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sureshpathi10

Active User


Joined: 03 May 2010
Posts: 154
Location: Kuala Lumpur

PostPosted: Thu Dec 19, 2013 8:58 am
Reply with quote

I've a requirement to create two output files from one single file.

Code:

ID             CODE
11111          AAAA
11111          BBBB
11111          CCCC
11111          EEEE
22222          AAAA
22222          CCCC
22222          DDDD
22222          EEEE
22222          FFFF


From the above file,
File 1 should contain:
1. Same ID with code 'AAAA' AND 'BBBB'
2. Same ID with code 'CCCC' AND 'DDDD'
2. Same ID with code 'EEEE' AND 'FFFF'

File 2 should contain all other non-matched records

output should be
File 1
Code:

ID             CODE
11111          AAAA
11111          BBBB
22222          CCCC
22222          DDDD
22222          EEEE
22222          FFFF


File 2

Code:

ID             CODE
11111          CCCC
11111          EEEE
22222          AAAA


Any help would be greatly appreciated.
Back to top
View user's profile Send private message
gcicchet

Senior Member


Joined: 28 Jul 2006
Posts: 1702
Location: Australia

PostPosted: Thu Dec 19, 2013 11:58 am
Reply with quote

Hi,

Can there be duplicate CODEs within the same ID ?

Are the wanted CODEs consecutively in the file ?


Gerry
Back to top
View user's profile Send private message
sureshpathi10

Active User


Joined: 03 May 2010
Posts: 154
Location: Kuala Lumpur

PostPosted: Thu Dec 19, 2013 12:02 pm
Reply with quote

Mr. Gcicchet

1. Yes. there may be duplicate CODE's within same ID.
2. The file is sorted by ID then CODE.
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Thu Dec 19, 2013 12:41 pm
Reply with quote

Hi Suresh,

How many different codes do you expect?
Back to top
View user's profile Send private message
sureshpathi10

Active User


Joined: 03 May 2010
Posts: 154
Location: Kuala Lumpur

PostPosted: Thu Dec 19, 2013 12:53 pm
Reply with quote

There are only 6 CODE's. They are
AAAA
BBBB
CCCC
DDDD
EEEE
FFFF
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Dec 19, 2013 2:03 pm
Reply with quote

If there can be duplicate codes within the same ID, please show that in your sample input with the expected output.
Back to top
View user's profile Send private message
sureshpathi10

Active User


Joined: 03 May 2010
Posts: 154
Location: Kuala Lumpur

PostPosted: Thu Dec 19, 2013 2:11 pm
Reply with quote

Hi Bill,

AAAA & BBBB is one set, so are CCCC & DDDD and EEEE & FFFF.
All the records have set should come in file 1. All others should be written to file1.

if input file contains
11111 AAAA
11111 AAAA
11111 AAAA
11111 BBBB
11111 BBBB
22222 BBBB

Then, File 1 should be
11111 AAAA
11111 AAAA
11111 BBBB
11111 BBBB

File 2 should be
11111 AAAA
22222 BBBB

Code 'AAAA' & 'BBBB' are 1 set. One ID 11111 with code 'AAAA' doesn't have its set. so it should come in file2. So is the last record.

I hope, I'm not confusing more. Thanks all for your efforts.
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Thu Dec 19, 2013 2:37 pm
Reply with quote

What is the sort product and version you are using?
Back to top
View user's profile Send private message
sureshpathi10

Active User


Joined: 03 May 2010
Posts: 154
Location: Kuala Lumpur

PostPosted: Thu Dec 19, 2013 2:47 pm
Reply with quote

Hi Pandora,

I'm using Z/OS DFSORT V1R10.

ICE201I H RECORD TYPE (October, 2010 PTF and are completely up to date on DFSORT functional PTFs )

Please let me know if anything missing or I understood your question wrongly.
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Thu Dec 19, 2013 9:54 pm
Reply with quote

Try this

Code:
//STEP0100 EXEC PGM=SORT
//SYSOUT   DD SYSOUT=*
//INA      DD *
11111          AAAA
11111          AAAA
11111          AAAA
11111          BBBB
11111          BBBB
22222          BBBB
//INB      DD *
11111          AAAA
11111          AAAA
11111          AAAA
11111          BBBB
11111          BBBB
22222          BBBB
//SORTOUT  DD DSN=&&TEMP,DISP=(MOD,PASS),SPACE=(CYL,(1,1),RLSE)
//OUT1     DD SYSOUT=*
//OUT2     DD SYSOUT=*
//SYSIN    DD *
  OPTION COPY
  JOINKEYS F1=INA,FIELDS=(28,3,A,22,2,A,1,5,A)
  JOINKEYS F2=INB,FIELDS=(28,3,A,22,2,A,1,5,A)
  JOIN UNPAIRED F1,F2
  REFORMAT FIELDS=(F1:1,30,?,F2:1,30)
* INREC IFTHEN=(WHEN=(31,1,CH,EQ,C'B'),BUILD=(1,30,C'B',/,32,30,C'B')),
*       IFTHEN=(WHEN=(31,1,CH,EQ,C'1'),BUILD=(32,30,C'I'))
  OUTFIL INCLUDE=(31,1,CH,EQ,C'B',OR,31,1,CH,EQ,C'1',
         OR,31,1,CH,EQ,C'2'),
         BUILD=(1,31,/,1:32,30,31,1)
* OUTFIL FNAMES=OUT2,INCLUDE=(31,1,CH,EQ,C'1'),BUILD=(1,30)
//*
//JNF1CNTL DD *
  INCLUDE COND=(16,4,CH,EQ,C'AAAA',OR,16,4,CH,EQ,C'CCCC',OR,
                16,4,CH,EQ,C'EEEE')
  INREC IFTHEN=(WHEN=INIT,BUILD=(1,20,28:SEQNUM,3,ZD)),
        IFTHEN=(WHEN=(16,4,CH,EQ,C'AAAA'),BUILD=(1,20,X,C'AB',
                                        28:28,3)),
        IFTHEN=(WHEN=(16,4,CH,EQ,C'CCCC'),BUILD=(1,20,X,C'CD',
                                        28:28,3)),
        IFTHEN=(WHEN=(16,4,CH,EQ,C'EEEE'),BUILD=(1,20,X,C'EF',
                                        28:28,3))
//*
//JNF2CNTL DD *
  INCLUDE COND=(16,4,CH,EQ,C'BBBB',OR,16,4,CH,EQ,C'DDDD',OR,
                16,4,CH,EQ,C'FFFF')
  INREC IFTHEN=(WHEN=INIT,BUILD=(1,20,28:SEQNUM,3,ZD)),
        IFTHEN=(WHEN=(16,4,CH,EQ,C'BBBB'),BUILD=(1,20,X,C'AB',
                                          28:28,3)),
        IFTHEN=(WHEN=(16,4,CH,EQ,C'DDDD'),BUILD=(1,20,X,C'CD',
                                          28:28,3)),
        IFTHEN=(WHEN=(16,4,CH,EQ,C'FFFF'),BUILD=(1,20,X,C'EF',
                                          28:28,3))
//*
//STEP0200 EXEC PGM=SORT
//SORTIN   DD DSN=&&TEMP,DISP=(MOD,PASS)
//SORTOUT DD SYSOUT=*
//OUT1       DD SYSOUT=*
//OUT2       DD SYSOUT=*
//SYSOUT  DD SYSOUT=*
//SYSIN   DD *
  OMIT COND=(1,20,CH,EQ,C' ')
  SORT FIELDS=(1,5,CH,A,16,4,CH,A,22,10,CH,A)
  SUM FIELDS=NONE
  OUTFIL FNAMES=OUT1,INCLUDE=(31,1,CH,EQ,C'B'),BUILD=(1,20)
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Dec 20, 2013 12:49 am
Reply with quote

Pandora-box,

The data is already sorted. By splitting the data in JNFnCNTL as you do you can make use of the sort order. Use IFTHEN=(WHEN=GROUP with KEYBEGIN (H has it) to give a sequence number as the fourth key (first two keys are the original data, third is the "AB" etc, fourth the sequence number).

B match-marker gives one file, anything else gives the other file. Remember to drop the extension.

One step, no sorts.

When extending records, try to use OVERLAY where possible. If better identifies what is happening, to the next person along, and at times will be more efficient than BUILD (if it doesn't "build" as it extends the record, but OVERLAYs existing data, it will save shuffling stuff about).
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Fri Dec 20, 2013 1:12 am
Reply with quote

Thanks Bill will try that for my own collection

Just getting to used to speed after quiet some disappointing performances icon_biggrin.gif
Back to top
View user's profile Send private message
gcicchet

Senior Member


Joined: 28 Jul 2006
Posts: 1702
Location: Australia

PostPosted: Fri Dec 20, 2013 5:58 am
Reply with quote

Hi Pandora-Box,

what is the result using this data ?
Code:
11111    01YES AAAA
11111    02YES AAAA
11111          AAAA
11111    01YES BBBB
11111    02YES BBBB
11111          CCCC
11111          EEEE
22222          AAAA
22222    01YES CCCC
22222          CCCC
22222          CCCC
22222    01YES DDDD
22222    02YES EEEE
22222    02YES FFFF
22222          FFFF
22222          FFFF
22222          FFFF
22222          FFFF



Using the above data, this is the result I'm getting

Code:
11111    01YES AAAA 
11111    02YES AAAA 
11111    01YES BBBB 
11111    02YES BBBB 
instead of
Code:
11111    01YES AAAA
11111    01YES BBBB
11111    02YES AAAA
11111    02YES BBBB
22222    01YES CCCC
22222    01YES DDDD
22222    02YES EEEE
22222    02YES FFFF


Gerry
Back to top
View user's profile Send private message
sureshpathi10

Active User


Joined: 03 May 2010
Posts: 154
Location: Kuala Lumpur

PostPosted: Fri Dec 20, 2013 7:23 am
Reply with quote

Hi All,

First of all I want to thank everyone for all your efforts.

Pandora-Box - I've single file that needs to be split-ed into 2 files.
Back to top
View user's profile Send private message
gcicchet

Senior Member


Joined: 28 Jul 2006
Posts: 1702
Location: Australia

PostPosted: Fri Dec 20, 2013 7:26 am
Reply with quote

Hi,

a different approach
Code:
//STEP0100 EXEC PGM=ICETOOL     
//TOOLMSG  DD SYSOUT=*           
//DFSMSG   DD SYSOUT=*           
//IN       DD *                 
11111    01YES AAAA             
11111    02YES AAAA             
11111          AAAA             
11111    01YES BBBB             
11111    02YES BBBB             
11111          CCCC             
11111          EEEE             
22222          AAAA             
22222    01YES CCCC             
22222          CCCC             
22222          CCCC             
22222    01YES DDDD             
22222    02YES EEEE             
22222    02YES FFFF             
22222          FFFF             
22222          FFFF             
22222          FFFF             
22222          FFFF                                         
/*                                                           
//T1       DD DSN=&&T1,DISP=(,PASS,DELETE),                 
//            UNIT=SYSDA,SPACE=(TRK,(10,5),RLSE)             
//OUT      DD SYSOUT=*                                       
//OTHER    DD SYSOUT=*                                       
//SYSOUT   DD SYSOUT=*                                       
//TOOLIN   DD *                                             
  COPY FROM(IN) TO(T1) USING(CTL1)                           
  SELECT FROM(T1) TO(OUT) ON(01,5,CH) -                     
                          ON(22,2,CH) -                     
                          ON(41,8,CH) EQUAL(2) -             
  DISCARD(OTHER)                                             
//CTL1CNTL DD *                                             
  INREC IFTHEN=(WHEN=INIT,                                   
                OVERLAY=(31:SEQNUM,8,ZD,                     
                         41:SEQNUM,8,ZD,RESTART=(16,4))),   
        IFTHEN=(WHEN=(16,4,CH,EQ,C'AAAA'),                   
                OVERLAY=(22:C'AB')),                         
        IFTHEN=(WHEN=(16,4,CH,EQ,C'BBBB'),                   
                OVERLAY=(22:C'AB')),                         
        IFTHEN=(WHEN=(16,4,CH,EQ,C'CCCC'),           
                OVERLAY=(22:C'CD')),                 
        IFTHEN=(WHEN=(16,4,CH,EQ,C'DDDD'),           
                OVERLAY=(22:C'CD')),                 
        IFTHEN=(WHEN=(16,4,CH,EQ,C'EEEE'),           
                OVERLAY=(22:C'EF')),                 
        IFTHEN=(WHEN=(16,4,CH,EQ,C'FFFF'),           
                OVERLAY=(22:C'EF'))                 
 SORT FIELDS=(1,5,BI,A,22,2,BI,A,41,8,BI,A,16,4,BI,A)
/*


Gerry
Back to top
View user's profile Send private message
sureshpathi10

Active User


Joined: 03 May 2010
Posts: 154
Location: Kuala Lumpur

PostPosted: Fri Dec 20, 2013 7:54 am
Reply with quote

Superb Mr.Gcicchet.

Your CTL1 card meets my requirement. Thank you so much.

I was trying with same kind of approach but didn't include the SEQNUM, which caused same ID with same CODE came in File1.

Thanks to Pandora-Box and Bill.

You guys saved my day. Greatly appreciated.
Back to top
View user's profile Send private message
sureshpathi10

Active User


Joined: 03 May 2010
Posts: 154
Location: Kuala Lumpur

PostPosted: Fri Dec 20, 2013 9:02 am
Reply with quote

Hi All,

A small change, May be silly yet, needs to be spotted for anyone who needed it in future.

When I use Gerry's JOB, I got proper output but with SEQNUMs in the files. So here is the JOB with small modification for output files without SEQNUMs.

Code:

//STEP0100 EXEC PGM=ICETOOL
//TOOLMSG  DD SYSOUT=*     
//DFSMSG   DD SYSOUT=*     
//IN       DD *           
11111    01YES AAAA       
11111    02YES AAAA       
11111          AAAA       
11111    01YES BBBB       
11111    02YES BBBB       
11111          CCCC       
11111          EEEE       
22222          AAAA       
22222    01YES CCCC       
22222          CCCC       
22222          CCCC       
22222    01YES DDDD       
22222    02YES EEEE       
22222    02YES FFFF       
22222          FFFF                                     
22222          FFFF                                     
22222          FFFF                                     
22222          FFFF                                     
/*                                                       
//T1       DD DSN=&&T1,DISP=(,PASS,DELETE),             
//            UNIT=SYSDA,SPACE=(TRK,(10,5),RLSE)         
//OUT      DD SYSOUT=*                                   
//OTHER    DD SYSOUT=*                                   
//SYSOUT   DD SYSOUT=*                                   
//TOOLIN   DD *                                         
  COPY FROM(IN) TO(T1) USING(CTL1)                       
  SELECT FROM(T1) TO(OUT) ON(01,5,CH) -                 
                          ON(22,2,CH) -                 
                          ON(41,8,CH) EQUAL(2) -         
  DISCARD(OTHER) USING(CTL2)                             
//CTL1CNTL DD *                                         
  INREC IFTHEN=(WHEN=INIT,                               
                OVERLAY=(31:SEQNUM,8,ZD,                 
                         41:SEQNUM,8,ZD,RESTART=(16,4))),
        IFTHEN=(WHEN=(16,4,CH,EQ,C'AAAA'),               
                OVERLAY=(22:C'AB')),                 
        IFTHEN=(WHEN=(16,4,CH,EQ,C'BBBB'),           
                OVERLAY=(22:C'AB')),                 
        IFTHEN=(WHEN=(16,4,CH,EQ,C'CCCC'),           
                OVERLAY=(22:C'CD')),                 
        IFTHEN=(WHEN=(16,4,CH,EQ,C'DDDD'),           
                OVERLAY=(22:C'CD')),                 
        IFTHEN=(WHEN=(16,4,CH,EQ,C'EEEE'),           
                OVERLAY=(22:C'EF')),                 
        IFTHEN=(WHEN=(16,4,CH,EQ,C'FFFF'),           
                OVERLAY=(22:C'EF'))                 
 SORT FIELDS=(1,5,BI,A,22,2,BI,A,41,8,BI,A,16,4,BI,A)
//CTL2CNTL DD *                                     
  OUTFIL FNAMES=OUT,BUILD=(1,19) 
  OUTFIL FNAMES=OTHER,BUILD=(1,19)                             
/*                                                   


Thanks once again Guys.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
No new posts Access to non cataloged VSAM file JCL & VSAM 18
Search our Forums:

Back to Top