Joined: 09 Mar 2011
|Got an update for this. A Bug Fix, as the original FINDREP has no ENDPOS (so could get false hits if counting numerics). And a simplification, to use a binary count value instead of the character one.
The binary method can count up to 255 simply, and beyond would not be onerous.
|//HUMPHREY EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTOUT DD SYSOUT=*
//SYMNAMES DD *
* The character or string to be counted
* Contents of ARBITRARY-STRING are irrelevant, as long as one byte
* shorter than SEARCH-CHAR-OR-STRING.
* In binary, from zero to the maximum to be counted. If line is filled,
* multiple constants will be needed.
* Important - define the entire input record here.
* Define DUMMY... imemdiately after the record, it is "POSITION'ed" to
* Fields prefixed OUTPUT- are just for the example, not part
* of the solution.
* To locate to first byte after end of record.
* The following must be have the length of count constant(s), else some
* danger of a false hit.
* If the constant for the count required splitting (see above)
* then each part of the constant requires a unique starting position
* immediately after then end of the previous one.
* This will hold the count, in binary of length one, starting from zero
* and going up to maximum needed, to a maximum of 255.
//SYMNOUT DD SYSOUT=*
//SYSIN DD *
* IFOUTLEN is just for the example, not part of the solution.
* Establishes the count contant(s) in the extention to the input record.
* Does the required search, in the example from position 7 to position
* 80, change these to what is needed.
* The appended constant has been shifted left by the FINDREP for each
* instance of the character/string found, so that the first byte of the
* extended counts points to the count of times shifted.
* The leading part of the appended count constant has "underflowed"
* into the place established for it. The count of successful searches
* is just sitting there in a one-byte binary field.
* Just formatting for the output example.
//SORTIN DD *