View previous topic :: View next topic
Author
Message
Anand Kumar New User Joined: 29 Aug 2007Posts: 24 Location: chennai
Hi,
I have a requirement to find the sum of accounts like below:
Input file looks like this:
act no- 1:3
amt - 4: 8
Name - 12:5
Code:
00100000052Anand
00100000061Kumar
00100000007Aruna
00200000004Anand
00300000002Prave
00300000001Veena
for each act no, we need to sum the amt's in this case 52+61+7 = 120 and write all the three records with 120 in end.
so my output file should be as follows:
Code:
00100000052Anand00000000120
00100000061Kumar00000000120
00100000007Aruna00000000120
00200000004Anand00000000004
00300000002Prave00000000003
00300000001Veena00000000003
Hence the same for act 002 the sum is 4 and the act 003 the sum is 2+1= 3.
Please can any one help in such a scenario?
topic edited to provide a[n almost] meaningful title
Back to top
sqlcode1 Active Member Joined: 08 Apr 2010Posts: 577 Location: USA
Anand Kumar,
See if below works for you...
Code:
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTJNF1 DD *
00100000052ANAND
00200000004ANAND
00100000061KUMAR
00300000002PRAVE
00300000001VEENA
00100000007ARUNA
/*
//SORTJNF2 DD *
00100000052ANAND
00200000004ANAND
00100000061KUMAR
00300000002PRAVE
00300000001VEENA
00100000007ARUNA
/*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
JOINKEYS FILES=F1,FIELDS=(01,03,A)
JOINKEYS FILES=F2,FIELDS=(01,03,A)
REFORMAT FIELDS=(F1:01,16,
F2:81,08)
OPTION COPY
/*
//JNF2CNTL DD *
INREC OVERLAY=(81:04,08)
SUM FIELDS=(81,8,ZD)
/*
OUTPUT
Code:
00100000052ANAND00000120
00100000061KUMAR00000120
00100000007ARUNA00000120
00200000004ANAND00000004
00300000002PRAVE00000003
00300000001VEENA00000003
Thanks,
Back to top
Anand Kumar New User Joined: 29 Aug 2007Posts: 24 Location: chennai
Thank you..
Back to top
Escapa Senior Member Joined: 16 Feb 2007Posts: 1399 Location: IL, USA
I was thinking of two stage solution without joinkeys.. but this one looks better... Good one sqlcode1
Back to top
dick scherrer Moderator Emeritus Joined: 23 Nov 2006Posts: 19244 Location: Inside the Matrix
Hello,
If the "real" account number is 10 bytes (instead of the 3 shown in the example) and there are 200 million records, duplicating the file may not be desirable. . .
Back to top
sqlcode1 Active Member Joined: 08 Apr 2010Posts: 577 Location: USA
Escapa wrote:
I was thinking of two stage solution without joinkeys ..
Without JOINKEYS,something like below might work as a single pass solution but I doubt the efficiency in this case... This was given by Kolusu on other board. In fact,I think the one with JOINKEYS was also provided by him
Code:
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
$$$
/*
// DD *
00100000052ANAND
00200000004ANAND
00100000061KUMAR
00300000002PRAVE
00300000001VEENA
00100000007ARUNA
/*
// DD *
$$$
/*
// DD *
00100000052ANAND
00200000004ANAND
00100000061KUMAR
00300000002PRAVE
00300000001VEENA
00100000007ARUNA
/*
//SORTOUT DD SYSOUT=*
//SYSIN DD *
INREC IFTHEN=(WHEN=INIT,
OVERLAY=(81:4,8,ZD)),
IFTHEN=(WHEN=GROUP,
BEGIN=(1,3,CH,EQ,C'$$$'),PUSH=(91:ID=1,SEQ=8)),
IFTHEN=(WHEN=(91,1,ZD,EQ,1),OVERLAY=(92:7C'0',C'1'))
SORT FIELDS=(1,3,CH,A,92,8,ZD,A),EQUALS
SUM FIELDS=(81,8,ZD)
OUTREC IFTHEN=(WHEN=GROUP,BEGIN=(91,1,ZD,EQ,1),PUSH=(81:81,8))
OUTFIL INCLUDE=(91,1,ZD,EQ,2),
BUILD=(1,16,X,81,8,ZD,TO=ZD,LENGTH=8)
/*
OUTPUT
Code:
00100000052ANAND 00000120
00100000061KUMAR 00000120
00100000007ARUNA 00000120
00200000004ANAND 00000004
00300000002PRAVE 00000003
00300000001VEENA 00000003
Thanks,
Back to top
Please enable JavaScript!