Page 1 of 1

Need some help to sort with a group

PostPosted: Tue May 06, 2014 2:40 am
by akanchu
I have the below file where in 1 thru 10 bytes are values of 1 set .
Was trying to sort the data based on position 49 onwards for 50 bytes.
015258642   01EXXQ01AL7859689FI      DEM   050H09348341L11 FINANCIAL  TLC                       
015258642   01EXXQ01AL7859689FI      PBS
015258642   01EXXQ01AL7859689FI      FA1
015258642   01EXXQ01AL7859689FI      BEN
015258643   01EXXQ01AL7859689FI      DEM   040H09348342P1L FINANCIAL  DDC                       
015258643   01EXXQ01AL7859689FI      PBS
015258643   01EXXQ01AL7859689FI      FA1
015258643   01EXXQ01AL7859689FI      BEN
016279862   01NYYW05HI7859688ID      DEM   020H07688688USA REPRESENTATIVE CORP 
016279862   01NYYW05HI7859688ID      PBS
016279862   01NYYW05HI7859688ID      FA1
016279862   01NYYW05HI7859688ID      BEN
016279997   01NYYW05GA7859687ID      DEM   120H07349349BUMBLE BEE INC             
016279997   01NYYW05GA7859687ID      PBS
016279997   01NYYW05GA7859687ID      FA1
016279997   01NYYW05GA7859687ID      BEN


Tried the following :
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(38,3,CH,EQ,C'DEM'),PUSH=(10123:ID=4)),
        IFTHEN=(WHEN=INIT,OVERLAY=(10001:5516,12,1983,100,1,10))         
  SORT FIELDS=(10001,126,CH,A),EQUALS                                   
  OUTREC IFTHEN=(WHEN=GROUP,BEGIN=(38,3,CH,EQ,C'DEM'),                   
                 PUSH=(10127:ID=4)),                                     
        IFTHEN=(WHEN=INIT,OVERLAY=(10001:5516,12,1983,100,1,10))         


But when I do that, the rest of the records get shuffled into different positions.
Tried group and seq, did not get it the way I want.

Expected output :
016279862   01NYYW05HI7859688ID      DEM   020H07688688USA REPRESENTATIVE CORP 
016279862   01NYYW05HI7859688ID      PBS
016279862   01NYYW05HI7859688ID      FA1
016279862   01NYYW05HI7859688ID      BEN
015258643   01EXXQ01AL7859689FI      DEM   040H09348342P1L FINANCIAL  DDC                       
015258643   01EXXQ01AL7859689FI      PBS
015258643   01EXXQ01AL7859689FI      FA1
015258643   01EXXQ01AL7859689FI      BEN
015258642   01EXXQ01AL7859689FI      DEM   050H09348341L11 FINANCIAL  TLC                       
015258642   01EXXQ01AL7859689FI      PBS
015258642   01EXXQ01AL7859689FI      FA1
015258642   01EXXQ01AL7859689FI      BEN
016279997   01NYYW05GA7859687ID      DEM   120H07349349BUMBLE BEE INC             
016279997   01NYYW05GA7859687ID      PBS
016279997   01NYYW05GA7859687ID      FA1
016279997   01NYYW05GA7859687ID      BEN


Please guide me how can I rearrange it.
Thanks
Aka

Re: Need some help to sort with a group

PostPosted: Tue May 06, 2014 4:05 am
by BillyBoyo
Ok, you sa 49 for 50 bytes, but that does not appear in your code.

If you make the ID from the GROUP the major part of the sort key, you will get all items for a group staying together. Is that what you want?

Otherwise, please clarify, and show the output your actually get, as well as the expected output.

Re: Need some help to sort with a group

PostPosted: Tue May 06, 2014 7:14 am
by akanchu
Thanks for replying, I had adjusted the data to fit the screen.. forgot to adjust the parms.

  INREC IFTHEN=(WHEN=GROUP,BEGIN=(38,3,CH,EQ,C'DEM'),PUSH=(123:ID=4)),
        IFTHEN=(WHEN=INIT,OVERLAY=(101:44,12,56,30,1,10))         
  SORT FIELDS=(101,52,CH,A),EQUALS                                   
  OUTREC IFTHEN=(WHEN=GROUP,BEGIN=(38,3,CH,EQ,C'DEM'),                   
                 PUSH=(127:ID=4)),                                     
        IFTHEN=(WHEN=INIT,OVERLAY=(101:44,12,56,30,1,10))


Output looked like, the DEM records went down.. and the records with spaces remained up.
015258642   01EXXQ01AL7859689FI      PBS
015258642   01EXXQ01AL7859689FI      FA1
015258642   01EXXQ01AL7859689FI      BEN
015258643   01EXXQ01AL7859689FI      PBS
015258643   01EXXQ01AL7859689FI      FA1
015258643   01EXXQ01AL7859689FI      BEN
016279862   01NYYW05HI7859688ID      PBS
016279862   01NYYW05HI7859688ID      FA1
016279862   01NYYW05HI7859688ID      BEN
016279997   01NYYW05GA7859687ID      PBS
016279997   01NYYW05GA7859687ID      FA1
016279997   01NYYW05GA7859687ID      BEN
016279862   01NYYW05HI7859688ID      DEM   020H07688688USA REPRESENTATIVE CORP 
015258643   01EXXQ01AL7859689FI      DEM   040H09348342P1L FINANCIAL  DDC                       
015258642   01EXXQ01AL7859689FI      DEM   050H09348341L11 FINANCIAL  TLC                       
016279997   01NYYW05GA7859687ID      DEM   120H07349349BUMBLE BEE INC             

