View previous topic :: View next topic
|
Author |
Message |
AlexSalas95
New User
Joined: 18 Mar 2024 Posts: 6 Location: United States
|
|
|
|
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 |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2120 Location: USA
|
|
|
|
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 |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2120 Location: USA
|
|
|
|
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 |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2120 Location: USA
|
|
|
|
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 |
|
|
Joerg.Findeisen
Senior Member
Joined: 15 Aug 2015 Posts: 1308 Location: Bamberg, Germany
|
|
|
|
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 |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2120 Location: USA
|
|
|
|
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
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 |
|
|
AlexSalas95
New User
Joined: 18 Mar 2024 Posts: 6 Location: United States
|
|
|
|
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 |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2120 Location: USA
|
|
|
|
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
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 |
|
|
|