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

Count and Average


IBM Mainframe Forums -> JCL & VSAM
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
shrivatsa
Warnings : 1

Active User


Joined: 17 Mar 2006
Posts: 174
Location: Bangalore

PostPosted: Tue Jun 07, 2011 7:05 pm
Reply with quote

Hi,

I have input file as below
LRECL=80 FB

Code:
Hello World      01RES
Hello World      01RES
Hello World      01RES
Hello World      01RES
Hello World      02RES
Hello World      02RES
Hello World      02RES
Hello World      02RES
Hello World      02RES
TRAINING         03TER
TRAINING         03TER
TRAINING         03TER


Output report Required in below format
Code:

DEPT           COUNT   AVERAGE%
---------      -----  ---------
Hello World      04   33.33
Hello World      05   41.66
TRAINING         03   25.00


Average is calculated as (number of occurance of record per group of DEPT and number by total number of records *100)
Back to top
View user's profile Send private message
Skolusu

Senior Member


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

PostPosted: Tue Jun 07, 2011 9:55 pm
Reply with quote

shrivatsa,

The following DFSORT JCL will give you the desired results.

Code:

//STEP0100 EXEC PGM=SORT                                 
//SYSOUT   DD SYSOUT=*                                   
//INA      DD *                                         
HELLO WORLD      01RES                                   
HELLO WORLD      01RES                                   
HELLO WORLD      01RES                                   
HELLO WORLD      01RES                                   
HELLO WORLD      02RES                                   
HELLO WORLD      02RES                                   
HELLO WORLD      02RES                                   
HELLO WORLD      02RES                                   
HELLO WORLD      02RES                                   
TRAINING         03TER                                   
TRAINING         03TER                                   
TRAINING         03TER                                   
//INB      DD *                                         
HELLO WORLD      01RES                                   
HELLO WORLD      01RES                                   
HELLO WORLD      01RES                                   
HELLO WORLD      01RES                                   
HELLO WORLD      02RES                                   
HELLO WORLD      02RES                                   
HELLO WORLD      02RES                                   
HELLO WORLD      02RES                                   
HELLO WORLD      02RES                                   
TRAINING         03TER                                   
TRAINING         03TER                                   
TRAINING         03TER                                   
//SORTOUT  DD SYSOUT=*                                   
//SYSIN    DD *                                                   
  JOINKEYS F1=INA,FIELDS=(20,1,A)                                 
  JOINKEYS F2=INB,FIELDS=(01,1,A)                                 
  JOIN UNPAIRED                                                   
  REFORMAT FIELDS=(F1:1,20,F2:2,8)                                 
  INREC BUILD=(1,28,X,C'00000001')                                 
  SORT FIELDS=(1,19,CH,A)                                         
  SUM FIELDS=(30,8,ZD)                                             
  OUTREC OVERLAY=(40:(+10000,MUL,30,8,ZD),DIV,21,8,ZD,EDIT=(TT.TT))
  OUTFIL REMOVECC,NODETAIL,BUILD=(80X),                           
  HEADER2=('DEPT                    COUNT  AVERAGE%',/,           
           '-------------------- --------  --------'),             
  SECTIONS=(1,19,TRAILER3=(1,19,22:30,8,35:40,5))                 
//JNF1CNTL DD *                                                   
  INREC BUILD=(1,19,X)                                             
//JNF2CNTL DD *                                                   
  INREC BUILD=(X,C'00000001')                                     
  SUM FIELDS=(2,8,ZD)                                             
//*


The output from this job is
Code:

DEPT                    COUNT  AVERAGE%
-------------------- --------  --------
HELLO WORLD      01  00000004     33.33
HELLO WORLD      02  00000005     41.66
TRAINING         03  00000003     25.00
Back to top
View user's profile Send private message
shrivatsa
Warnings : 1

Active User


Joined: 17 Mar 2006
Posts: 174
Location: Bangalore

PostPosted: Tue Jun 07, 2011 10:03 pm
Reply with quote

Hi Skolusu,

Very perfect. Thanks for your time in providing the solution.
I was playing around with one file. Can you please tell me what has given you the idea to achieve this solution by using same input file 2 times?
Back to top
View user's profile Send private message
Skolusu

Senior Member


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

PostPosted: Tue Jun 07, 2011 10:08 pm
Reply with quote

shrivatsa wrote:
Hi Skolusu,

