IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Subtraction through DFSORT


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
useit

Active User


Joined: 05 Oct 2006
Posts: 152

PostPosted: Thu Apr 26, 2012 12:43 pm
Reply with quote

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.

Code:
key1 +80
key2 +10


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
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2481
Location: Netherlands, Amstelveen

PostPosted: Thu Apr 26, 2012 12:52 pm
Reply with quote

And now ?
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Thu Apr 26, 2012 1:05 pm
Reply with quote

Quote:
And now ?

the TS wants a solution, what else icon_wink.gif

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
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Thu Apr 26, 2012 2:10 pm
Reply with quote

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
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Thu Apr 26, 2012 10:24 pm
Reply with quote

I guess we need to wait for the actual requirement once again?
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Fri Apr 27, 2012 2:21 am
Reply with quote

Give the guy a break - he's only done 94 posts since 2006!
Back to top
View user's profile Send private message
useit

Active User


Joined: 05 Oct 2006
Posts: 152

PostPosted: Fri Apr 27, 2012 11:02 am
Reply with quote

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
View user's profile Send private message
useit

Active User


Joined: 05 Oct 2006
Posts: 152

PostPosted: Fri Apr 27, 2012 3:49 pm
Reply with quote

hi,
can this be done through DFSORT?Could you please give me some hint?

Regds,
useit
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Apr 27, 2012 4:25 pm
Reply with quote

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
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Fri Apr 27, 2012 4:32 pm
Reply with quote

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
View user's profile Send private message
useit

Active User


Joined: 05 Oct 2006
Posts: 152

PostPosted: Fri Apr 27, 2012 4:32 pm
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Fri Apr 27, 2012 6:08 pm
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Sat Apr 28, 2012 5:18 am
Reply with quote

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
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Apr 30, 2012 2:22 pm
Reply with quote

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 +10
KEY2 +40


Code:
KEY1 +0
KEY1 +0
KEY1 +10
KEY2 +0
KEY2 +40
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Mon Apr 30, 2012 2:46 pm
Reply with quote

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
View user's profile Send private message
useit

Active User


Joined: 05 Oct 2006
Posts: 152

PostPosted: Fri May 18, 2012 12:44 pm
Reply with quote

hi,
i have taken similar examples and tried.am stuck in between.

input file1:

Code:
DEPOTA10
DEPOTA20
DEPOTA30


input file2:

Code:
DEPOTA50



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:

Code:
DEPOTA50

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
View user's profile Send private message
useit

Active User


Joined: 05 Oct 2006
Posts: 152

PostPosted: Fri May 18, 2012 12:46 pm
Reply with quote

hi,
sorry for the late reply. i was not keeping well:(

Regds,
useit
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue May 22, 2012 3:54 am
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts DFsort help with SUM() DFSORT/ICETOOL 12
No new posts DFSORT - VB file RDW getting overridden DFSORT/ICETOOL 3
Search our Forums:

Back to Top