Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Percentage calculation from fields in different rows of file

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
View previous topic :: :: View next topic  
Author Message
nave11

New User


Joined: 28 Oct 2008
Posts: 4
Location: Chennai

PostPosted: Wed Oct 29, 2008 1:12 pm    Post subject: Percentage calculation from fields in different rows of file
Reply with quote

Hi,

I am not sure if this is possible in SORT or not.

I have an input file as shown below:
----|----1----|----2----|----3----|----4----|----5----|----6----|----7----
AAAAAAAAAA COUNTX 25
BBBBBBBBBB COUNTP 50
CCCCCCCCCC COUNTU 75
AAAAAAAAAA COUNTY 75
BBBBBBBBBB COUNTQ 100
CCCCCCCCCC COUNTV 25

My output file should be:
----|----1----|----2----|----3----|----4----|----5----|----6----|----7----
AAAAAAAAAA COUNTX 25
BBBBBBBBBB COUNTP 50
CCCCCCCCCC COUNTU 75
AAAAAAAAAA COUNTY 75
PERCENTAGE 300.00
BBBBBBBBBB COUNTQ 100
PERCENTAGE 200.00
CCCCCCCCCC COUNTV 25
PERCENTAGE 33.33

Basically I need to find out the % of the counts given in record 4 against the record 1 of input file. ie., 75*100/25 = 300.00
Similarly record 5 (Vs) record 2 and record 6 (Vs) record 3.

This percentage should get written in the output file as shown above.

Kindly do the needful to resolve this problem.

Thanks,
Naveen.
Back to top
View user's profile Send private message

Skolusu

Senior Member


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

PostPosted: Wed Oct 29, 2008 10:47 pm    Post subject: Reply to: Percentage calculation from fields in different ro
Reply with quote

The following DFSORT/ICETOOL JCL will give you the desired results. I assumed that your input is RECFM FB and 80 bytes in length.

Code:

//STEP0100 EXEC PGM=ICETOOL                                         
//TOOLMSG  DD SYSOUT=*                                               
//DFSMSG   DD SYSOUT=*                                               
//IN       DD *                                                     
AAAAAAAAAA COUNTX  25                                               
BBBBBBBBBB COUNTP  50                                               
CCCCCCCCCC COUNTU  75                                               
AAAAAAAAAA COUNTY  75                                               
BBBBBBBBBB COUNTQ 100                                               
CCCCCCCCCC COUNTV  25                                               
//T1       DD DSN=&&T1,DISP=(,PASS),SPACE=(CYL,(1,1),RLSE)           
//OUT      DD SYSOUT=*                                               
//TOOLIN   DD *                                                     
  SORT FROM(IN) USING(CTL1)                                         
  SORT FROM(T1) USING(CTL2)                                         
//CTL1CNTL DD *                                                     
  OPTION EQUALS                                                     
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,8,ZD,90:6C'0',X))       
  SORT FIELDS=(1,10,CH,A)                                           
                                                                     
  OUTREC IFTHEN=(WHEN=INIT,OVERLAY=(89:SEQNUM,1,ZD,RESTART=(1,10))),
  IFTHEN=(WHEN=(89,1,ZD,EQ,1),OVERLAY=(90:19,3,SFF,ZD,LENGTH=3)),   
  IFTHEN=(WHEN=(89,1,ZD,EQ,2),OVERLAY=(93:19,3,SFF,ZD,LENGTH=3))     
                                                                     
  OUTFIL FNAMES=T1,REMOVECC,                                         
  SECTIONS=(1,10,                                                   
  TRAILER3=('PERCENTAGE',81:MAX=(81,8,ZD,M11,LENGTH=8),             
            90:TOT=(90,3,ZD,M11,LENGTH=3),                           
            93:TOT=(93,3,ZD,M11,LENGTH=3),                           
            'Y'))                                                   
