|
View previous topic :: View next topic
|
| Author |
Message |
Aneesh
New User
Joined: 30 Sep 2006 Posts: 60
|
|
|
|
Hi,
I have an FB file of length 80 that has a key field, a value field and a multiple field. I need to sort the file in the order of the lowest unit value field record. Unit value is the value field divided by the multiple.
Key field - numeric 10 bytes
Value field - numeric 15 bytes
Multiple feild - numeric 5 bytes
000000000100000000000010100003
000000000100000000000010000003
000000000100000000000007500001
I am using a sort card to divide the value/multiple and then sort on the divided value.
| Code: |
INREC FIELDS=(1,30,(11,15,ZD,DIV,26,5,ZD))
SORT FIELDS=(1,10,ZD,A,31,15,CH,A)
|
When i am doing this, i am facing issues with rounding down in the division operation. Value 100 with a multiple of 3 and value 101 with a multiple of 3 both give 33 as output, although i want the sorted order to have 100 with value 3 to come first.
Is there a way around this?
Thanks,
Aneesh. |
|
| Back to top |
|
 |
Frank Yaeger
DFSORT Developer

Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
You aren't really having trouble with rounding down. You're having trouble with the integer result DFSORT gives for DIV.
You can scale the value by +100 to get more significance in the integer result. For example (assuming you don't really want to keep the unit value):
| Code: |
INREC OVERLAY=(81:(11,15,ZD,MUL,+100),
DIV,26,5,ZD,TO=ZD,LENGTH=15)
SORT FIELDS=(1,10,ZD,A,81,15,CH,A)
OUTREC BUILD=(1,80)
|
Now the unit value will be 000000000003333 for 100/3 and 000000000003366 for 101/3, so it will sort correctly, and your output will be:
| Code: |
000000000100000000000010000003
000000000100000000000010100003
000000000100000000000007500001
|
If you want something else for the output, you need to show what you want exactly. |
|
| Back to top |
|
 |
Aneesh
New User
Joined: 30 Sep 2006 Posts: 60
|
|
|
|
Thanks a lot, Frank . That works fine for my purposes. |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|