COUNTING
Syntax
![]()
Command
Mandatory parameter Optional parameter Mandatory keyword Optional keyword |
INSPECT (<Variable>)
COUNTING (<Result>, <Option>[, <Search> |
<Search array>][, <Condition>, <Value>])
ENDINSPECT
Description
This command counts the number of times the value(s) specified in <Search> or <Search array> is (are) found in <Variable>. The result of the count is added to the current value of the variable <Result>. When a BEFORE or AFTER condition is specified, the count will stop at <Value> or start after <Value>.
Diagram
Returned value type
None
Parameters
Parameter | Description | |||
<Variable> |
The variable to be inspected | |||
<Result> |
The variable to return the result of the count in | |||
<Option> | CHARACTERS | Counts all the characters that are in <Variable> or when a BEFORE or AFTER is specified all the
characters in <Variable> that corresponds with the BEFORE or AFTER condition. When the
CHARACTERS option has been specified, the <Search> or <Search array> parameter
should be omitted.
|
||
ALL | Counts all occurrences of <Search> or all occurrences of the elements of <Search array> in <Variable>. | |||
LEADING | On the condition that the first character in <Variable> matches <Search> all the successive occurrences of <Search> will be counted. | |||
TRAILING | On the condition that the last character in <Variable> matches <Search> all the backwards counted successive occurrences of <Search> will be counted. I.e. this option does the exact opposite of LEADING. | |||
<Search> | Specification of a character or string to be searched for in <Variable>. | |||
<Search array> | Array of search characters or strings in the format: [ <search 1>, <search 2>, ... ]. The [] square brackets are mandatory. | |||
<Condition> | BEFORE | Specifies a BEFORE condition. I.e. the counting will start at the beginning of <Variable> and stop at the first occurrence of <Value> in <Variable>. | ||
AFTER | Specifies an AFTER condition. I.e. the counting will start directly after the occurrence of <Value> in <Variable> till the end of <Variable>. | |||
<Value> | The start/stop character of string to use in the BEFORE or AFTER condition. |
Remarks
INSPECT COUNTING has two different possible ways of behaviour.
- The original IBM Cobol behaviour of the Inspect Tallying command whereby the count result is added to the current value of the used count variable.
- The AMT behaviour whereby the result variable is initialized to zero at the start of the count and the count result will therefore replace any value that was in the result variable before the count.
The way the INSPECT COUNTING will behave can be set in the Application Options of the application. This setting will then apply for the complete application.
Note: The behaviour changed between the different patches of AMT. Up to AMT Patch 6 the second way of behaviour was supported. Since this differed from the original IBM Cobol Tallying behaviour this was seen as a bug and therefore corrected to the first way of behaviour in Patch 6. But some customers had already adopted the second way of behaviour in their code and therefore we now support both ways as of Patch 6 Fix 2. |
Example
va-inspect := '**AB**CD**EF'
inspect (va-inspect)
counting (result, all, '*')
counting (result, all, [ '*', 'C', 'D' ])
counting (result, all, '*', before, 'C')
counting (result, characters, before, 'C')
counting (result, leading, '*')
counting (result, trailing, '*')
endinspect
inspect (va-inspect)
counting (result, all, '*')
counting (result, all, [ '*', 'C', 'D' ])
counting (result, all, '*', before, 'C')
counting (result, characters, before, 'C')
counting (result, leading, '*')
counting (result, trailing, '*')
endinspect