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

Count occuprance of | in a row


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

New User


Joined: 21 Dec 2006
Posts: 20
Location: London

PostPosted: Fri Mar 13, 2009 2:39 pm
Reply with quote

Hi,

I have a requirement where I need to find the count for number of occurance of | in a single row.

Ex.

"asdsf"|1234|2009-09-01|"asdr"

The result of count should be: 3

Can Parse be used for this requirement.
Back to top
View user's profile Send private message
vpalanivelu

New User


Joined: 24 Feb 2009
Posts: 14
Location: chennai

PostPosted: Fri Mar 13, 2009 4:24 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
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Sat Mar 14, 2009 1:26 am
Reply with quote

shuklas,

Here is a DFSORT JCL which will give you the desired results. Using FINDREP we eliminate all character A thru Z and 0 thru 9 and ", - . By doing this we are only left with the character which you want to count. And now we convert this to VB file so that we get the accurate count of the characters. It also eliminates records without the | character

FINDREP function of DFSORT is available with z/OS DFSORT V1R5 PTF UK90013 (July, 2008)

Code:

//STEP0100 EXEC PGM=SORT                                           
//SYSOUT   DD SYSOUT=*                                             
//SORTIN   DD *                                                   
"ASDSF"|1234|2009-09-01|"ASDR"                                     
"ASDSF"|1234                                                       
"ASDSF"                                                           
//SORTOUT  DD DSN=&&T1,DISP=(,PASS),SPACE=(CYL,(1,1),RLSE)         
//SYSIN    DD *                                                   
  SORT FIELDS=COPY                                                 
  INREC FINDREP=(IN=(C'A',C'B',C'C',C'D',C'E',C'F',C'G',C'H',C'I',
                     C'J',C'K',C'L',C'M',C'N',C'O',C'P',C'Q',C'R',
                     C'S',C'T',C'U',C'V',C'W',C'X',C'Y',C'Z',C'0',
                     C'1',C'2',C'3',C'4',C'5',C'6',C'7',C'8',C'9',
                     C'"',C'-'),OUT=C'')                           
  OUTFIL FTOV,VLTRIM=C' ',OMIT=(1,1,CH,NE,C'|')                   
//*                                                               
//STEP0200 EXEC PGM=SORT                                           
//SYSOUT   DD SYSOUT=*                                             
//SORTIN   DD DSN=&&T1,DISP=SHR                                   
//SORTOUT  DD SYSOUT=*                                             
//SYSIN    DD *                                                   
  SORT FIELDS=COPY                                                 
  OUTFIL VTOF,BUILD=(5,1,C' COUNT = ',1,2,BI,SUB,+4,M10,LENGTH=5) 
/*                                                                 


The output from this job is
Code:

| COUNT =     3 
| COUNT =     1 

If you don't have the July, 2008 PTF installed, ask your System Programmer to install it (it's free).

For complete details on the new FINDREP and the other new functions available with PTF UK90013, see:

Use [URL] BBCode for External Links
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sat Mar 14, 2009 1:37 am
Reply with quote

Hello,

Suggest if the file has 100 million records some other solution would be a far better use of the system.

To simply count the |'s, there will be 100 million "writes" and then another 100 million reads to actually get the count. . .

This to get around 5 minutes of writing code? (read, inspect/tallying, add to total - at eof display the total) . . .
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts To get the count of rows for every 1 ... DB2 3
No new posts To find whether record count are true... DFSORT/ICETOOL 6
No new posts Validating record count of a file is ... DFSORT/ICETOOL 13
No new posts Insert header record with record coun... DFSORT/ICETOOL 14
No new posts Count the number of characters in a f... CA Products 1
Search our Forums:

Back to Top