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

Finding the count of filled elements in an array.


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sivakumar M

New User


Joined: 03 Jul 2011
Posts: 8
Location: india

PostPosted: Wed Nov 02, 2011 11:34 pm
Reply with quote

Hi All,

I do have question in OCCURS class in COBOL. I have an array which is of length 100. In that array if I need to know the count of filled element, is there a way to do it through any keyword?

I can do it by reading the array until it meets the NULL value and I can display the count value. But is there any short way to do it?

Example:

A(1) = 5
A(2) = 8
A(3) = NULL
A(4) = NULL

Required O/P = 2; Please suggest me.
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 Nov 02, 2011 11:40 pm
Reply with quote

No arrays in Cobol. Table, yes. The length of a Cobol table is length of occurs item time no of occurs.

To your question, don't you keep track of what you put in the table, so that you know how many are there all along without having to do any sort of other stuff? If you read this from a file, there should be a count of the no of entries occupied on the file.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Wed Nov 02, 2011 11:46 pm
Reply with quote

You could -

01) Keep a counter-variable in WS, adding one to the counter each time an element is added.

02) Use the SEARCH Verb until you find an element that equals LOW-VALUES. To avoid the SEARCH, check element number 100 for not equal to LOW-VALUES (Table is FULL) as well as element number 001 for equal to LOW-VALUES (Table is EMPTY).

Mr. Bill
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: Thu Nov 03, 2011 10:12 am
Reply with quote

Hello,

NULL is not a value - it is a condition. Do you mean x'00' or x'40' or something is "null"?

When you put things into the array, you could save a "high-water" mark and know without looking which was the last element used. . .
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 Finding and researching jobs All Other Mainframe Topics 0
No new posts To get the count of rows for every 1 ... DB2 3
No new posts VB to FB - Finding LRECL SYNCSORT 4
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
Search our Forums:

Back to Top