Page 1 of 1

Multiply or divide records in a file

PostPosted: Fri Jun 17, 2011 11:50 am
by Puffe
Hi,

I have a file (lrecl=10,recfm=fb) containing several records.
What I want to achieve is to count records with the same value in position 6 and 2 long.
At the same time I want another field in the output file where you multiply the sum of counted records with 4.
Yet another field in the output file I want is to divide by 2 and rounded up.
So far I've managed to do the counted records in SYSIN-statement but not the multiply/divide-statements.

//SORTIN DD *
ABC1233ABA
ABD1233ABA
BBB2233BBA
ABD1244ABA
BBB1244BBA
CCC1244CCC

//SYSIN DD *
INREC FIELDS=(6,2,7X)
INCLUDE COND=(10,1,CH,EQ,C'A')
SORT FIELDS=(1,2,CH,A)
OUTFIL REMOVECC,NODETAIL,
SECTIONS=(1,2,
TRAILER3=(1,2,COUNT=(EDIT=(IIIIIIT))))

This result in the file
33 3
44 2

But I want (*4) (/2)
33 3 12 2
44 2 4 1

Suggestions?

Micke

Re: Multiply or divide records in a file

PostPosted: Fri Jun 17, 2011 9:22 pm
by skolusu
Puffe,

The following DFSORT JCL will give you the desired results. You will 8 bytes of total number of records in position 3 and 10 bytes of total*4 and another 8 bytes of total/2 rounded. All of them have the leading zeroes supressed.

//STEP0100 EXEC PGM=SORT                                         
//SYSOUT   DD SYSOUT=*                                           
//SORTIN   DD *                                                 
ABC1233ABA                                                       
ABD1233ABA                                                       
BBB2233BBA                                                       
ABD1244ABA                                                       
BBB1244BBA                                                       
CCC1244CCC                                                       
//SORTOUT  DD SYSOUT=*                                           
//SYSIN    DD *                                                 
  INCLUDE COND=(10,1,CH,EQ,C'A')                                 
  INREC BUILD=(6,2,7C'0',C'1')                                   
  SORT FIELDS=(1,2,CH,A)                                         
  SUM FIELDS=(3,8,ZD)
                                           
  OUTREC IFOUTLEN=28,IFTHEN=(WHEN=INIT,                         
  BUILD=(1,2,3,8,ZD,M10,LENGTH=8,+4,MUL,3,8,ZD,M10,LENGTH=10,   
         3,8,ZD,MUL,+100,DIV,+2,EDIT=(IIIIIIII.TT))),           
  IFTHEN=(WHEN=(30,2,ZD,NE,0),                                   
  OVERLAY=(21:+1,ADD,21,8,UFF,M10,LENGTH=8))                     
//*


The output from the above job is
33       3        12       2
44       2         8       1

Re: Multiply or divide records in a file

PostPosted: Mon Jun 20, 2011 10:13 am
by Puffe
Thanks !

A lots of new commands I've never used before. Now I've to learn a little bit more of them

Re: Multiply or divide records in a file

PostPosted: Mon Jun 20, 2011 10:48 am
by Puffe
Hi again.

Is it possible for you, skolusu, to explain the sort step by step from statement OUTREC?

Re: Multiply or divide records in a file

PostPosted: Mon Jun 20, 2011 10:40 pm
by Frank Yaeger
If you're not familiar with DFSORT and DFSORT's ICETOOL, I'd suggest reading through "z/OS DFSORT: Getting Started". It's an excellent tutorial, with lots of examples, that will show you how to use DFSORT, DFSORT's ICETOOL and DFSORT Symbols. You can access it online, along with all of the other DFSORT books, from:

http://www.ibm.com/support/docview.wss? ... g3T7000080