I have a problem that i can’t solve with DFSORT but I hope it possible to solve with DFSORT.
I have a file with the input money and output money from an account and I need to match each output with each input. The rules to match a output with a input are:
1.- Look for an input with a date less than the output.
2.- If the input money is >= than the output money , the match finish and the output money is subtracted from the input money.
3.- If the input money is < than the output money, subtract the input money from the output money and look for another input.
Example file:
KEY INPUT/OUTPUT MONEY
------------ ------------- ------
A 2010-01-01 input +40
A 2010-03-02 input +80
A 2011-04-06 input +100
A 2012-01-03 output -110
A 2012-02-05 output -10
A 2012-05-03 output -12
A 2012-06-09 input +50
------------ ------------- ------
A 2010-01-01 input +40
A 2010-03-02 input +80
A 2011-04-06 input +100
A 2012-01-03 output -110
A 2012-02-05 output -10
A 2012-05-03 output -12
A 2012-06-09 input +50
I need to obtain the next file :
KEY INPUT/OUTPUT MONEY
------------ ------------- ------
A 2010-01-01 input +0
A 2010-03-02 input +0
A 2011-04-06 input +82
A 2012-01-03 output -110
A 2012-02-05 output -10
A 2012-05-03 output -12
A 2012-06-09 input +50
------------ ------------- ------
A 2010-01-01 input +0
A 2010-03-02 input +0
A 2011-04-06 input +82
A 2012-01-03 output -110
A 2012-02-05 output -10
A 2012-05-03 output -12
A 2012-06-09 input +50
Explanation
The first output with 110 matches with the first input of 40 and let the input with 0, but in the output remain 70 not matched against any input. Then search for other Input and find the second input with 80, subtract 70 from 80 and leave de second input with 10. The first output now is fully matched.
The second output with 10 use the second input, and leave the second input with 0 and the second output is fully matched.
The third output with 12 matches with the third input and let the input with 82 and the third output is fully matched.
There is any interested to help me?
Thanks.
Code'd