Page 1 of 1

compare 2 lines from 1 file

PostPosted: Tue Mar 02, 2010 6:20 pm
by retep
I have the following problem.

I have a file with the following content:
A TEST 0Y
A TEST 0N
A TEST 1Y
A TEST 2Y
A TEST 2N
A TEST 3N
A TEST 4Y
A TEST 5N


Now, I expect at the end only the following lines at the output:
A TEST 0Y
A TEST 1Y
A TEST 2Y
A TEST 3N
A TEST 4Y
A TEST 5N


what syncsort coding do I need?

Re: compare 2 lines from 1 file

PostPosted: Tue Mar 02, 2010 11:40 pm
by Alissa Margulies
Here is a SyncSort for z/OS job that will produce the requested output:
//SORT  EXEC PGM=SORT           
//SORTOUT DD SYSOUT=*           
//SORTIN  DD *                   
A TEST 0Y                       
A TEST 0N                       
A TEST 1Y                       
A TEST 2Y                       
A TEST 2N                       
A TEST 3N                       
A TEST 4Y                       
A TEST 5N                       
//SYSOUT  DD SYSOUT=*           
//SYSIN   DD *                   
   SORT FIELDS=(1,8,CH,A),EQUALS
   SUM FIELDS=NONE   
/*

Re: compare 2 lines from 1 file

PostPosted: Wed Mar 03, 2010 1:54 pm
by retep
Thank you very much for the statement - it works very good - when the records are in this special sortorder.

unfortunatly is my example only the half truth - my records can (and, as i understand murphy), will be unsorted.

like this:
A TEST 0N
A TEST 2Y
A TEST 0Y
A TEST 1Y
A TEST 0N
A TEST 5Y
A TEST 4N
A TEST 2Y
A TEST 2N
A TEST 5N
A TEST 3N
A TEST 4Y

at the moment i do in the first step (exec) a sort like this:
SORT FIELDS=(1,8,CH,D)

afterwards i am running your sort.

this work very good, but: can i shorten these 2 steps in 1?

thank you very much for your help !!!

Re: compare 2 lines from 1 file

PostPosted: Wed Mar 03, 2010 9:44 pm
by Alissa Margulies
There is a SORT performed in my example on the same field. Why are you sorting in descending order and then resorting in ascending order in my step. Either remove the first sort step and just run my step, or remove your step and modify my step to reflect descending instead of ascending. Is there something I am missing here?

Re: compare 2 lines from 1 file

PostPosted: Thu Mar 04, 2010 7:04 pm
by retep
sorry for my wrong details.

1st: i have a file which contains the following UNSORTED data content:
A TEST 0N
A TEST 2Y
A TEST 0Y
A TEST 1Y
A TEST 0N
A TEST 5Y
A TEST 6N
A TEST 4N
A TEST 2Y
A TEST 2N
A TEST 5N
A TEST 3N
A TEST 4Y

2nd: i want to have the following result:
A TEST 6N
A TEST 5Y
A TEST 4Y
A TEST 3N
A TEST 2Y
A TEST 1Y
A TEST 0Y

when POS(1:8) are equals take the first record with 'Y' in POS(9:1), else take the first record with 'N' in POS(9:1), the remaining matching records can be discarded.

i hope this was more clear.

thank you for your patience!

Re: compare 2 lines from 1 file

PostPosted: Thu Mar 04, 2010 9:19 pm
by Alissa Margulies
Here is a SyncSort for z/OS 1.3 job that will do what you asked:
//SORT  EXEC PGM=SORT 
//SORTOUT DD SYSOUT=* 
//SORTIN  DD *         
A TEST 0N             
A TEST 2Y             
A TEST 0Y             
A TEST 1Y             
A TEST 0N             
A TEST 5Y             
A TEST 6N             
A TEST 4N             
A TEST 2Y             
A TEST 2N             
A TEST 5N             
A TEST 3N             
A TEST 4Y             
//SYSOUT  DD SYSOUT=* 
//SYSIN   DD *                                                     
   SORT FIELDS=(1,8,CH,A,9,1,CH,D)                                 
   OUTREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,1,ZD,RESTART=(1,8)))
   OUTFIL INCLUDE=(81,1,ZD,EQ,1),BUILD=(1,80)                     
/*     

Here is the output produced from the above job:
A TEST 0Y
A TEST 1Y
A TEST 2Y
A TEST 3N
A TEST 4Y
A TEST 5Y
A TEST 6N

Re: compare 2 lines from 1 file

PostPosted: Thu Mar 04, 2010 9:23 pm
by Alissa Margulies
Here is another alternative:
//SYSIN   DD *             
   SORT FIELDS=(1,9,CH,A)   
   OUTFIL SECTIONS=(1,8,   
          TRAILER3=(1,80)),
          REMOVECC,NODETAIL
/*                         

Re: compare 2 lines from 1 file

PostPosted: Thu Mar 11, 2010 8:48 pm
by retep
thanx a lot, the second one works phantasic!

:D