Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Intrinsic function to get max # of Occurs?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Is there some method to find the maximum number of occurrences in a table as can be done with the Visual Basic UBound command?
 
Hi Vbol,

Don't know of any intrinsic functs to do this, but if you have atable for e.g.:

01 ws-tbl.
05 ws-entry occurs x times.
10 ws-fld1
10 ws-fld2
etc.

You can: compute ws-occurs = length of ws-tbl / length of ws-entry

Don't know if this will work if you use ODO instead of occurs. You can test it easily enough; just exec the compute twice:

1) exec compute; display ws-occurs, result s/b x
2) move 1 to the ODO-fld before the compute; display ws-occurs, result s/b 1

If not I'm out of ideas.

Regards, Jack.
 
Let me add a bit here (and perhaps bollux up the works a bit :)

Are you talking about a variable length table or else a fixed-length table which isn't always filled each time you use it?

If it is a variable-length table, then you would set it up using a DEPENDING ON clause.

It would look something like this:
01 WS-NUM-OF-OCCURS PIC S9(4) COMP.
01 WS-TABLE.
05 WS-TABLE-FIELDS OCCURS 1 TO 1000 TIMES DEPENDING ON
WS-NUM-OF-OCCURS.
10 FIELD-1 PIC X(5).
10 FIELD-2 PIC X(10).

At the beginning of your program, you initiate WS-NUM-OF-OCCURS to the maximum value, which is +1000. Then, as you fill up your table with records, you use a counter, which will count the number of records actually loaded into your table.

When you get to the end of your file (or whatever), then you move the counter's value into WS-NUM-OF-OCCURS. And now you know how many records you actually have.

This seems like the easiest way to keep track of variable length tables.

You could also use a fixed-length table and then start loading it, using the same sort of counter. When you reach the end-of-file, then you have to make sure that the un-used portion of the table is filled with low-values (or spaces or whatever) rather than having random garbage.

Hope this helps, NIna Too

 
I was looking for a method that I could use to determine how many occurrences were in a fixed table without having to hard-code the occurrence number within COBOL statements e.g. PERFORM WS-OCCURRENCE TIMES. I guess I was looking for an equivalient of the VB UBound statement in COBOL without thinking about the division formula that can give the # of occurrences. It will work just the way I need it to. Much obliged, everyone!
 
Now I've got a question, about the divison formula. You all have my curiosity roiling. :)

Is the purpose of this division formula to find the number of actual occurences in a fixed-size table where not all the "slots" are being used? Because usually, the total number of occurences is a given in the OCCURS clause.

If you take the length of the table, will this value reflect the actual number of records filling the table? Or will it reflect the given number of occurrences specified in the OCCURS clause?

Thanks, Nina Too
 
Hi Vbol,

You can define the tbl as an indexed table and use the SEARCH verb. The AT END clause will tell you when EOT is reached. At end just set a switch to signal the perform to stop.

Depending on the application reqs, searching a tbl beyond the last entry in the tbl can be costly in CPU time. Use the ODO w/an indexed tbl and the loop will stop at the last entry.

Hope this helps, Jack.
 
Hi Vbol,

If you have a fld in an entry that appears in ascending (or descending) sequence in the table, you can use the ord-max (or max-min) intrinsic function available in any of the post COBOLII versions of COBOL. I don't know how that relates to PC COBOL. Here's an example:

compute nbr-of-entries = function (ord-max(seq-entry-fld))

Check the syntax; I coded that from memory.

Regards, Jack.
 
Thanks, Jack from me as well. I didn't know about the ord-max (or max-min) function in COBOL.

Nina Too
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top