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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Keycounts in Cobol

Status
Not open for further replies.

supra94red

Programmer
Nov 27, 2002
11
US
Hi was wondering if anyone has a COBOL algorithm handy
that would perform a keycount on a specified field.
For example, lets say I wanted a keycount on a state
field in a sequential file of 1 million records and
I want it to return a report that looks something like
the following:

State Count
------ --------
IL 50,000
CA 500,000
WI 50,000
MA 100,000
OR 300,000
Total: 1,000,000
 
I think I figured it out. I can probably
do it with a one-level control break.
 
Yep, that's right. Just a single level control break.

I had to set one up yesterday.

Be sure to re-initialize your state counter to zeroes after
each control break. You probably know that anyway.

I haven't written Cobol in over 7 months until a week ago so I'm still trying to get back up to speed.

Good luck in your efforts,

Oldcoboler
 
"keycount"? The messages above assume the input file is sorted on the State field, right? Else I can't make sense out of your response of single-level control break. I was thinking more in line of a program that could process an unsorted file and produce the same result, by using a table.
I must be missing something here, "keycount"?
 
You could probably get the same result from a sorting utility like syncsort which can also condense on a value and count the no. of records condensed. Moreover, it would probably be faster.
Other then that, indeed, sort on key, process each key until level break while counting and display or write results.
--------
Regards,
Ronald.
 
AustinOne, I think you're right in that the input file
will have to be sorted on state field for this to work.
I need an algorithm to process an unsorted file and will
probably have to go back to my original plan of using
tables. I'm trying to use this as part of my data
validation program so I really don't want to add an
additional syncsort step, especially when I need counts
on several fields.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top