- subexprAny Type
Any valid expression that includes a field or a combination of fields from the current table or set that specifies what you want to examine.
When to reset the count to zero. Set GRP->Grand to count over the entire report.
What item to count (e.g. GRP->INV_NO to count each INV_NO in the group.)
Get the running count of subexpression over group 'over' sampled each group 'each'
The Group and Sub_Group are optional parameters that define the range of records to summarize, and may or may not be required, depending upon the context of the summary calculation. Possible values for GRP->Group and GRP->Sub_Group include:
GRAND (all records)
The name of the current table
The name of a table in the current set
The name of a grouping level that is defined in a report layout
DETAIL (over the records in the detail section)
RUN_COUNT() is used in the Detail section of a report to return the running count of records of the Expression evaluated from the first record to the current record related to the group. The expression is evaluated from the sub-group's first record to the current record, and the resulting count is returned.
For example, to summarize the line-items in an invoice set, the Group parameter might be GRP->INV_HEAD and the Sub_Group parameter GRP->INV_ITEM. This means the Summary operation includes only those child records in INV_ITEM related to the current parent record in the INV_HEAD table. To summarize all the records in a table or set, use the name GRAND as the Group name. The Group GRP->GRAND and Sub_Group GRP->INV_ITEM will produce a summary result based on all invoices.
This function is a report writer function, not intended for table level field rules or other expressions. While the function may perform in some areas outside of the report writer, its use there is not supported.
Assume that an invoicing set consists of two tables. One holds the invoices (INVOICE), and the other holds each invoice's line-items (INV_ITEM):
INVOICE is related to INV_ITEM through a one-to-many link on the INV_NO field. To find the running count of line-item records, use the following expressions:
run_count(INV_ITEM->AMOUNT) -> 9, if the current INV_NO is "I105" run_count(INV_ITEM->AMOUNT) -> 8, if the current INV_NO is "I104"
Using run_count() in Groups
If you wanted to produce a running count of all Invoices, you could define the following calculated field that would create a running count of each INVOICE (as opposed to each line item in each INVOICE.) In the example below, it's assumed that a Group Header has been defined in the Report that breaks on the INVOICE->INV_NO field:
invoiceCount = run_count(INVOICE->INV_NO,GRP->Grand,GRP->INV_NO)
This code creates a calculated field that computes a running total over the entire report (GRP->Grand) that is incremented every time the invoice number changes (GRP->INV_NO).
Once created, the calculated field can be inserted into the Group Header where desired.
In the example below, run_count() has been used to create counts for two groups: Country and City. Each country is enumerated with a number, as well as each city. The count resets to zero for the City every time a new Country is encountered. Two calculated fields were created with the following definition to generate the counts:
countryCount = run_count(country,GRP->Grand,GRP->Country) cityCount = run_count(city,GRP->Country,GRP->City)
The calculated fields were then placed in the Group Header for the Country and City groups, as shown in the image below.
The result is a report with numbered countries and cities, with the customers for each city listed in the detail:
You can click here to download the report used in this example.
This function is a report writer function, not intended for table level field rules or other expressions.