chinnielr
New User
Joined: 11 Jul 2005 Posts: 87
|
|
|
|
Below is the requirement we have, please let me know how can we handle it using sort.
I have the file with following fields (lrecl = 43)
Code: |
FIELD1 FIELD2 FIELD3
8/AN 15/SNUM 20/AN
-------- -------- ------
123/2345 400.00 AAA111
111/896 300.00 BBA222
111/896 250.00 BBA222
111/896 -100.00 BBA222
888/970 800.00 CDD333
888/970 -100.00 CDD333
910/999 200.00 XYX444
910/999 200.00 XYX444
|
We need to sort the above file using the field1 and Field3 as key fields and sum the amount for the key fields except the records with field1 value
of '888/970' has to be written in the o/p file as it is from i/p file without summation. The o/p file also need to reformatted to have the first26 bytes alone from i/p file, rest being spaces for all the records except '888/970' records.
Hence, the o/p file should look like the one below.(LRECL=43)
Code: |
FIELD1 FIELD2 FIELD3
8/AN 15/SNUM 20/AN
-------- -------- ------
111/896 450.00 BBA
123/2345 400.00 AAA
888/970 800.00 CDD333
888/970 -100.00 CDD333
910/999 400.00 XYX
|
Thanks in advance,
Chinni. |
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
Here's a DFSORT job that will do what you asked for:
Code: |
//S1 EXEC PGM=ICEMAN
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=... input file (FB/43)
//SORTOUT DD DSN=... output file (FB/43)
//SYSIN DD *
INREC IFTHEN=(WHEN=INIT,
OVERLAY=(9:9,15,SFF,TO=ZD,LENGTH=15,44:8C'0')),
IFTHEN=(WHEN=(1,8,CH,EQ,C'888/970'),OVERLAY=(44:SEQNUM,8,ZD))
SORT FIELDS=(1,8,CH,A,24,20,CH,A,44,8,ZD,A)
SUM FIELDS=(9,15,ZD)
OUTREC IFOUTLEN=43,
IFTHEN=(WHEN=INIT,
OVERLAY=(9:9,15,ZD,EDIT=(SIIIIIIIIIIT.TT),SIGNS=(,-))),
IFTHEN=(WHEN=(1,8,CH,NE,C'888/970'),BUILD=(1,26))
/*
|
|
|