Extract First Row From Each Group of Rows



Support for NetApp SyncSort for z/OS, Visual SyncSort, SYNCINIT, SYNCLIST and SYNCTOOL

Extract First Row From Each Group of Rows

Postby wallacec » Wed Sep 04, 2013 7:45 pm

Hi,

I have an input file with the following fields:

1) FLD1   X(2)
2) FLD2   X(1)
3) FLD3   X(3)
4) FLD4   X(4)

INPUT:
----|----|----|
11AXXX9999                  <- (1)
11AYYY9999                  <- (2)
13AZZZ9999                  <- (3)
21BXXX9999                  <- (4)
22BXXX9999                  <- (5)


I need to split all rows in the file into 2 separate files using the following rules:
1) Group all rows by FLD2 and sort by FLD1 AND FLD3 in ascending order
2) Put first row in each group into one file and put remaining rows in each group into another file
3) Combine FLD1 and FLD3 into a new field and place at the beginning of each row

Below is the expected output. Could anyone advise how this can be accomplished using SORT?

OUTPUT 1:
----|----|----|
11XXX11AXXX9999             <- (1)
21XXX21BXXX9999             <- (4)

OUTPUT 2:
----|----|----|
11YYY11AYYY9999             <- (2)
13ZZZ13AZZZ9999             <- (3)
22XXX22BXXX9999             <- (5)


Thanks.
wallacec
 
Posts: 4
Joined: Wed Sep 04, 2013 7:38 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Extract First Row From Each Group of Rows

Postby BillyBoyo » Thu Sep 05, 2013 5:23 am

If you sort on FLD2, then 1 then 3, then in OUTREC use IFTHEN=(WHEN=GROUP on FLD2 and PUSH a sequence number (to the end of the record if fixed-length, start of the record if variable).

In OUTFIL, have one file which has INCLUDE= for the sequence number being one, and a second file with SAVE (which will get all the other records on that file). Use BUILD on each of the OUTFIL datasets to do your final arrangement of the data.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Extract First Row From Each Group of Rows

Postby wallacec » Thu Sep 05, 2013 5:08 pm

Since I am not familiar with the control statements you mentioned, I will do a search to verify. Thanks for the suggestion.
wallacec
 
Posts: 4
Joined: Wed Sep 04, 2013 7:38 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Extract First Row From Each Group of Rows

Postby BillyBoyo » Thu Sep 05, 2013 6:29 pm

Good for you. If you get stuck with any of it, someone will be here.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times


Return to Syncsort/Synctool

 


  • Related topics
    Replies
    Views
    Last post