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

Percentage calculation from fields in different rows of file


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
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
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
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
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
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
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
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 2
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts To get the count of rows for every 1 ... DB2 3
Search our Forums:

Back to Top