Very perfect. Thanks for your time in providing the solution.
I was playing around with one file. Can you please tell me what has given you the idea to achieve this solution by using same input file 2 times?


shrivatsa,

You can still do with 1 file but would require 2 passes of data. I just eliminated the 2 passes and clubbed the solution into 1 pass. Nothing fancy in there as it is just another programming approach.
Back to top
View user's profile Send private message
gylbharat

Active Member


Joined: 31 Jul 2009
Posts: 565
Location: Bangalore

PostPosted: Wed Jun 08, 2011 12:46 pm
Reply with quote

Hi Skolusu,

I ran this job but got the below error
Code:

PARMEXIT : VSCORET=12M,MSG=SC                                                 
SYSIN :                                                                       
  JOINKEYS F1=INA,FIELDS=(20,1,A)                                             
           *                                                                   
  JOINKEYS F2=INB,FIELDS=(01,1,A)                                             
           *                                                                   
  JOIN UNPAIRED                                                               
  REFORMAT FIELDS=(F1:1,20,F2:2,8)                                             
  INREC BUILD=(1,28,X,C'00000001')                                             
  SORT FIELDS=(1,19,CH,A)                                                     
  SUM FIELDS=(30,8,ZD)                                                         
  OUTREC OVERLAY=(40:(+10000,MUL,30,8,ZD),DIV,21,8,ZD,EDIT=(TT.TT))           
  OUTFIL REMOVECC,NODETAIL,BUILD=(80X),                                       
  HEADER2=('DEPT                    COUNT  AVERAGE%',/,                       
           '-------------------- --------  --------'),                         
  SECTIONS=(1,19,TRAILER3=(1,19,22:30,8,35:40,5))                             
WER161B  ALTERNATE PARM USED                                                   
WER268A  JOINKEYS STATEMENT: SYNTAX ERROR                                     
WER268A  JOINKEYS STATEMENT: SYNTAX ERROR                                     
WER211B  SYNCSMF  CALLED BY SYNCSORT; RC=0000                                 
WER449I  SYNCSORT GLOBAL DSM SUBSYSTEM ACTIVE                                 
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Wed Jun 08, 2011 1:11 pm
Reply with quote

WER449I SYNCSORT GLOBAL DSM SUBSYSTEM ACTIVE
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Wed Jun 08, 2011 2:07 pm
Reply with quote

Look at the syntax of JOINKEYS for SyncSort and all will be forgiven, provided you're using the realse of the product which supports the JOINKEYS functionality.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Wed Jun 08, 2011 9:13 pm
Reply with quote

Quote:
Look at the syntax of JOINKEYS for SyncSort and all will be forgiven, provided you're using the realse of the product which supports the JOINKEYS functionality.


This statement is misleading. DFSORT supports JNFxCNTL for modifying the records from the input files before they are joined. Syncsort does not support JNFxCNTL. So with Syncsort, you'd actually need multiple steps to do what DFSORT can do in one step.
Back to top
View user's profile Send private message
Skolusu

Senior Member


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

PostPosted: Wed Jun 08, 2011 10:18 pm
Reply with quote

gylbharat wrote:
Hi Skolusu, I ran this job but got the below error


gylbharat,

I know you are eager to learn and experiment every possible solution, but you need to understand that you are using syncsort which is a competitor product for DFSORT and not all features of DFSORT are supported by syncsort. 99.99% of the time , I do test my solutions before I post them. So if you are getting an error , then you need to realize that it is your sort product that has the problem and not the solution provided.

I'm a DFSORT developer. I'm happy to answer questions on DFSORT and DFSORT's ICETOOL, but I don't answer questions on syncsort.
Back to top
View user's profile Send private message
gylbharat

Active Member


Joined: 31 Jul 2009
Posts: 565
Location: Bangalore

PostPosted: Thu Jun 09, 2011 12:53 pm
Reply with quote

Thanks Skolusu
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 -> JCL & VSAM

 


Similar Topics
Topic Forum Replies
No new posts To get the count of rows for every 1 ... DB2 3
No new posts To find whether record count are true... DFSORT/ICETOOL 6
No new posts Validating record count of a file is ... DFSORT/ICETOOL 13
No new posts Insert header record with record coun... DFSORT/ICETOOL 14
No new posts Timestamp difference and its average ... DB2 11
Search our Forums:

Back to Top