Hi,
i have two files. for each entry of file2 there can be multiple entries in file1.my requirement is i want to subtractall quantites from file1 with quanties
from file2.
say for example.
01 INFILE:
05 KEY PIC X(5)
05 QTY1 PIC S9(9) COMP-3.
I wonder why the TS requested a solution for the "amount against multiple invoices" problem
using a dsfort solution, instead writing a program to provide a properly audited track of the computations
if it is just for learning just start trying something Yourself
some hints ...
joinkeys <== the trick is to put the total amount only on the first occurrence of the key
then ....
if amount >= invoice
invoice = 0
amount = amount-invoice
push amount
if amount = 0
do nothing
see what happens without cleaning up the work columns
my point is not about the lowly technicalities, but about the proper business approach
Joined: 03 Oct 2009 Posts: 1788 Location: Bloomington, IL
enrico-sorichetti wrote:
I wonder why the TS requested a solution for the "amount against multiple invoices" problem using a dsfort solution, instead writing a program to provide a properly audited track of the computations
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
The tricky part is keeping the records with zeros on. There is no information other than the zero - in this "requirement".
Is there a maximum number of records for a key?
Why we are wary is because of the previous two, where the first "requirement" looks like a "get some skeleton code so I can do the rest", but where you didn't understand it enough to be able to implement it, and the combined effort of getting to the actual solution for the actual requirement far exceeded that needed to just provide the actual requirement.
So, do a JOINKEYS, with a SUM in the JNFnCNTL for the multi-record file. When you get the match, update the balance, copy the balance to the multiple-now-one record and write to two seperate files with OUTFIL.
If you are somehow desperate to keep the zeros, which are meaningless, and there is no sensible limit to the number of records per key, let us know, as I think you'll need another JOINKEYS step just to do it, which seems a bit of a waste.
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
Well, it can be done in one step. Still don't think it is real... and the real thing may require code to change significantly (you never know, it did last time), so, until we see the real thing...
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
Whoops. Forgot the method.
Requires two single-record files for a header and a trailer, same DCB as other files.
JOINKEYS
First file, transactions
SUMmed on amount (have to convert it for the SUM) and the character "1" to get SUM to indicate how many records make up the summed record.
Second file
header
master
trailer
transactions
GROUP using header and trailer to set a marker for masters
Main processing (not necessarily in order/consolidated, see INREC/OUTREC comment)
REFORMAT sticking both records together
GROUP on the 2nd file part, generating sequence
GROUP on the 2nd file part pushing amount
if Master, update to reflect transactions
if not Master, set to "+0 " or the trans
if trans no is equal to seq no, set to value from master
You'll need to use INREC and OUTREC in the main processing.
There are probably better ways, but it can definitely be done.
EDIT: Forgot. Two OUTFILs to create the new datasets.