HP 3000 Manuals

EXAMINE Statement [ HP COBOL II/XL Reference Manual ] MPE/iX 5.0 Documentation


HP COBOL II/XL Reference Manual

EXAMINE Statement 

The EXAMINE statement is an HP extension to the ANSI COBOL standard.  It
has been replaced by the INSPECT statement, covered later in this
chapter.  Although HP COBOL II includes the EXAMINE statement for
compatibility with COBOL'68, it is advisable that you use the INSPECT
statement for coding new programs.

The EXAMINE statement replaces or counts the number of occurrences of a
given character in a data item.

Syntax 

[]
Parameters identifier names a data item whose usage is DISPLAY. It is this data item that is examined. literal-1, each a single character whose data type is the same as literal-2, identifier. Any or all of these literals may be any and so figurative constant except ALL. forth Description When the EXAMINE statement is executed, it acts differently depending upon whether identifier names a numeric or a nonnumeric data item. If identifier is a nonnumeric data item, examination begins with the leftmost character, and proceeds to the right. Each character is examined in turn. If identifier is a numeric data item, the data item may contain a sign, and examination proceeds on a digit by digit basis. This examination starts with the leftmost digit and proceeds to the right. If a sign is included in the data item being examined, it is ignored regardless of its physical location. TALLYING Phrase When the TALLYING phrase is used in an EXAMINE statement, a count is placed in the special HP COBOL II register named TALLY. This count is an integer and represents a value that is dependent upon the keywords following the word TALLYING. If TALLYING UNTIL FIRST is specified, the integer in the TALLY register after execution of an EXAMINE statement is the number of occurrences of characters in identifier before the first occurrence of literal-1. If TALLYING ALL is specified, every occurrence of literal-1 is counted and the result of this counting is placed in the TALLY register. If TALLYING LEADING is specified, only those occurrences of literal-1 that precede any other characters in the data item named by identifier are counted. For example, if the first character of identifier is not literal-1, the EXAMINE statement ceases execution immediately. If the REPLACING phrase is used in conjunction with the TALLYING phrase, then, depending upon which keywords are used with the TALLYING phrase, those occurrences of literal-1 that participate in the tallying are replaced by literal-2. For example, if the EXAMINE statement: EXAMINE ABMASK TALLYING ALL A REPLACING BY B. is executed and ABMASK contains the value ABBBBABBABAAAB before execution, when execution of the EXAMINE statement is complete, the value in the TALLY register is 6 and ABMASK contains the value BBBBBBBBBBBBBB. REPLACING Phrase The REPLACING phrase acts in the same manner as the REPLACING verb in the TALLYING phrase. However, since no tallying takes place, the TALLY register remains unchanged. The rules of the REPLACING phrase are stated below: * If REPLACING ALL is specified, all occurrences of literal-3 in identifier are replaced by literal-4. * If REPLACING LEADING is specified, each occurrence of literal-3 is replaced by literal-4 until the first occurrence of a character other than literal-3 or the rightmost character of the data item is examined. * If REPLACING UNTIL FIRST is specified, every character of the data item represented by identifier is replaced by literal-4 until literal-3 is encountered in the data item. If literal-3 does not appear in the data item, the entire data item is filled with literal-4. * If REPLACING FIRST is specified, only the first occurrence of literal-3 is replaced by literal-4. If literal-3 does not appear in the data item represented by identifier, the data item is unchanged after execution of the EXAMINE statement.


MPE/iX 5.0 Documentation