MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Summing up two columns for key records

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities
View previous topic :: View next topic  
Author Message
psmadhusudhan
Beginner


Joined: 28 Nov 2006
Posts: 143
Topics: 48

PostPosted: Wed May 12, 2010 3:31 am    Post subject: Summing up two columns for key records Reply with quote

I have an input file with following structure

01 RECORD.
02 KEY PIC X(32)
02 FIELD1 PIC S9(9)V99 COMP-3.
02 FIELD2 PIC S9(9)V99 COMP-3.

Following is the sample input file

Code:
----+----1----+----2----+----3----+----4----
********************************************
0742212345678901234567890666666A           
0742212345678901234567890666666A           
0742212345678901234567890666666A           
0742212345678901234567890666666A           
0742212345678901234567890666666A           
0742212345678901234567891666666B           
0742212345678901234567891666666B           
0742212345678901234567891666666B           
0742212345678901234567891666666B           
0742212345678901234567891666666B   
********************************************   


My requirement is that I need to sum up fields FIELD1 and FIELD2 for each record under
one key and write single record for each key in the output file with KEY field and
total value. In the above example file I have two keys. Assuming FIELD1 and FIELD2 values for first KEY records are 100.00 and 110.00 & for second record key FIELD1 AND FIELD2 values are 200.00 and 220.00 respectively. As comp-3 fields can't be displayed in browse mode I am unable to show them in above inputfile.

I need to have output file in following format:

Code:
----+----1----+----2----+----3----+----4----
********************************************
0742212345678901234567890666666A
0742212345678901234567891666666B   
********************************************


The totals beside first and second key should be 1050.00 and 2100.00
For exampl calculation for first key is (100.00 + 110.00)*5 = 1050.00
As I assumed FIELD1 and FIELD2 values to be equal for all 5 records I have shown it as multiplication by 5, in real scenario they will be different.

Please let me know how can I achieve this using DFSORT or ICETOOL.
_________________
Thanks
Madhu Sudhan
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Wed May 12, 2010 10:36 am    Post subject: Reply with quote

psmadhusudhan,

Use the following DFSORT JCL. This will create an output file with 32 bytes of key and 7 bytes of total value in PD format.

Code:

//STEP0100 EXEC PGM=SORT                             
//SYSOUT   DD SYSOUT=*                               
//SORTIN   DD DSN=Your input FB 44 byte file,DISP=SHR
//SORTOUT  DD SYSOUT=*                               
//SYSIN    DD *                                       
  SORT FIELDS=(1,32,CH,A),EQUALS                     
  SUM FIELDS=(33,6,PD,39,6,PD)                       
  OUTREC BUILD=(1,32,33,6,PD,ADD,39,6,PD,PD,LENGTH=7)
//*

_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
psmadhusudhan
Beginner


Joined: 28 Nov 2006
Posts: 143
Topics: 48

PostPosted: Wed May 12, 2010 11:18 pm    Post subject: Reply with quote

Thanks kolusu. It's working Smile
_________________
Thanks
Madhu Sudhan
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group