How can we sum amount and get max date at the same time when group by id in JCL
Input:
Id Amount Date
--------------------
123 200 20180516
123 300 20180520
456 100 20180616
456 700 20180420
Expected result:
Id Amount Date
--------------------
123 500 20180520
456 800 20180616
What i try already:
SORTST5 EXEC PGM=SORT
SYSOUT DD SYSOUT=*
SYSPRINT DD SYSOUT=*
SORTIN DD DSN=&VNTMPççWRK.INWORK,DISP=SHR
SORTOUT DD DSN=&VNTMP..WRK.OUTWORK.OUT.FRM,
DISP=(,CATLG,DELETE),
RECFM=FB,LRECL=84, SPACE=(CYL,(100,100), RLSE)
SYSIN DD *
SORT FIELDS=(1,3,PD,A)
SUM FIELDS=(4,3,PD)
JCL isn't an executable and you can't manipulate date in JCL without utilities like SORT.
I've used ICETOOL (a utility) in JCL to achieve your expected result. First Control statement will sort the Input using ID (in ascending order) and Date (in descending order). Second control statement will do SUM FIELDS on the output yielded using first control statement.
//STEP1 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFMSG DD SYSOUT=*
//TOOLIN DD *
SORT FROM(INDD) TO(OUTDD1) USING(CTL1)
SORT FROM(OUTDD1) TO(OUTDD2) USING(CTL2)
//INDD DD *
123 200 20180516
123 300 20180520
456 700 20180420
456 100 20180616
//OUTDD1 DD DSN=XXX.ICETOOL.OUTDD1,
// DISP=(,CATLG,DELETE),
// SPACE=(CYL,(100,0),RLSE),
// DCB=(LRECL=80,RECFM=FB,BLKSIZE=0)
//OUTDD2 DD DSN=XXX.ICETOOL.OUTDD2,
// DISP=(,CATLG,DELETE),
// SPACE=(CYL,(100,0),RLSE),
// DCB=(LRECL=80,RECFM=FB,BLKSIZE=0)
//SSMSG DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//CTL1CNTL DD *
SORT FIELDS=(1,3,ZD,A,9,8,ZD,D)
/*
//CTL2CNTL DD *
SORT FIELDS=(1,3,ZD,A)
SUM FIELDS=NONE
/*