View previous topic :: View next topic
|
Author |
Message |
prabhucs01 Warnings : 1 New User
Joined: 07 Mar 2005 Posts: 43
|
|
|
|
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 |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Scan through the array and count the number of times "a particular value" is repeated....... |
|
Back to top |
|
|
ashwinreddy
Active User
Joined: 16 Sep 2004 Posts: 106 Location: Hyderabad
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
balakrishna reddy
Active User
Joined: 13 Jul 2007 Posts: 128 Location: Guntur
|
|
|
|
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 |
|
Back to top |
|
|
jasorn Warnings : 1 Active User
Joined: 12 Jul 2006 Posts: 191 Location: USA
|
|
|
|
You could also you inspect tallying. |
|
Back to top |
|
|
|