# Sort & Sum on Key

Author Message
AlexSalas95

New User

Joined: 18 Mar 2024
Posts: 6
Location: United States

Posted: Thu May 30, 2024 9:15 pm

Given the following input, where each record consists of 4 sets of key/value pairs (i.e the first 4 bytes are the key, followed by a space, then in the next 3 bytes its corresponding value)

 Code: 1111 050 2222 005 3333 200 4444 010 1110 030 2222 001 3333 201 4445 010 1111 000 2222 007 3333 150 4445 050

Can a sort card be written that will sort and sum on each key to produce the following output?;

 Code: 1110 030 1111 050          2222 013                   3333 551                            4444 010                            4445 060
sergeyken

Senior Member

Joined: 29 Apr 2008
Posts: 2081
Location: USA

Posted: Thu May 30, 2024 9:25 pm

 AlexSalas95 wrote: Can a sort card be written that will sort and sum on each key to produce the following output?;

Yes, it can be written. More than one "sort cards" may be required.

SORT has been designed specifically for the tasks like this one.
sergeyken

Senior Member

Joined: 29 Apr 2008
Posts: 2081
Location: USA

 Posted: Fri May 31, 2024 12:41 am Hint: do it in three stages - 1) convert 4-columns file to a single-column file 2) sort and summarize the single-column file 3) shift single-column data back to their original positions in 4 columns
sergeyken

Senior Member

Joined: 29 Apr 2008
Posts: 2081
Location: USA

Posted: Fri May 31, 2024 5:54 pm

Hint #2: do it in three stages -

 Code: 1111 050 2222 005 3333 200 4444 010  1110 030 2222 001 3333 201 4445 010  1111 000 2222 007 3333 150 4445 050

1) convert 4-columns file to a single-column file (with appended initial column number)
 Code: 1111 050 1 2222 005 2 3333 200 3 4444 010 4 1110 030 1 2222 001 2 3333 201 3 4445 010 4 1111 000 1 2222 007 2 3333 150 3 4445 050 4

2) (a) sort and (b) summarize the single-column file
 Code: 1110 030 1 1111 050 1 1111 000 1 2222 005 2 2222 001 2 2222 007 2 3333 200 3 3333 201 3 3333 150 3 4444 010 4 4445 010 4 4445 050 4

 Code: 1110 030 1                                  1111 050 1                                  2222 013 2                          3333 551 3                4444 010 4        4445 060 4

3) shift single-column data back to their original positions in 4 columns
 Code: 1110 030                                    1111 050                                             2222 013                                            3333 551                                             4444 010                                   4445 060
Joerg.Findeisen

Senior Member

Joined: 15 Aug 2015
Posts: 1295
Location: Bamberg, Germany

 Posted: Sun Jun 02, 2024 3:45 pm As sergeyken has pointed out, you need at least two steps. ICETOOL/SYNCTOOL can be used (I haven't tested this way), and also regular SORT.
sergeyken

Senior Member

Joined: 29 Apr 2008
Posts: 2081
Location: USA

Posted: Mon Jun 03, 2024 6:43 pm

If you cannot resolve the complex task, then start from a simplified one, like this one: convert this input
 Code: 1111 050 1110 030 1111 000

to this output
 Code: 1110 030 1111 050

When this is done, then continue with a more complex task.

Unless you start doing something BY YOURSELF, do not expect others would do your own job for you.
AlexSalas95

New User

Joined: 18 Mar 2024
Posts: 6
Location: United States

 Posted: Wed Jun 05, 2024 11:58 pm Thanks sergeyken and Joerg.Findeisena, I appreciate your help Due to ever-changing requirements, I decided to go about this programatically instead of using syncsort. I do want to defend myself a little bit, as prior to posting this I had tried for several hours over the course of two days to come up with a solution. My knowledge of syncsort is very limited, and unfortunately few people at my shop use it for some reason I've gotten ahold of some literature so I'll try to reference that in the future. I quite like syncsort and wish my team specifically would use it more so I think in my spare time I'll still try to figure this out. Again, I want to thank you for your responses as I understand now what I'd have to do. Breaking it into multiple steps makes a lot more sense
sergeyken

Senior Member

Joined: 29 Apr 2008
Posts: 2081
Location: USA

Posted: Thu Jun 06, 2024 12:21 am

sergeyken wrote:
If you cannot resolve the complex task, then start from a simplified one, like this one: convert this input
 Code: 1111 050 1110 030 1111 000

to this output
 Code: 1110 030 1111 050

When this is done, then continue with a more complex task.

Unless you start doing something BY YOURSELF, do not expect others would do your own job for you.

This initial task is the most primitive one. Any SORT manual gives this example on the first few pages!
 Code: //SORTSUM  EXEC PGM=SORT //SYSOUT   DD  SYSOUT=* //SORTIN   DD  * 1111 050 1110 030 1111 000 //* //SORTOUT  DD  SYSOUT=* //SYSIN    DD  *  SORT FIELDS=(1,4,CH,A)  SUM FIELDS=(6,3,ZD)  END //*

just reproduce this primitive common and standard example.
 View Bookmarks All times are GMT + 6 Hours

 Topic Forum Replies Similar Topics To Omit records based n SORT condition DFSORT/ICETOOL 6 Looking for help with SORT JCL/SYNC sort DFSORT/ICETOOL 6 sort to find out the char which repea... Mainframe Interview Questions 10 Dynamically build sort control statem... SYNCSORT 18 Need to set RC4 through JCL SORT DFSORT/ICETOOL 5
Search our Forums:

 IBMMainframes.com is not an official and/or affiliated with IBM® in anyway Board Rules | FAQ | Downloads | Wiki | SiteMap | Contact Us