Portal | IBM Manuals | Downloads | Products | Refer | Info | Programs | JCLs | Forum Rules*| Site Map | Mainframe CD 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index
 
Register
 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index FAQ Search Memberlist Usergroups Profile Log in to check your private messages Log in
 
Count number occurence of character in each row/record

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
Author Message
pushpagiri

Active User


Joined: 07 Jul 2005
Posts: 50

PostPosted: Mon Dec 05, 2005 12:35 pm    Post subject: Count number occurence of character in each row/record
Reply with quote

Hi,

I want to count occurence of a character in each record and write the record and count to outfile.
Exampe:(count 'x' in each row)
infile :

aaaaxxaaaaaxxxx
aaaaaaffdfxmm
dddddxxxdddddd

outfile :

aaaaxxaaaaaxxxx 6
aaaaaaffdfxmm 1
dddddxxxdddddd 3

Is this possible through DFSORT/any JCL ?
I don't want to do this using COBOL/any Programs .
Back to top
View user's profile Send private message
References
Frank Yaeger

DFSORT Moderator


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

PostPosted: Mon Dec 05, 2005 9:46 pm    Post subject:
Reply with quote

Assuming there are no numbers in the characters for which you want to count x's, you can use this DFSORT job to do what you asked for:

Code:

//S1    EXEC  PGM=ICEMAN
//SYSOUT    DD  SYSOUT=*
//SORTIN DD *
aaaaxxaaaaaxxxx
aaaaaaffdfxmm
dddddxxxdddddd
//SORTOUT DD SYSOUT=*
//SYSIN    DD    *
  OPTION COPY
* Change 'x' to '1'
  ALTSEQ CODE=(A7F1)
* Copy 1-15 to 21-35 and change each 'x' to a '1' in 21-35.
  INREC FIELDS=(1,15,21:1,15,TRAN=ALTSEQ)
* Get total of 1s in 21-35 (with FS, letters will be treated as 0).
  OUTREC FIELDS=(1,15,X,
    21,1,FS,ADD,22,1,FS,ADD,23,1,FS,ADD,24,1,FS,ADD,25,1,FS,ADD,
    26,1,FS,ADD,27,1,FS,ADD,28,1,FS,ADD,29,1,FS,ADD,30,1,FS,ADD,
    31,1,FS,ADD,32,1,FS,ADD,33,1,FS,ADD,34,1,FS,ADD,35,1,FS,
    TO=FS,LENGTH=3)
/*


SORTOUT will have:

Code:

aaaxxaaaaaxxxx   6
aaaaaffdfxmm     1
ddddxxxdddddd    3


If there are numbers in the characters for which you want to count x's, change the ALTSEQ statement to:

Code:

  ALTSEQ CODE=(A7F1,F1F0,F2F0,F3F0,F4F0,F5F0,F6F0,F7F0,F8F0,F9F0) 


This will ensure that numbers are counted as 0s and only x's are counted as 1s.
Back to top
View user's profile Send private message
pushpagiri

Active User


Joined: 07 Jul 2005
Posts: 50

PostPosted: Tue Dec 06, 2005 12:07 pm    Post subject:
Reply with quote

Hi Frank,

Thanks for the solution.It works fine.
i got to know more about ADD in outrec.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1