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

Count number occurence of character in each row/record


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
pushpagiri

New User


Joined: 07 Jul 2005
Posts: 51

PostPosted: Mon Dec 05, 2005 12:35 pm
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
Frank Yaeger

DFSORT Developer


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

PostPosted: Mon Dec 05, 2005 9:46 pm
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

New User


Joined: 07 Jul 2005
Posts: 51

PostPosted: Tue Dec 06, 2005 12:07 pm
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
View previous topic : : View next topic  
Post new topic   Reply to topic All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts count contained values of several col... DB2 5
No new posts DB2 Query to get the count of Unique ... DB2 2
No new posts To Discard record with 0 entry if Dup... SYNCSORT 7
No new posts Compare the member of two pds on las... DFSORT/ICETOOL 13
No new posts To Populate Trailer cnt in the file w... SYNCSORT 1
Search our Forums:


Back to Top