Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ 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
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    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

Frank Yaeger

DFSORT Moderator


Joined: 15 Feb 2005
Posts: 7130
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

New User


Joined: 07 Jul 2005
Posts: 51

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
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Check if any Detail records and extra... V S Amarendra Reddy SYNCSORT 19 Mon May 08, 2017 8:54 pm
No new posts Adding big TEXT lines to each record ... bshkris SYNCSORT 4 Sat May 06, 2017 1:40 am
No new posts SMTP the current generation number of... Jyothi Kulunde JCL & VSAM 4 Thu May 04, 2017 4:08 pm
This topic is locked: you cannot edit posts or make replies. Merge two files and update Trailer re... Yashashri JCL & VSAM 1 Thu May 04, 2017 12:54 pm
No new posts Sort Large record length cmsmoon DFSORT/ICETOOL 14 Tue Apr 11, 2017 5:49 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us