|
View previous topic :: View next topic
|
| Author |
Message |
ramsri
Active User

Joined: 18 Oct 2008 Posts: 380 Location: India
|
|
|
|
Hi,
May I please know how to calculate difference between records from an input file? 1st position is the key, 2nd position has '-' followed by numeric value.
| Code: |
X-6839
X-6838
X-6835
K-4987
K-4980
T-3312
T-3311
T-3310
T-3309
T-3308
|
I would like to calculate difference between each record within each group and write somewhere in same line in output or just difference alone
Output-1:
| Code: |
X-6839
X-6838 difference is 1
X-6835 difference is 3
K-4987
K-4980 difference is 7
T-3312
T-3311 difference is 1
T-3310 difference is 1
T-3309 difference is 1
T-3308 difference is 1
|
Achievable with SYNCSORT FOR Z/OS V1.3.2.2R? Please help. Thanks. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
| You use WHEN=GROUP, PUSH the amount (which will be that of the first record in the group). When you process each record in the group, you will have current amount and the amount from the first record. |
|
| Back to top |
|
 |
gcicchet
Senior Member
Joined: 28 Jul 2006 Posts: 1702 Location: Australia
|
|
|
|
Hi Bill,
my understanding is you need to push the value from the previous record to the current record in the group to obtain the difference.
eg.
| Code: |
X-6839
X-6838 6839 difference is 1
X-6835 6838 difference is 3
|
Gerry |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Thanks Gerry, I didn't look closely-enough at the example. It is something of an arbitrary choice, as really I'd think the best way would be to have the minimum and maximum value for a group and take the difference between them. However, I suppose it depends...
So, for each record, a GROUP with no BEGIN/END but instead just RECORDS=2, push the number and the group-identifier. You need a bit of a left/right thing going on. Try to follow this one. |
|
| Back to top |
|
 |
ramsri
Active User

Joined: 18 Oct 2008 Posts: 380 Location: India
|
|
|
|
Pity to know that this is not (POSSIBLE) easy with Syncsort at least. Going the COBOL way
Thanks for all the suggestions. |
|
| Back to top |
|
 |
gcicchet
Senior Member
Joined: 28 Jul 2006 Posts: 1702 Location: Australia
|
|
|
|
Hi,
try this
| Code: |
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
X-6839
X-6838
X-6835
K-4987
K-4980
L-1234
T-3312
T-3311
T-3310
T-3309
T-3308
//OUT01 DD DSN=&&OUT01,DISP=(,PASS,DELETE),UNIT=SYSDA,
// SPACE=(TRK,(20,5),RLSE)
//OUT02 DD DSN=&&OUT02,DISP=(,PASS,DELETE),UNIT=SYSDA,
// SPACE=(TRK,(20,5),RLSE)
//SYSIN DD *
SORT FIELDS=COPY
INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,8,ZD,RESTART=(1,1))),
IFTHEN=(WHEN=GROUP,BEGIN=(81,8,ZD,EQ,+1),
PUSH=(21:ID=8,SEQ=8))
OUTFIL FNAMES=OUT01,BUILD=(1,28,29,8,ZD,SUB,+1,EDIT=(TTTTTTTT),80:X)
OUTFIL FNAMES=OUT02,BUILD=(1,80)
//*
//STEP0200 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTJNF1 DD DSN=&&OUT01,DISP=SHR
//SORTJNF2 DD DSN=&&OUT02,DISP=SHR
//SORTOUT DD SYSOUT=*
//SYSIN DD *
OPTION COPY
JOINKEYS FILE=F1,FIELDS=(21,16,A),SORTED
JOINKEYS FILE=F2,FIELDS=(21,16,A),SORTED
JOIN UNPAIRED,F1
REFORMAT FIELDS=(F1:1,6,29,8,F2:1,6)
OUTREC IFTHEN=(WHEN=(7,8,ZD,EQ,+0),
BUILD=(1,6,80:X)),
IFTHEN=(WHEN=(7,8,ZD,GT,+0),
BUILD=(1,6,10:17,4,ZD,SUB,3,4,ZD,EDIT=(IIII)))
|
Gerry |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Ramsri,
You come here for Sort solutions, don't provide everything asked, and then go off and do it in Cobol anyway.
You were a trailer record away with your previous (similar) request and seem to have abandoned that, went for Zellers Congruent in Cobol instead of a table of dates in Sort,
How about next time we just ignore your Sort requests and let you go straight for Cobol? Saves us wasting time on it. |
|
| Back to top |
|
 |
ramsri
Active User

Joined: 18 Oct 2008 Posts: 380 Location: India
|
|
|
|
Gerry, I will try it and come back.....thanks.
Bill, I was just expressing my views and did not hurt anybody....did I?
Thanks. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Ramsri,
If you answer all the questions, you'll get more out of it. I had the workings of a solution for your Monday/Sunday dates, if you could answer. You were close with your NULLOFL, and I have a different solution, and then it sort of quietly went away. Where you want something "complicated" for Sort, then the answer is going to be "complicated" - these are relative terms. If you are worried about "complications", then why not just go for Cobol to start with?
If you go for Cobol, don't do Zeller's, choose a date for a known day, get the integer of value of that date, the integer value of the day that you want, and do a divide with a remainder. All the "hard" work is done by the function doing the integer of the date. |
|
| Back to top |
|
 |
dick scherrer
Moderator Emeritus

Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
| Quote: |
| I was just expressing my views and did not hurt anybody....did I? |
Possibly only yourself. . .
You continue to demonstrate that you prefer to have things given to you rather than work on the solutions yourself. . . .
Had you actually worked thru several of your earlier projects rather than just grab what was given and use it, i suspect you could now be more self-reliant.
| Quote: |
| Pity to know that this is not (POSSIBLE) easy with Syncsort at least. |
No, it is quite possible. Things are usually more difficult when one is trying to learn. They will remain difficult if one is unwilling to invest the time/effort to learn. |
|
| Back to top |
|
 |
ramsri
Active User

Joined: 18 Oct 2008 Posts: 380 Location: India
|
|
|
|
| Hi Gerry, tried the solution given by you and got expected results...thank you very much. |
|
| Back to top |
|
 |
ramsri
Active User

Joined: 18 Oct 2008 Posts: 380 Location: India
|
|
|
|
Bill, I studied Zeller's congruence from wikipedia and have written COBOL version of it after working it out till I understood it. I did not put it here....sorry. Regarding NULLOFL, I probably never tried to understand how it works
Thank for all your time and effort. |
|
| Back to top |
|
 |
ramsri
Active User

Joined: 18 Oct 2008 Posts: 380 Location: India
|
|
|
|
| I feel that SYNCSORT lacks many good features when compared to DFSORT and we always end-up doing it in a lengthy way than a simpler solution. This extra effort of coding drives me to COBOL which I am more convenient with but in the background I still practice SORT solutions too. |
|
| Back to top |
|
 |
dick scherrer
Moderator Emeritus

Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Then maybe you should find employment in an organizaton that uses DFSORT.
| Quote: |
| I feel that SYNCSORT lacks many good features when compared to DFSORT |
I suspect that (from your perspective) DFSORT has the "feature" of always having someone who will do your work for you . . .
| Quote: |
| we always end-up doing it in a lengthy way than a simpler solution. |
Nearly everything can be done with either product with about the same amount of effort. |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|