Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
shuklas

New User

Joined: 21 Dec 2006
Posts: 20
Location: London

 Posted: Fri Mar 13, 2009 2:39 pm    Post subject: Count occuprance of | in a row 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.

vpalanivelu

New User

Joined: 24 Feb 2009
Posts: 14
Location: chennai

Posted: Fri Mar 13, 2009 4:24 pm    Post subject: Re: Reply to: Count occuprance of | in a row

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
Skolusu

Senior Member

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

Posted: Sat Mar 14, 2009 1:26 am    Post subject: Reply to: Count occuprance of | in a row

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:

www.ibm.com/systems/support/storage/software/sort/mvs/ugpf/
dick scherrer

Site Director

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

 Posted: Sat Mar 14, 2009 1:37 am    Post subject: 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) . . .
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics Creation of Datasets dynamically on t... Raghu M N DFSORT/ICETOOL 8 Fri Mar 16, 2018 12:56 am Skip records depends on count lakshmiibmmainframes DFSORT/ICETOOL 5 Sun Dec 24, 2017 9:51 pm ISMF Difference between volume count ... upendrasri IBM Tools 2 Tue Dec 05, 2017 12:40 pm How to write Rexx program to size and... sreejeshcs CLIST & REXX 14 Thu Oct 12, 2017 7:26 am column with count of rows within dist... ronald wouterson DB2 4 Sun Sep 17, 2017 9:48 pm

 © 2003-2017 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us