I am using SORT to add up a field in a file.
LRECL = 80
RECFM = FB
The file has a packed decimal field of length 3 starting from column 1.
It has values 200, 300, and -5 in the three records. And that is all it has.
When i use SUM FIELDS=(1,3,PD) the output has value 495. ( Sum of the above 3 records).
I want the sum to be appearing as 505 ( i.e 200+300+5) discarding the sign. Is there a way to do this? Is it possible to do this in one step?
found somewhere on the net googling for "SYNCSORT ABSOLUTE VALUE"
FWIW, this technique works with DFSORT. I assumed the PD value is in
11-15 and the input file has RECFM=FB and LRECL=80, but the statements
can be changed appropriately for other situations. I also assumed you
want to keep the original negative values rather than actually making
* If PD value in 11-15 is negative, set 81-85 to value * -1
* If PD value in 11-15 is positive, copy value to 81-85
* Sort on absolute PD value in 81-85.
* Remove 81-85.