Re: Need some help to sort with a group

PostPosted: Tue May 06, 2014 12:59 pm
by BillyBoyo
As I said earlier, to keep the groups together, you need the ID you have pushed to be the major part of the sort key. You need to sort on the ID, then on the rest of the data. Or, if you have some other grouping to do, make that the major part, then the ID, then the sequencing within the group.

Perhaps you can describe what sequence you need?

Re: Need some help to sort with a group

PostPosted: Tue May 06, 2014 6:46 pm
by akanchu
So I added the ID that I am pushing to the sort key, but I get the same result
SORT FIELDS=(101,52,CH,A,123,4,CH,A),EQUALS                                   


Thanks

Re: Need some help to sort with a group

PostPosted: Tue May 06, 2014 6:56 pm
by BillyBoyo
"Major" means before the rest of the key. The ID as the minor key is what you did originally, it was just stuck on the end of the data.

Re: Need some help to sort with a group

PostPosted: Tue May 06, 2014 7:14 pm
by akanchu
I am sorry, but I may not be picking up your hints right or I might not have stated my requirement clearly.
If I move the id before the rest of the key, I think it will just order the records within that group.
My need is to sort it based on the group, based on data in pos 49.
015258642   01EXXQ01AL7859689FI      DEM   050H09348341L11 FINANCIAL  TLC                       
015258642   01EXXQ01AL7859689FI      PBS
015258642   01EXXQ01AL7859689FI      FA1
015258642   01EXXQ01AL7859689FI      BEN
015258643   01EXXQ01AL7859689FI      DEM   040H09348342P1L FINANCIAL  DDC                       
015258643   01EXXQ01AL7859689FI      PBS
015258643   01EXXQ01AL7859689FI      FA1
015258643   01EXXQ01AL7859689FI      BEN
016279862   01NYYW05HI7859688ID      DEM   020H07688688USA REPRESENTATIVE CORP 
016279862   01NYYW05HI7859688ID      PBS
016279862   01NYYW05HI7859688ID      FA1
016279862   01NYYW05HI7859688ID      BEN
016279997   01NYYW05GA7859687ID      DEM   120H07349349BUMBLE BEE INC             
016279997   01NYYW05GA7859687ID      PBS
016279997   01NYYW05GA7859687ID      FA1
016279997   01NYYW05GA7859687ID      BEN


So in this case 016279862 group has 020H0768868 which should come at the top.
016279862   01NYYW05HI7859688ID      DEM   020H07688688USA REPRESENTATIVE CORP 
016279862   01NYYW05HI7859688ID      PBS
016279862   01NYYW05HI7859688ID      FA1
016279862   01NYYW05HI7859688ID      BEN
015258643   01EXXQ01AL7859689FI      DEM   040H09348342P1L FINANCIAL  DDC                       
015258643   01EXXQ01AL7859689FI      PBS
015258643   01EXXQ01AL7859689FI      FA1
015258643   01EXXQ01AL7859689FI      BEN
015258642   01EXXQ01AL7859689FI      DEM   050H09348341L11 FINANCIAL  TLC                       
015258642   01EXXQ01AL7859689FI      PBS
015258642   01EXXQ01AL7859689FI      FA1
015258642   01EXXQ01AL7859689FI      BEN
016279997   01NYYW05GA7859687ID      DEM   120H07349349BUMBLE BEE INC             
016279997   01NYYW05GA7859687ID      PBS
016279997   01NYYW05GA7859687ID      FA1
016279997   01NYYW05GA7859687ID      BEN


Apologies if I was not clear.
Thanks.

Re: Need some help to sort with a group

PostPosted: Tue May 06, 2014 8:28 pm
by akanchu
I have figured out the way to get this done.
Did a push of 49 bytes and the 1 thru 10 bytes when it reads DEM record
The PUSH helped me to replicate the same value found in DEM record onto the other, so they all have the same value
and then did a sort based on the pushed value.

Got it the way I want it.

Thank you for your help.
Aka

Re: Need some help to sort with a group

PostPosted: Tue May 06, 2014 9:39 pm
by BillyBoyo
Thanks for the update. You wanted to sort the entire file on the value from 49 on the DEM record, keeping the groups together? I think what you've said you've down sounds about right.

I don't think you'll need the 1,10 or even the ID. If you have duplicate keys, the EQUALS is going to ensure that records do not become intermingled.

If going that way, ensure that the use of EQUALS is commented to that effect, so someone doesn't "make it more efficient" by removing the EQUALS without thinking about it.

Kudos for getting there yourself.