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

Find how many times a value has repeated in the array


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
prabhucs01
Warnings : 1

New User


Joined: 07 Mar 2005
Posts: 43

PostPosted: Thu Aug 02, 2007 7:30 pm
Reply with quote

I have an array of 100 records. I want to know how many times a particular value has repeated in the array.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Thu Aug 02, 2007 8:01 pm
Reply with quote

Scan through the array and count the number of times "a particular value" is repeated.......
Back to top
View user's profile Send private message
ashwinreddy

Active User


Joined: 16 Sep 2004
Posts: 106
Location: Hyderabad

PostPosted: Thu Aug 02, 2007 8:01 pm
Reply with quote

Can you expand your request whether you should do it in cobol program, if so its simple

like take the 1 array value and compare it with all the other value from array value two

keep on incrementing a counter when you get a match.

cheers
Ashwin
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: Fri Aug 03, 2007 12:27 am
Reply with quote

Hello,

Is it acceptable to have the same value in the array more than one time?

If this is not valid, how is the array populated? As the array is being populated, the code could look at the previous entries in the array and determine if this is a "new" value or is it is already in the array.

If you post more detail on your requirement, we will be able to offer better suggestonis.
Back to top
View user's profile Send private message
balakrishna reddy

Active User


Joined: 13 Jul 2007
Posts: 128
Location: Guntur

PostPosted: Fri Aug 03, 2007 11:52 am
Reply with quote

hi prabhu,

Quote:

I have an array of 100 records. I want to know how many times a particular value has repeated in the array


You can do it using search verb also.
Code:

working-storage section.
01 I       pic  9(3).
01 temp pic  9(3) value '1'.
01  tab1 occurs 100 times indexed by I.
     05  val    pic x(20).
procedure division.
perform para-1
para-1.
        move temp to I.
        search tab1 at end go to para-exit
                 when val(I) not = 'bala'
                          set I up by 1.
          if (I <= 100)
              move I to temp
              add 1 to counter
             go to para-1
          end-if.
para-exit.
         exit.


Please correct me if i am wrong icon_neutral.gif
Back to top
View user's profile Send private message
jasorn
Warnings : 1

Active User


Joined: 12 Jul 2006
Posts: 191
Location: USA

PostPosted: Tue Aug 07, 2007 4:25 pm
Reply with quote

You could also you inspect tallying.
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts To find whether record count are true... DFSORT/ICETOOL 6
No new posts Build a record in output file and rep... DFSORT/ICETOOL 11
No new posts Find the size of a PS file before rea... COBOL Programming 13
No new posts COBOL Ascending and descending sort n... COBOL Programming 5
No new posts Find the occurrence of Key Field (Par... DFSORT/ICETOOL 6
Search our Forums:

Back to Top