The blow example illustrates how to add two numeric fields in a record
Following is the i/p file
111 222
333 444
000 111
222 000
O/p file should look as follows
333 ( i.e, 111 + 222)
777
111
222
Here is the simplest way it can be done:
//STEP020 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
111 222
333 444
001 111
222 000
//SORTOUT DD SYSOUT=*
//SYSIN DD *
INREC FIELDS=(1,3,ZD,ADD,
5,3,ZD)
SORT FIELDS=COPY
/*
The output will be:
333
777
112
222
You might notice that there are a few SPACES before the results. If you want to avoid them you could code it as follows: (Note that I made it four characters to avoid possible overflows)
//STEP020 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
111 222
333 444
001 111
222 000
//SORTOUT DD SYSOUT=*
//SYSIN DD *
INREC FIELDS=((1,3,ZD,ADD,
5,3,ZD),EDIT(TTTT))
SORT FIELDS=COPY
/*
Now, the output will be:
0333
0777
0112
0222
Here is the round about way using Synctool.
//STEP020 EXEC PGM=SYNCTOOL
//IN DD *
111222
333444
//TEMP1 DD DSN=&&TEMP1,
// DISP=(,CATLG),SPACE=(TRK,1),LRECL=6,RECFM=FB
//TEMP2 DD DSN=&&TEMP2,
// DISP=(,CATLG),SPACE=(TRK,1),LRECL=6,RECFM=FB
//OUT DD SYSOUT=*
//SSMSG DD SYSOUT=*
//TOOLMSG DD SYSOUT=*
//TOOLIN DD *
COPY FROM(IN) TO(TEMP1) USING(CTL1)
SORT FROM(TEMP1) USING(CTL2)
COPY FROM(TEMP2) TO(OUT) USING(CTL3)
//CTL1CNTL DD *
INREC FIELDS=(1,6,SEQNUM,3,ZD)
OUTFIL OUTREC=(7,3,1,3,/,
7,3,4,3)
//CTL2CNTL DD *
SORT FIELDS=(1,3,CH,A)
SUM FIELDS=(4,3,ZD)
OUTFIL FNAMES=TEMP2
//CTL3CNTL DD *
OUTREC FIELDS=(4,3,3X)
//*
Following is the i/p file
111 222
333 444
000 111
222 000
O/p file should look as follows
333 ( i.e, 111 + 222)
777
111
222
Here is the simplest way it can be done:
//STEP020 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
111 222
333 444
001 111
222 000
//SORTOUT DD SYSOUT=*
//SYSIN DD *
INREC FIELDS=(1,3,ZD,ADD,
5,3,ZD)
SORT FIELDS=COPY
/*
The output will be:
333
777
112
222
You might notice that there are a few SPACES before the results. If you want to avoid them you could code it as follows: (Note that I made it four characters to avoid possible overflows)
//STEP020 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
111 222
333 444
001 111
222 000
//SORTOUT DD SYSOUT=*
//SYSIN DD *
INREC FIELDS=((1,3,ZD,ADD,
5,3,ZD),EDIT(TTTT))
SORT FIELDS=COPY
/*
Now, the output will be:
0333
0777
0112
0222
Here is the round about way using Synctool.
//STEP020 EXEC PGM=SYNCTOOL
//IN DD *
111222
333444
//TEMP1 DD DSN=&&TEMP1,
// DISP=(,CATLG),SPACE=(TRK,1),LRECL=6,RECFM=FB
//TEMP2 DD DSN=&&TEMP2,
// DISP=(,CATLG),SPACE=(TRK,1),LRECL=6,RECFM=FB
//OUT DD SYSOUT=*
//SSMSG DD SYSOUT=*
//TOOLMSG DD SYSOUT=*
//TOOLIN DD *
COPY FROM(IN) TO(TEMP1) USING(CTL1)
SORT FROM(TEMP1) USING(CTL2)
COPY FROM(TEMP2) TO(OUT) USING(CTL3)
//CTL1CNTL DD *
INREC FIELDS=(1,6,SEQNUM,3,ZD)
OUTFIL OUTREC=(7,3,1,3,/,
7,3,4,3)
//CTL2CNTL DD *
SORT FIELDS=(1,3,CH,A)
SUM FIELDS=(4,3,ZD)
OUTFIL FNAMES=TEMP2
//CTL3CNTL DD *
OUTREC FIELDS=(4,3,3X)
//*
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.