sort accending depends on a field value



IBM's flagship sort product DFSORT for sorting, merging, copying, data manipulation and reporting. Includes ICETOOL and ICEGENER

sort accending depends on a field value

Postby helen2000 » Thu Aug 16, 2012 2:41 am

hello, I have a file with 3 fields (AA, SIN, BN), I sort the records as the following rules:
if AA=60 , sort on field SIN; if AA=61, sort on field BN, for example:
the source file is:
AA SIN BN
61 555 777
60 222 111
61 333 555
60 444 666
after sort should be :
AA SIN BN
61 333 555
60 222 111
61 555 777
60 444 666
thanks in advance,

Helen
helen2000
 
Posts: 80
Joined: Sat Aug 08, 2009 9:44 pm
Has thanked: 0 time
Been thanked: 0 time

Re: sort accending depends on a field value

 

Re: sort accending depends on a field value

Postby BillyBoyo » Thu Aug 16, 2012 4:26 am

LRECL and RECFM? Positions of fields?

It is quite simple. Add a new field, within sort, to your record. Put a value in this field depending on the AA value. Sort the file on the new field. Ignore the new field for output as no longer required.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: sort accending depends on a field value

Postby helen2000 » Thu Aug 16, 2012 6:53 pm

thanks for your useful information,

sorry, I make a mistake, should be:
If the before sort file is like this:
AA SIN BN
61 555 555
60 222 111
61 333 777
60 444 666


The result I want is like this:
AA SIN BN
60 222 111
60 444 666
61 555 555
61 333 777

Sort by: 1. AA
2. If AA=60 then sort by SIN
If AA=61 then sort by BN
helen2000
 
Posts: 80
Joined: Sat Aug 08, 2009 9:44 pm
Has thanked: 0 time
Been thanked: 0 time

Re: sort accending depends on a field value

Postby BillyBoyo » Thu Aug 16, 2012 6:55 pm

You missed the lrecl/recfm information.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: sort accending depends on a field value

Postby helen2000 » Thu Aug 16, 2012 8:01 pm

sorry, Mr. BIllyboyo, LRECL=80, RECFM=FB, I have a solution for the sort, but it's not a better one, as I have to have 2 times sort,


1: first sort by AA, SIN
2: condition sort by BN, ex, include cond=(1,2,ch,eq,c’61’) sort fields=(25,10,ch,A)
anybody can sort just one time for the issue, thanks,
helen2000
 
Posts: 80
Joined: Sat Aug 08, 2009 9:44 pm
Has thanked: 0 time
Been thanked: 0 time

Re: sort accending depends on a field value

Postby dick scherrer » Thu Aug 16, 2012 8:49 pm

Hello,

It is quite simple. Add a new field, within sort, to your record. Put a value in this field depending on the AA value. Sort the file on the new field. Ignore the new field for output as no longer required.
Please re-read this from BB's first reply. This explains how to get what you want in one pass, i believe . . .
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Re: sort accending depends on a field value

Postby skolusu » Thu Aug 16, 2012 9:25 pm

helen,

Assuming that SIN starts in position 15 for 10 bytes and BIN starts in position 25 for 10 bytes, the following DFSORT JCL will give you the desired results. By default we pick the sort field as SIN and only for records with 61 in pos 1 we pick BIN as sort field.

//STEP0100 EXEC PGM=SORT                             
//SYSOUT   DD SYSOUT=*                               
//SORTIN   DD *                                     
----+----1----+----2----+----3----+----4----+----5---
61            555       555                         
60            222       111                         
61            333       777                         
60            444       666                         
//SORTOUT  DD SYSOUT=*                               
//SYSIN    DD *                                     
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:15,10)),       
  IFTHEN=(WHEN=(1,2,CH,EQ,C'61'),OVERLAY=(81:25,10))
  SORT FIELDS=(81,10,CH,A),EQUALS
  OUTREC BUILD=(1,80)                   
//*
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
skolusu
 
Posts: 586
Joined: Wed Apr 02, 2008 10:38 pm
Has thanked: 0 time
Been thanked: 39 times

Re: sort accending depends on a field value

Postby helen2000 » Fri Aug 17, 2012 4:43 am

thank you for your help, but still problem,
jcl is as following:
000019 //SORTIN  DD DSN=MP.TESTIN,DISP=SHR
000020 //SORTOUT DD DSN=MP.TESTOUT,
000021 //           DISP=(NEW,CATLG,DELETE),
000022 //           UNIT=SYSDA,SPACE=(CYL,(20,50),RLSE)
000023 //SYSIN  DD *
000024   INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:15,10)),
000025   IFTHEN=(WHEN=(1,2,CH,EQ,C'61'),OVERLAY=(81:25,10))
000026   SORT FIELDS=(81,10,CH,A),EQUALS
000027   OUTREC BUILD=(1,80)
000028 //*


my input file is:
000001 61            555       555
000002 60            222       111
000003 61            333       777
000004 60            444       666
000005 60            555       222
000006 60            111       123
000007 61            546       211

output is:
000001 60            111       123
000002 60            222       111
000003 61            333       777
000004 60            444       666
000005 61            546       211
000006 61            555       555
000007 60            555       222


but my expected output is:

000001 60            111       123
000002 60            222       111
000004 60            444       666
000007 60            555       222
000005 61            546       211
000006 61            555       555
000003 61            333       777


thanks again,

helen
helen2000
 
Posts: 80
Joined: Sat Aug 08, 2009 9:44 pm
Has thanked: 0 time
Been thanked: 0 time

Re: sort accending depends on a field value

Postby BillyBoyo » Fri Aug 17, 2012 6:20 am

Is it so much trouble to get to

  SORT FIELDS=(1,2,CH,A,81,10,CH,A),EQUALS


?
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: sort accending depends on a field value

Postby dick scherrer » Fri Aug 17, 2012 7:16 am

Hi Helen,

Do notice that your control statements do not sort on the 60/61 field. . .

Run what BB has provided and let us know. . .
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6304
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 91 times

Next

Return to DFSORT/ICETOOL/ICEGENER

 


  • Related topics
    Replies
    Views
    Last post