Posted: Sun Jul 26, 2009 7:18 am Post subject: ICETOOL: Matching amounts equal and opposite
I have a file of records, with a key field and a value
There should be 2 records per 'transaction' ie the debit and the credit value
I want to ouput those records which have either
- a missing debit or credit,
- or where the values are not equal and complementary
(I was doing ok until it multiple pairings for the same key came in)
Can you suggest a method
e.g.
KEY1 5000+
KEY1 5000-
KEY1 5000+
KEY1 5000-
KEY1 1500+ --> output
KEY1 5000- --> output
KEY1 5000- --> output
KEY1 5000+
KEY1 5000-
KEY1 1200- --> output
KEY2 3000+
KEY2 3000-
KEY3 4000+ --> output
KEY4 4000+
KEY4 1200+ --> output
KEY4 4000-
KEY5 4000+ --> output
KEY5 3800- --> output
In the above data 1500 is compared against 5000 which does not match so it is written to output but the next set is 5000 is compared to +5000 so it wouldn't match , so shouldn't you be writting those 2 records also to output? But you matched the next 5000+ to the next 5000- . Shouldn't you be comparing 2 records at a time? what happens if your data is like this ?
Code:
KEYA 5000- MATCH WITH LAST RECORD
KEYA 1000- MATCH WITH NEXT RECORD
KEYA 1000+ MATCH WITH PREV RECORD
KEYA 2000- MATCH WITH NEXT RECORD
KEYA 2000+ MATCH WITH PREV RECORD
KEYA 3000- MATCH WITH NEXT RECORD
KEYA 3000+ MATCH WITH PREV RECORD
KEYA 4000- MATCH WITH NEXT RECORD
KEYA 4000+ MATCH WITH PREV RECORD
KEYA 5000+ MATCH WITH FIRST RECORD
What is the LRECL and RECFM of the input file? What is the position and format of the key field and the amount field? _________________ Kolusu
www.linkedin.com/in/kolusu
Yep thats the problem the recs aren't consistent - I don't know how to best sort and then match them
from rec 5
rec5: 1500+ has nomatching 1500- so output
rec6: 5000- has no matching 5000+ so output
rec8 matches with either rec 7 or rec 9, so output the unmatched
rec10 has no matching +1200
The problem is the order of the file is random so ill have to sort them into some order
So taking your example and then making some of the pairings missing:
KEYA 5000+
KEYA 5000-
KEYA 4000+ unmatched
KEYA 3999+
KEYA 3999-
KEYA 3000- unmatched
KEYA 2000+
KEYA 2000-
KEYA 2000- unmatched
KEYA 1000- unmatched
KEYA 999+ unmatched
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum