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

count no.of occurrences


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

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Tue Jul 10, 2012 4:03 pm
Reply with quote

Hi,

I have a file (LRECL=80, RECFM=FB) with data to count no.of occurrences of a word "ORDER" appearing somewhere in each line.

Code:

DATA00001000ORDER
DATAORDER01003903
DATA39ORDER394301
DATA0975ORDER1930


Output:
Code:

ORDER 4


Please let me know how to get it done using OCCURS operator of DFSORT.....we are using Z/OS DFSORT V1R10.

Thanks.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Jul 10, 2012 4:07 pm
Reply with quote

Do you mean OCCURS of ICETOOL?

Why not INCLUDE/OMIT with SS, and use reporting functions of OUTFIL to produce a TRAILERn with your COUNT and text, using NODETAIL and REMOVECC?

There are examples here.
Back to top
View user's profile Send private message
ramsri

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Tue Jul 10, 2012 4:16 pm
Reply with quote

Bill, what should I omit? All the records have ORDER appearing somewhere in it !!!

Thanks.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Jul 10, 2012 4:17 pm
Reply with quote

So are you really saying you want to know how many records there are on the file, since that is what it comes down to if all contain the text "ORDER"?
Back to top
View user's profile Send private message
ramsri

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Tue Jul 10, 2012 4:19 pm
Reply with quote

Code:

//STEPONE1 EXEC PGM=ICETOOL                         
//SYSOUT   DD SYSOUT=*                               
//TOOLMSG  DD SYSOUT=*                               
//DFSMSG   DD SYSOUT=*                               
//IN       DD *                                     
ABC001      JKEHFKNDVJWVMFGRB                       
ABC001      FBREBHEFBRGFBTBGG                       
ABC001      REGFEVRHGERVERGRE                       
ABC002      GREGERGRBGETBHTBB                       
ABC002      GREVBRGREGGRRGGRE                       
//OUT      DD SYSOUT=*                               
//TOOLIN   DD *                                     
  OCCUR FROM(IN) LIST(OUT) ON(1,6,CH)  ON(VALCNT) - 
  NOHEADER BLANK                                     
/*                                                   


In fact, I found above example in this forum but don't know how to adjust it to my requirement. Because, in my case, ORDER is appearing at different places icon_sad.gif

Please help.

Thanks.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Jul 10, 2012 4:24 pm
Reply with quote

Have you looked at the manual? You can't just find a "solution" to something and hope that you can tweak it to become a "solution" to your problem.
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: Tue Jul 10, 2012 9:39 pm
Reply with quote

Hello,

Why do you believe you need to use OCCURS?

If ORDER is in Every record, why do you need to do anything other than get the count?

Did you read about SS (which will accommodate the changing position of the ORDER value)?

You posted a solution for something maybe similar, but not the output from the run. . .

The biggest part of getting help from a forum is what you provide for the helpers to work with.
Back to top
View user's profile Send private message
Skolusu

Senior Member


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

PostPosted: Tue Jul 10, 2012 9:47 pm
Reply with quote

ramsri,

Use the following JCL which will give you the desired results

Code:

//STEP0100 EXEC PGM=SORT                   
//SYSOUT   DD SYSOUT=*                     
//SORTIN   DD *                             
DATA00001000ORDER                           
DATAORDER01003903                           
DATA39ORDER394301                           
DATA0975ORDER1930                           
//SORTOUT  DD SYSOUT=*                     
//SYSIN    DD *                             
  INCLUDE COND=(1,80,SS,EQ,C'ORDER')       
  SORT FIELDS=COPY                         
  INREC BUILD=(C'O')                       
  OUTFIL REMOVECC,NODETAIL,BUILD=(16X),     
  TRAILER1=('ORDER ',COUNT=(M10,LENGTH=10))
//*
Back to top
View user's profile Send private message
ramsri

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Wed Jul 11, 2012 8:22 am
Reply with quote

Kolusu, thank you very much for the trick......now, we at least know that OCCURS has got some limitations and could not do this !

Thanks again.
Back to top
View user's profile Send private message
ramsri

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Wed Jul 11, 2012 2:06 pm
Reply with quote

Hi,

Is it possible to modify this solution to get count of more than one?

Input:
Code:

DATA00001000ORDER
DATAORDER01003903
BATA39ORDER394301
DATA0975ORDER1930


Output:
Code:

ORDER 3
BATA  1


Thanks.
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2455
Location: Hampshire, UK

PostPosted: Wed Jul 11, 2012 2:14 pm
Reply with quote

What does your reading of the manual and your experiments tell you?
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Jul 11, 2012 2:18 pm
Reply with quote

I see four ORDERs. What would be the rules for getting your count to 3?
Back to top
View user's profile Send private message
ramsri

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Wed Jul 11, 2012 3:25 pm
Reply with quote

Yes Bill.......sorry for the typo......

Output:
Code:

ORDER 4
BATA  1


Thanks.
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2481
Location: Netherlands, Amstelveen

PostPosted: Wed Jul 11, 2012 3:30 pm
Reply with quote

And now you have 5 records, instead of 4.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2481
Location: @my desk

PostPosted: Wed Jul 11, 2012 3:39 pm
Reply with quote

Peter, some records have both icon_smile.gif
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2481
Location: Netherlands, Amstelveen

PostPosted: Wed Jul 11, 2012 3:42 pm
Reply with quote

Arun Raj wrote:
Peter, some records have both icon_smile.gif


Sure Arun, we all know that. But how about the end user (if there is one)?
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Jul 11, 2012 4:28 pm
Reply with quote

You need two counts for your values. These can be at the "front" of the record as you don't need the data.

Use IFOUTLEN to limit the size of the record to your counts.

Use IFTHEN=(WHEN=INIT to initialise your counts

Use IFTHEN=(WHEN=(logexp) with SS to find each field and set count to 1, remembering to use HIT=NEXT on the first.

Use the reporting functions to add up the fileds and format your desired output.
Back to top
View user's profile Send private message
Skolusu

Senior Member


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

PostPosted: Wed Jul 11, 2012 10:03 pm
Reply with quote

ramsri,

Use the following DFSORT JCL

Code:

//STEP0100 EXEC PGM=SORT                                       
//SYSOUT   DD SYSOUT=*                                         
//SORTIN   DD *                                                 
DATA00001000ORDER                                               
DATAORDER01003903                                               
BATA39ORDER394301                                               
DATA0975ORDER1930                                               
//SORTOUT  DD SYSOUT=*                                         
//SYSIN    DD *                                                 
  INCLUDE COND=(1,80,SS,EQ,C'ORDER',OR,                         
                1,80,SS,EQ,C'BATA')                             
                                                               
  SORT FIELDS=COPY                                             
  INREC IFOUTLEN=2,IFTHEN=(WHEN=INIT,BUILD=(2C'0',1,80)),       
  IFTHEN=(WHEN=(3,80,SS,EQ,C'ORDER'),OVERLAY=(1:C'1'),HIT=NEXT),
  IFTHEN=(WHEN=(3,80,SS,EQ,C'BATA'),OVERLAY=(2:C'1'))           
                                                               
  OUTFIL REMOVECC,NODETAIL,BUILD=(16X),                         
  TRAILER1=('ORDER ',TOT=(1,1,ZD,M10,LENGTH=10),/,             
            'BATA  ',TOT=(2,1,ZD,M10,LENGTH=10))               
//*
Back to top
View user's profile Send private message
ramsri

Active User


Joined: 18 Oct 2008
Posts: 380
Location: India

PostPosted: Thu Jul 12, 2012 8:22 am
Reply with quote

Hi Kolusu, thanks a lot for this useful sort card icon_biggrin.gif
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 Exclude rows with > than x occurre... DFSORT/ICETOOL 6
No new posts Insert header record with record coun... DFSORT/ICETOOL 14
Search our Forums:

Back to Top