/*                                                                   
//CTL2CNTL DD *                                                     
  OPTION EQUALS                                                     
  INREC IFTHEN=(WHEN=(96,1,CH,EQ,C'Y'),                             
  OVERLAY=(81:+1,ADD,81,8,ZD,M11,LENGTH=8,                           
           12:+10000,MUL,93,3,ZD,DIV,90,3,ZD,EDIT=(IIT.TT)))         
  SORT FIELDS=(81,8,CH,A)                                           
  OUTFIL FNAMES=OUT,BUILD=(1,80)                                     
/*                                                                   


the output from this job is

Code:

AAAAAAAAAA COUNTX  25   
BBBBBBBBBB COUNTP  50   
CCCCCCCCCC COUNTU  75   
AAAAAAAAAA COUNTY  75   
PERCENTAGE 300.00       
BBBBBBBBBB COUNTQ 100   
PERCENTAGE 200.00       
CCCCCCCCCC COUNTV  25   
PERCENTAGE  33.33       
Back to top
View user's profile Send private message
nave11

New User


Joined: 28 Oct 2008
Posts: 4
Location: Chennai

PostPosted: Thu Oct 30, 2008 5:55 pm    Post subject: Reply to: Percentage calculation from fields in different ro
Reply with quote

Hi,

Thanks a lot for your time and the code works fine. The idea is great.
But now I am facing a problem while getting a Count of Zero in the input file as shown below:
----|----1----|----2----|----3----|----4----|----5----|----6----|----7----
AAAAAAAAAA COUNTX 0
BBBBBBBBBB COUNTP 0
CCCCCCCCCC COUNTU 75
AAAAAAAAAA COUNTY 75
BBBBBBBBBB COUNTQ 100
CCCCCCCCCC COUNTV 25

The error message is 'INREC ARITHMETIC OVERFLOW'.
Kindly suggest me if you have any idea to resolve this.

Thanks,
Back to top
View user's profile Send private message
Skolusu

Senior Member


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

PostPosted: Thu Oct 30, 2008 9:45 pm    Post subject: Re: Reply to: Percentage calculation from fields in differen
Reply with quote

nave11 wrote:
Hi,
The error message is 'INREC ARITHMETIC OVERFLOW'.
Kindly suggest me if you have any idea to resolve this.
Thanks,


The arthimetic overflow is because you are dividing by zero which is infinity. Incase of zero how would you lke to calcuate the percentage?
Back to top
View user's profile Send private message
nave11

New User


Joined: 28 Oct 2008
Posts: 4
Location: Chennai

PostPosted: Fri Oct 31, 2008 5:33 pm    Post subject: Reply to: Percentage calculation from fields in different ro
Reply with quote

Hi,
In case of a zero, the percentage can be a zero.
Thanks,
Back to top
View user's profile Send private message
Skolusu

Senior Member


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

PostPosted: Fri Oct 31, 2008 9:20 pm    Post subject: Reply to: Percentage calculation from fields in different ro
Reply with quote

nave11,

Change your CTL2CNTL control cards to the following which will give you the desired results

Code:

//CTL2CNTL DD *                                               
  OPTION EQUALS                                               
  INREC IFTHEN=(WHEN=(96,1,CH,EQ,C'Y',AND,90,3,ZD,GT,0),     
  OVERLAY=(81:+1,ADD,81,8,ZD,M11,LENGTH=8,                   
           12:+10000,MUL,93,3,ZD,DIV,90,3,ZD,EDIT=(IIT.TT))),
  IFTHEN=(WHEN=(96,1,CH,EQ,C'Y',AND,90,3,ZD,EQ,0),           
  OVERLAY=(81:+1,ADD,81,8,ZD,M11,LENGTH=8,12:C'000.00'))     
  SORT FIELDS=(81,8,CH,A)                                     
  OUTFIL FNAMES=OUT,BUILD=(1,80)                             
/*                                                           
Back to top
View user's profile Send private message
nave11

New User


Joined: 28 Oct 2008
Posts: 4
Location: Chennai

PostPosted: Mon Nov 03, 2008 9:20 pm    Post subject:
Reply with quote

Hi Kolusu,
Thanks for your help. It worked great.

Thanks,
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts SORTJOIN - Copy Matched and Unmatched... Steve Ironmonger DFSORT/ICETOOL 4 Tue Jan 17, 2017 4:26 pm
No new posts DB2 query Using Recursion, Converting... smilewithashu2 DB2 1 Tue Jan 03, 2017 12:50 pm
No new posts Syncsort Help to group fields sudhakarraju SYNCSORT 6 Thu Dec 29, 2016 1:38 am
No new posts Copy RECFM =VB TO FB file with RECL =... sahil41352 DFSORT/ICETOOL 3 Wed Dec 28, 2016 11:29 pm
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us