Page 1 of 1

Count number of records and combine it..

PostPosted: Fri Oct 07, 2011 11:20 am
by anchal jain
Hi,
I have a dataset having some records as follows

DEM|JH|I|1234
DEM|JH|I|1235
DEM|JH|O|2115
DEM|FR|I|2536
DEM|FR|O|5264

I want to count the number of records of each type and write them in following format

DEM|JH|2|1
DEM|FZ|1|1

Here the third field is number of records of type 'I' and fourth field is number of records of type 'O'.

I used following JCL

//JBSTEP01 EXEC PGM=SORT                                       
//SORTIN   DD DISP=SHR,DSN=IMAN.FILE1                           
//SORTOUT  DD DSN=IMAN.FILE2,                                   
//         DISP=(NEW,CATLG,DELETE),                                 
//         SPACE=(CYL,(550,500),RLSE),                         
//         UNIT=SYSDA                                           
//SYSOUT   DD SYSOUT=*                                         
//SYSIN    DD *                                                 
 INCLUDE COND=(1,8,CH,EQ,C'DEM|JH|I')                             
 SORT FIELDS=(1,9,CH,A)                                         
 OUTFIL REMOVECC,NODETAIL,                                     
  TRAILER1=('CDEM|JH|',COUNT=(M10,LENGTH=8))                   
//*

This gave me number of records of type 'I' , so I applied same step again for type 'O'.These two different steps output is like
DEM|JH|2
DEM|JH|1
DEM|FZ|1
DEM|FZ|1

but I want both the records to be written in same line as follows the first count should be of type 'I' and second should be of type 'O'.

DEM|JH|2|1
DEM|FZ|1|1

Your help is most appreciated.
Thank you.

Re: Count number of records and combine it..

PostPosted: Fri Oct 07, 2011 10:32 pm
by Frank Yaeger
Your description is very confusing. You are sorting the records but you don't show the output in correct sorted order. You have FR for the input records but you have FZ for the output records.

If I understand what you're trying to do, you can use a DFSORT job like the following:

//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
DEM|JH|I|1234
DEM|JH|I|1235
DEM|JH|O|2115
DEM|FR|I|2536
DEM|FR|O|5264
EEE|XX|I|1111
EEE|XX|I|2222
EEE|XX|I|3333
EEE|XX|O|4444
EEE|XX|O|4444
FFF|BB|I|5555
GGG|BB|O|5555
//SORTOUT DD SYSOUT=*
//SYSIN DD *
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:C'00')),
        IFTHEN=(WHEN=(8,1,CH,EQ,C'I'),OVERLAY=(81:C'1')),
        IFTHEN=(WHEN=(8,1,CH,EQ,C'O'),OVERLAY=(82:C'1'))
  SORT FIELDS=(1,6,CH,A)
  OUTFIL REMOVECC,NODETAIL,
    BUILD=(80X),
    SECTIONS=(1,6,
      TRAILER3=(1,7,TOT=(81,1,ZD,EDIT=(TTTTT)),C'|',
                    TOT=(82,1,ZD,EDIT=(TTTTT))))
/*


SORTOUT would have:

DEM|FR|00001|00001
DEM|JH|00002|00001
EEE|XX|00003|00002
FFF|BB|00001|00000
GGG|BB|00000|00001


If that's not what you want, then you need to do a better job of explaining what you do want.

Re: Count number of records and combine it..

PostPosted: Mon Oct 10, 2011 3:35 pm
by anchal jain
Thanks a lot Frank. I apologize to make it confusing I will take care of it next time that I sound clear to everyone. That 'FR' was typo mistake it is 'FZ' everywhere, but you answered exect what I was looking for. It's rally a great help for me.

Thank you very much.