|
View previous topic :: View next topic
|
| Author |
Message |
useit
Active User
Joined: 05 Oct 2006 Posts: 152
|
|
|
|
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.
input file1:
| Code: |
key1 +10
key1 +20
key1 +40
key2 -10
key2 -20 |
input file2:
01 INFILE:
05 KEY PIC X(5)
05 QTY2 PIC S9(9) COMP-3.
i should first subtract 10 from 80(80-10=70). and then i should remove 20 from remaining 70(70-20=50). and remove 40 from remaining 50.(50-40=10)
key1 +0 ------->(80-10=70)
key1 +0 ------->(70-20=50)
key1 +10 ------>(50-40=10)
key2 +0 ------->(10-10=0)
key2 +20
OUTPUT:
01 OUTFILE:
05 KEY PIC X(5)
05 QTY PIC S9(9) COMP-3.
| Code: |
--------
key1 +0
key1 +0
key1 +10
key2 +0
key2 +20
-------- |
Regds,
useit |
|
| Back to top |
|
 |
PeterHolland
Global Moderator

Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
| And now ? |
|
| Back to top |
|
 |
enrico-sorichetti
Superior Member

Joined: 14 Mar 2007 Posts: 10903 Location: italy
|
|
|
|
the TS wants a solution, what else
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 |
|
| Back to top |
|
 |
enrico-sorichetti
Superior Member

Joined: 14 Mar 2007 Posts: 10903 Location: italy
|
|
|
|
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 |
|
| Back to top |
|
 |
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
| I guess we need to wait for the actual requirement once again? |
|
| Back to top |
|
 |
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2454 Location: Hampshire, UK
|
|
|
|
| Give the guy a break - he's only done 94 posts since 2006! |
|
| Back to top |
|
 |
useit
Active User
Joined: 05 Oct 2006 Posts: 152
|
|
|
|
hi,
I would really be grateful if any of you could help me in this. give me some idea plssss
Regds,
useit |
|
| Back to top |
|
 |
useit
Active User
Joined: 05 Oct 2006 Posts: 152
|
|
|
|
hi,
can this be done through DFSORT?Could you please give me some hint?
Regds,
useit |
|
| Back to top |
|
 |
dbzTHEdinosauer
Global Moderator

Joined: 20 Oct 2006 Posts: 6965 Location: porcelain throne
|
|
|
|
useit,
you are being a little stubborn:
| Skolusu wrote: |
| I guess we need to wait for the actual requirement once again? |
no one can give you a solution, because your requirements are not clear. |
|
| Back to top |
|
 |
Akatsukami
Global Moderator

Joined: 03 Oct 2009 Posts: 1787 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 |
Because the TS is incapable of writing a program? |
|
| Back to top |
|
 |
useit
Active User
Joined: 05 Oct 2006 Posts: 152
|
|
|
|
hi,
sorry what i posted is the actual requirement. i want to incorporate similar logic in my requirement. please suggest me some idea
REGDS,
USEIT |
|
| Back to top |
|
 |
enrico-sorichetti
Superior Member

Joined: 14 Mar 2007 Posts: 10903 Location: italy
|
|
|
|
| Quote: |
| can this be done through DFSORT?Could you please give me some hint? |
You were given one ...
to make the task easier split it into two logical steps
step 1 use joinkey to produce something like
| Code: |
key1 +10 +80
key1 +20
key1 +40
key2 -10 +10
key2 -20 |
most probably the trickiest part
after that it should not be difficult to obtain the final result
applying the logic I explained before |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
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. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
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...
| Code: |
KEY1 +0
KEY1 +0
KEY1 +10
KEY2 +0
KEY2 +40 |
|
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
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. |
|
| Back to top |
|
 |
useit
Active User
Joined: 05 Oct 2006 Posts: 152
|
|
|
|
hi,
i have taken similar examples and tried.am stuck in between.
input file1:
| Code: |
DEPOTA10
DEPOTA20
DEPOTA30 |
input file2:
in the first step i have summed up all the qty from file1 and overlayed at the end of each record.
output of first step:
| Code: |
DEPOTA1060
DEPOTA2060
DEPOTA3060 |
in the second step.
| Code: |
//STEP0100 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//INA DD *
DEPOTA1060
DEPOTA2060
DEPOTA3060
//INB DD *
DEPOTA50
//SORTOUTA DD SYSOUT=*
//SORTOUTB DD SYSOUT=*
//SYSIN DD *
OPTION COPY
JOINKEYS F1=INA,FIELDS=(1,5,A)
JOINKEYS F2=INB,FIELDS=(1,5,A)
JOIN UNPAIRED,F1
SORT FIELDS=(1,5,A)
REFORMAT FIELDS=(F1:1,10,F2:7,2)
OUTFIL FNAMES=SORTOUTA,
INCLUDE=(11,1,CH,EQ,C' '),
BUILD=(1,10)
OUTFIL FNAMES=SORTOUTB,
INCLUDE=(11,1,CH,NE,C' '),
IFTHEN=(WHEN=(9,2,ZD,GT,11,2,ZD),
OVERLAY=(9:(11,2,ZD,SUB,7,2,ZD),ZD,LENGTH=2),HIT=NEXT),
IFTHEN=(WHEN=(9,2,ZD,GT,7,2,ZD),
OVERLAY=(7:C'00'),HIT=NEXT),
IFTHEN=(WHEN=(9,2,ZD,LT,7,2,ZD),
OVERLAY=(7:(7,2,ZD,SUB,9,2,ZD),ZD,LENGTH=2),HIT=NEXT)
//* |
so the final output is
| Code: |
DEPOTA00
DEPOTA00
DEPOTA10 |
which is correct.
but if the second or first record itself has the higher value my solution will not work.
say for example:
input file1 :
| Code: |
DEPOTA10
DEPOTA50
DEPOTA30 |
input file2:
so my final output should be
| Code: |
DEPOTA00-----------------------(50-10=40)
DEPOTA10......................(40-50=-10)
DEPOTA30 |
kindly help me in this regard
Regds,
useit |
|
| Back to top |
|
 |
useit
Active User
Joined: 05 Oct 2006 Posts: 152
|
|
|
|
hi,
sorry for the late reply. i was not keeping well:(
Regds,
useit |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
You should be able to apply the solution for your previous topic to the calculation of the new balance.
The problem you face is the setting to zero of the others.
If you are happy with two steps it'll make things easier.
Did you look through my outline? Unfortunately I have temoporarily (at least) "lost" the actual solution I came up with... |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|