I know there has to be an easier way to do this… I have a file that has say 200 records. Part of each record contains a form #. All I I want to group and summarize how many times each form occurs in those 200 records.
So for 200 records you would get something like this:
Form # # of Occurrences
12344 100
26351 10
85963 10
63693 2
98745 78
74582 100
Total number of records = 200
Well, may be there is one of course, but may I ask you: why don’t you like doing this task in your OWN way? If it works properly, why do you need another solution (especially for such a small number of records)?
Any way, I would NOT look for that “easier way”
If your FORM number is a descriptor on the file, you can get what you want with a simple histogram:
DEFINE DATA LOCAL
1 FILE-HIST VIEW OF FILE
2 FORM-NBR
1 #TOTAL (I4)
END-DEFINE
*
HIST.
HISTOGRAM FILE-HIST FORM-NBR
DISPLAY FORM-NBR *NUMBER(HIST.)
ADD *NUMBER(HIST.) TO #TOTAL
END-HISTOGRAM
WRITE '=' #TOTAL
END
If FORM-NBR is not a descriptor, or you need to get more info from each file record, you could read the file, sort by form number and us at break logic.
DEFINE DATA LOCAL
1 FILE VIEW OF FILE
2 FORM-NBR
END-DEFINE
*
RD.
READ FILE FORM-NBR
END-ALL
SORT BY FORM-NBR
USING KEYS
AT BREAK OF FORM-NBR
DISPLAY OLD(FORM-NBR) *COUNT(FORM-NBR)
END-BREAK
END-HISTOGRAM
WRITE '=' *COUNTER(RD.)
END
First, if FORM-NUMBER is a descriptor, use Jerome’s HISTOGRAM code.
If not, rather than using SORT, it might (I have not done a timing comparison yet) be faster to do something like:
DEFINE DATA LOCAL
1 FILE-HIST VIEW OF FILE
2 FORM-NBR
1 #COUNTS (I2/0:99999)
1 #LOOP (I2)
END-DEFINE
*
READ FILE-HIST
ADD 1 TO #COUNTS (FORM-NBR)
END-READ
*
FOR #LOOP = 0 to 99999
IF #COUNTS (#LOOP) NE 0
DISPLAY #LOOP#COUNTS (#LOOP)
END-IF
END-FOR
END
How do I change the rating I gave you?? uggg… Thank you, this is exactly … great example. 2nd is what I will need. Am I able to add a where statement in with this too? I tried and getting errors.
With a HISTOGRAM statement, you must reference a view that has only one field, namely the field to be HISTOGRAM’ed. Remember, HISTOGRAM does not read records, it only accesses the inverted tables. Thus you do not have access to other fields.
You can have a WHERE clause, but it would be something like:
HISTOGRAM MYVIEW FIELD1
WHERE FIELD1 NE ‘C’ THRU ‘G’
The WHERE clause as mentioned above could not reference a FIELD2.
If you are using the READ loop, there should be no problem with the WHERE clause. Very straightforward; for example:
Adabas, I got pulled away from this project and getting back on it today. I will let you know how I make out. Thank you for our help, this site is great!