IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Sort & Sum on Key


IBM Mainframe Forums -> SYNCSORT
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
AlexSalas95

New User


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

PostPosted: Thu May 30, 2024 9:15 pm
Reply with quote

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
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2050
Location: USA

PostPosted: Thu May 30, 2024 9:25 pm
Reply with quote

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.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2050
Location: USA

PostPosted: Fri May 31, 2024 12:41 am
Reply with quote

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
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2050
Location: USA

PostPosted: Fri May 31, 2024 5:54 pm
Reply with quote

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       
Back to top
View user's profile Send private message
Joerg.Findeisen

Senior Member


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

PostPosted: Sun Jun 02, 2024 3:45 pm
Reply with quote

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.
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2050
Location: USA

PostPosted: Mon Jun 03, 2024 6:43 pm
Reply with quote

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.
Back to top
View user's profile Send private message
AlexSalas95

New User


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

PostPosted: Wed Jun 05, 2024 11:58 pm
Reply with quote

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
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2050
Location: USA

PostPosted: Thu Jun 06, 2024 12:21 am
Reply with quote

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.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> SYNCSORT

 


Similar Topics
Topic Forum Replies
No new posts Need to set RC4 through JCL SORT DFSORT/ICETOOL 5
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts JCL sort card - get first day and las... JCL & VSAM 9
No new posts Sort First/last record of a subset th... DFSORT/ICETOOL 7
No new posts how to calculate SUM value for VB fil... DFSORT/ICETOOL 1
Search our Forums:

Back to Top