Procedure Division (cont.) [ COBOL/HP-UX Language Reference for the Series 700 and 800 ] MPE/iX 5.0 Documentation
COBOL/HP-UX Language Reference for the Series 700 and 800
Procedure Division (cont.)
The EXIT Statement
Function
The EXIT statement provides a common end point for a series of
procedures.
________________________________________________________________________
|The EXIT statement can also exit an inline PERFORM, a paragraph or a |
|section. (MF) |
________________________________________________________________________
The EXIT PROGRAM statement marks the logical end of a called program.
________________________________________________________________________
|You can also return values to calling programs written in any |
|language. (MF) |
________________________________________________________________________
General Formats
Format 1
EXIT
Format 4
Syntax Rules
Format 1
1. The EXIT statement should appear in a sentence by itself.
________________________________________________________________________
|This rule is not enforced. (MF) |
________________________________________________________________________
2. The EXIT sentence should be the only sentence in the paragraph.
________________________________________________________________________
|This rule is not enforced. (OSVS) (MF) |
________________________________________________________________________
________________________________________________________________________
|(MF) |
| |
|Format 2 |
| |
| |
| |
|3. A Format 2 EXIT statement can be used only within an inline |
| PERFORM. |
| |
| |
|Format 3 |
| |
| |
| |
|4. A Format 3 EXIT statement with the PARAGRAPH phrase must be |
| contained in a paragraph. |
| |
|5. A Format 3 EXIT statement with the SECTION phrase must be |
| contained in a section. |
| |
________________________________________________________________________
Format 4
6. If an EXIT PROGRAM statement appears in a consecutive sequence of
imperative statements within a sentence, it must not appear as the
last statement in that sequence.
________________________________________________________________________
|This rule is not enforced. (VSC2) (MF) |
________________________________________________________________________
7. There must be no sentence other than the EXIT PROGRAM sentence in
the paragraph.
________________________________________________________________________
|This rule is not enforced. (VSC2) (MF) |
________________________________________________________________________
________________________________________________________________________
|(MF) |
| |
| |
| |
|8. Literal-1 must be an integer. |
| |
|9. Data-name-1 can be specified anywhere within the Data Division. |
| |
|10. The value is passed in COMP-5 formt. |
| |
|11. If the SIZE clause is present, literal-1 must be numeric. |
| |
________________________________________________________________________
General Rules
Format 1
1. An EXIT statement serves only to enable the user to assign a
procedure-name to a given point in a program. Such an EXIT
statement has no other effect on the compilation or execution of
the program.
________________________________________________________________________
|(MF) |
| |
|Format 2 |
| |
| |
| |
|2. The execution of an EXIT PERFORM statement without a CYCLE phrase|
| causes control to be passed to an implicit CONTINUE statement, |
| immediately following the END-PERFORM associated with the nearest|
| inline PERFORM statement. |
| |
|3. The execution of an EXIT PERFORM statement with a CYCLE phrase |
| causes control to be passed to an implicit CONTINUE statement, |
| immediately preceding the END-PERFORM associated with the nearest|
| inline PERFORM statement. |
| |
| |
|Format 3 |
| |
| |
| |
|4. The execution of a Format 3 EXIT statement with the PARAGRAPH |
| phrase causes control to pass to an implicit CONTINUE statement |
| immediately preceding: |
| |
| |
| a. The next paragraph or section header, whichever comes |
| first. |
| |
| b. The end of the source program if no paragraph or section |
| header appears between this EXIT statement and the end of |
| the source program. |
| |
|5. The execution of a Format 3 EXIT statement with the SECTION |
| phrase causes control to pass to an implicit CONTINUE statement |
| immediately preceding: |
| |
| |
| a. The next section header. |
| |
| b. Or immediately before the end of the source program if no |
| section header appears between this EXIT statement and the|
| end of the source program. |
| |
________________________________________________________________________
________________________________________________________________________
|(ANS85) |
| |
|Format 4 |
| |
| |
| |
|6. If the EXIT PROGRAM statement is executed in a program which is |
| not under the control of a calling program, the EXIT PROGRAM |
| statement causes execution of the program to continue with the |
| next executable statement. |
| |
|7. The execution of an EXIT PROGRAM statement in a called program |
| which does not possess the initial attribute causes execution to |
| continue with the next executable statement following the CALL |
| statement in the calling program. The program state of the |
| calling program is not altered and is identical to that which |
| existed at the time it executed the CALL statement except that |
| the contents of data items and the contents of data files shared |
| between the calling and called program can have been changed. |
| The program state of the called program is not altered |
| except that the ends of the ranges of all PERFORM statements |
| executed by that called program are considered to have been |
| reached. |
| |
|8. Besides the actions specified in General Rule 7, the execution of|
| an EXIT PROGRAM statement in a called program which possesses the|
| initial attribute is equivalent to also executing a CANCEL |
| statement referencing that program except that the statement will|
| not free any memory. See the section "The CANCEL Statement" |
| earlier in this chapter. |
| |
|9. An EXIT PROGRAM statement must not be executed while executing a |
| declarative procedure in which the GLOBAL phrase is specified |
| except within a program called while executing that declarative |
| procedure. |
| |
________________________________________________________________________
________________________________________________________________________
|(MF) |
| |
| |
| |
|10. If the GIVING phrase is not specified in the calling program the |
| GIVING phrase of the EXIT PROGRAM statement is returned into the |
| RETURN-CODE special register of the calling program. |
| |
|11. The size of GIVING fields is limited to four bytes. Specific |
| operating systems or COBOL implementations can have different |
| limits. See your COBOL System Reference for additional |
| information. |
| |
|12. For a system in which COMP-5 fields are stored in "reverse order"|
| an implicit (invisible to the program/programmer) move will occur|
| from an implicit COMP-5 item to a receiving binary field |
| upon program entry when a BY VALUE phrase is specified in |
| either a PROCEDURE USING or an ENTRY USING statement if |
| the GIVING field is defined as BINARY, COMP, COMP-4, or |
| COMP-X. |
| |
|13. GIVING items are not affected by the RTNCODE-SIZE directive. |
| |
|14. The SIZE clause defines the number of PIC X characters to be |
| passed. |
| |
|15. If the RETURN-CODE special register is used either as the CALL |
| GIVING field or in an EXIT PROGRAM, STOP RUN, or GOBACK |
| GIVING, but not both, then the receiving field will be in |
| reverse order in systems which store COMP-5 fields in reverse |
| order). |
| |
|16. It is the programmer's responsibility to ensure that fields |
| referenced in a BY VALUE phrase agree as to size and USAGE in |
| both the calling and called program. In cases where these rules |
| are violated, results are unpredictable. However, there will be |
| no compile-time verification of this. |
| |
| In cases such as COMP-5 and Pointer data items where, in |
| some COBOL systems, they are implicitly identical storage |
| definitions in the current implementation, mixing these different|
| USAGEs in the calling and called programs can currently |
| give the desired results, but upward compatibility is not |
| guaranteed. |
| |
________________________________________________________________________
________________________________________________________________________
|The GOBACK Statement |
| |
|(OSVS) (VSC2) (MF) |
| |
|Function |
| |
|The GOBACK statement marks the logical end of a called program. |
| |
|You can also return values to calling programs written in any language|
|or to the operating system environment. (MF) |
________________________________________________________________________
General Format
________________________________________________________________________
|(OSVS) (VSC2) (MF) |
| |
|Syntax Rules |
| |
| |
| 1. A GOBACK statement should appear as the only statement, or as |
| the last of a series of imperative statements, in a sentence, |
| because any statements following the GOBACK are not executed. |
| However, violation of this rule is not rejected at compile |
| time. |
| |
| 2. Literal-1 must be an integer. (MF) |
| |
| 3. Data-name-1 can be specified anywhere within the Data Division.|
| (MF) |
| |
| 4. The SIZE clause defines the number of bytes to be passed. The |
| value is passed in COMP-5 format. (MF) |
| |
| 5. If the SIZE clause is present, literal-1 must be numeric. |
| (MF) |
| |
|General Rules |
| |
| |
| 1. If program execution reaches a GOBACK statement while operating|
| under control of a calling program, control returns to the |
| point immediately following the CALL statement in the calling |
| program as in the EXIT PROGRAM statement. |
| |
| 2. If program execution reaches a GOBACK statement in a main |
| program, the GOBACK statement causes program termination, as in|
| the STOP RUN statement. |
| |
| 3. A GOBACK statement must not be executed while executing a |
| declarative procedure in which the GLOBAL phrase is specified |
| except within a program called while executing that declarative|
| procedure. |
________________________________________________________________________
________________________________________________________________________
|(OSVS) (VSC2) (MF) |
| |
| |
| |
|4. If the program is called but the GIVING phrase is not specified |
| in the calling program, the GIVING phrase of the GOBACK statement|
| is returned into the RETURN-CODE special register of the calling |
| program. |
| |
|5. The size of the GIVING fields is limited to four bytes. Specific|
| operating systems or COBOL implementations can have different |
| limits. See your COBOL System Reference for additional |
| information. |
| |
|6. For a system in which COMP-5 fields are stored in "reverse order"|
| an implicit (invisible to the program/programmer) move will occur|
| from an implicit COMP-5 item to a receiving binary field |
| upon program entry when a BY VALUE phrase is specified in |
| either a PROCEDURE USING or an ENTRY USING statement if |
| the GIVING field is defined as BINARY, COMP, COMP-4, or |
| COMP-X. |
| |
|7. GIVING items are not affected by the RTNCODE-SIZE directive. |
| |
|8. If the Return-Code special register is used either as the CALL |
| GIVING field or in an EXIT PROGRAM, STOP RUN, or GOBACK GIVING, |
| but not both, then the receiving field will be in reverse |
| order (in systems which store COMP-5 fields in reverse |
| order). |
| |
|9. It is the programmer's responsibility to ensure that fields |
| referenced in a BY VALUE phrase agree as to size and USAGE in |
| both the CALLing and CALLed program. In cases where these rules |
| are violated, results are unpredictable. However, there will be |
| no compile-time verification of this. |
| |
| In cases such as COMP-5 and Pointer data items where, in |
| some COBOL systems, they are implicitly identical storage |
| definitions in the current implementation, mixing these different|
| USAGEs in the CALLing and CALLed programs can currently |
| give the desired results, but upward compatibility is not |
| guaranteed. |
| |
________________________________________________________________________
The GO TO Statement
Function
The GO TO statement causes control to be transferred from one part of the
Procedure Division to another.
________________________________________________________________________
|(ANS85) |
|The option of omitting procedure-name-1 in a Format 1 GO TO statement |
|is classed as an obsolete element in the ANSI'85 standard and is |
|scheduled to be deleted from the next full revision of the ANSI |
|Standard. |
________________________________________________________________________
________________________________________________________________________
|(MF) |
|All dialects within this COBOL implementation fully support this |
|syntax. Refer to your COBOL System Reference for details on |
|using the FLAGSTD directive to detect all occurrences of this |
|syntax. |
________________________________________________________________________
________________________________________________________________________
|(XOPEN) |
|Although it is a part of the standard COBOL definition, omitting the |
|procedure name in Format 1 is explicitly excluded from the X/Open |
|COBOL language definitions and should not be used in an X/Open COBOL |
|conforming source program. |
________________________________________________________________________
General Formats
Format 1
GO TO [procedure-name-1]
Format 2
GO TO procedure-name-1 [procedure-name-2] ... DEPENDING ON identifier
Syntax Rules
1. Identifier is the name of a numeric elementary item which is an
integer.
2. When a paragraph is referenced by an ALTER statement, that
paragraph can consist only of a paragraph header followed by a
Format 1 GO TO statement.
3. A Format 1 GO TO statement, without procedure-name-1, can only
appear in a single statement paragraph.
________________________________________________________________________
|This restriction is not enforced. (MF) |
________________________________________________________________________
4. If a GO TO statement represented by Format 1 appears in a
consecutive sequence of imperative statements within a sentence,
it must appear as the last statement in that sequence.
5. In Format 2, at least two procedure names should be specified.
________________________________________________________________________
|(ANS85) |
|A Format 2 statement can be written with only one procedure |
|name. |
________________________________________________________________________
General Rules
1. When a GO TO statement, represented by Format 1 is executed,
control is transferred to procedure-name-1 or to another
procedure-name if the GO TO statement has been modified by an
ALTER statement.
2. If procedure-name-1 is not specified in Format 1, an ALTER
statement, referring to this GO TO statement, must be executed
prior to the execution of this GO TO statement.
________________________________________________________________________
|(VSC2) (MF) |
|If an ALTER statement referring to the paragraph containing this GO TO|
|statement has not been executed before this GO TO statement |
|is executed, this GO TO statement is treated like a CONTINUE |
|statement. |
________________________________________________________________________
3. When a GO TO statement represented by Format 2 is executed,
control is transferred to procedure-name-1, procedure-name-2, and
so on, depending on the value of the identifier being 1, 2, ...,
n. If the value of the identifier is anything other than the
positive or unsigned integers 1, 2, ..., n, then no transfer
occurs and control passes to the next statement in the normal
sequence for execution.
The IF Statement
Function
The IF statement causes a condition to be evaluated (see the section
"Conditional Expressions" earlier in this chapter). The subsequent
action of the object program depends on whether the value of the
condition is true or false.
General Format
Syntax Rules
1. Statement-1 and statement-2 represent either an imperative
statement or a conditional statement optionally preceded by an
imperative statement.
2. If the END-IF phrase is specified, the NEXT SENTENCE phrase must
not be specified. (ANS85)
NEXT SENTENCE can be specified with END-IF. (VSC2) (MF)
If the NEXT SENTENCE phrase is executed, control will not pass to
the next statement following the END-IF, but instead will pass to
the statement after the closest following period.
General Rules
1. The scope of an IF statement can be terminated by any of the
following:
a. An END-IF phrase at the same level of nesting.
b. A separator period.
c. If nested, by an ELSE phrase associated with an IF
statement at a higher level of nesting.
2. When an IF statement is executed, the following transfers of
control occur:
a. If the condition is true, statement-1 is executed if
specified. If statement-1 contains a procedure branching
or conditional statement, control is explicitly transferred
in accordance with the rules of that statement. If
statement-1 does not contain a procedure branching or
conditional statement, the ELSE phrase, if specified, is
ignored and control passes to the end of the IF statement.
b. If the condition is true and the NEXT SENTENCE phrase is
specified instead of statement-1, the ELSE phrase, if
specified, is ignored and control passes to the next
executable sentence.
c. If the condition is false, statement-1 or its surrogate
NEXT SENTENCE is ignored, and statement-2, if specified, is
executed. If statement-2 contains a procedure branching or
conditional statement, control is explicitly transferred in
accordance with the rules of that statement. If
statement-2 does not contain a procedure branching or
conditional statement, control passes to the end of the IF
statement. If the ELSE statement-2 phrase is not
specified, statement-1 is ignored and control passes to the
end of the IF statement.
d. If the condition is false, and the ELSE NEXT SENTENCE
phrase is specified, statement-1 is ignored, if specified,
and control passes to the next executable sentence.
3. Statement-1 and/or statement-2 can contain an IF statement. In
this case the IF statement is said to be nested.
________________________________________________________________________
|(ANS85) |
|IF statements within IF statements are considered matched IF, ELSE, |
|and END-IF ordered combinations, proceeding from left to right. Thus,|
|any ELSE encountered is matched with the nearest preceding IF that has|
|not been already matched with an ELSE or has not been implicitly or |
|explicitly terminated. Any END-IF encountered is matched with the |
|nearest preceding IF that has not been implicitly or explicitly |
|terminated. |
________________________________________________________________________
________________________________________________________________________
|The INITIALIZE Statement |
| |
|(ANS85) |
| |
|Function |
| |
|The INITIALIZE statement provides the ability to set selected types of|
|data fields to predetermined values; for example, numeric data to |
|zeros or alphanumeric data to spaces. |
________________________________________________________________________
General Format
________________________________________________________________________
|(ANS85) |
| |
|Syntax Rules |
| |
| |
| 1. Literal-1 and the data item referenced by identifier-2 |
| represent the sending area; the data item referenced by |
| identifier-1 represents the receiving area. |
| |
| 2. Each category stated in the REPLACING phrase must be a |
| permissible category as a receiving operand in a MOVE statement|
| where the corresponding data item referenced by identifier-2 or|
| literal-1 is used as the sending operand. (See the section The|
| MOVE Statement later in this chapter.) |
| |
| 3. The same category cannot be repeated in a REPLACING phrase. |
| |
| 4. The description of the data item referenced by identifier-1 or |
| any items subordinate to identifier-1 can not contain the |
| DEPENDING phrase of the OCCURS clause. |
| |
| The data item referenced by identifier-1 can not be variably |
| located, that is, can not follow an item containing the |
| DEPENDING phrase of the OCCURS clause. (VSC2) |
| |
| The data item referenced by identifier-1 can be variably |
| located, that is, can follow an item containing the DEPENDING |
| phrase of the OCCURS clause. (MF) |
| |
| 5. An index data item can not appear as an operand of an |
| INITIALIZE statement. |
| |
| 6. The data description entry for the data item referenced by |
| identifier-1 must not contain a RENAMES clause. |
| |
| 7. A floating-point data item or literal can be used anywhere a |
| numeric identifier or literal is specified. (MF) (VSC2) |
________________________________________________________________________
________________________________________________________________________
|(ANS85) |
| |
|General Rules |
| |
| |
| 1. The key word following the word REPLACING corresponds to a |
| category of data as defined elsewhere in this document. (See |
| the section "Concepts of Classes of Data" in the chapter |
| COBOL Concepts.) |
| |
| 2. Whether identifier-1 references an elementary item or a group |
| item, all operations are performed as if a series of MOVE |
| statements had been written, each of which has an elementary |
| item as its receiving field, subject to the following |
| rules: |
| |
| If the REPLACING phrase is specified: |
| |
| |
| a. If identifier-1 references a group item, any elementary |
| item within the data item referenced by identifier-1 is |
| initialized only if it belongs to the category specified|
| in the REPLACING phrase. |
| |
| b. If identifier-1 references an elementary item, that item|
| is initialized only if it belongs to the category |
| specified in the REPLACING phrase. |
| |
| This initialization takes place as follows: the data item |
| referenced by identifier-2 or literal-1 acts as the sending |
| operand in an implicit MOVE statement to the identified |
| item. |
| |
| All such elementary receiving fields, including all occurrences|
| of table items within the group, are affected; the only |
| exceptions are those fields specified in General Rules 3 and |
| 4. |
| |
| 3. Index and pointer data items and elementary FILLER data |
| items are not affected by the execution of an INITIALIZE |
| statement. |
________________________________________________________________________
________________________________________________________________________
| |
| 4. Any item that is subordinate to a receiving area identifier and|
| which contains the REDEFINES clause or any item that is |
| subordinate to such an item is excluded from this operation. |
| However, a receiving area identifier can itself have a REDEFINES |
| clause or be subordinate to a data item with a REDEFINES |
| clause. |
| |
|5. When the statement is written without the REPLACING phrase, |
| data items of the categories alphabetic, alphanumeric, and |
| alphanumeric edited are set to spaces; data items of the |
| categories numeric, external floating-point (VSC2) (MF) and |
| numeric edited are set to zeros. In this case, the operation is |
| as if each affected data item is the receiving area in an |
| elementary MOVE statement with the indicated source literal (that|
| is, spaces or zeros). |
| |
|6. In all cases, the content of the data item referenced by |
| identifier-1 is set to the indicated value in the order |
| (left to right) of the appearance of identifier-1 in the |
| INITIALIZE statement. Within this sequence, where identifier-1 |
| references a group item, affected elementary items are |
| initialized in the sequence of their definition within the |
| group. |
| |
|7. If identifier-1 occupies the same storage area as identifier-2, |
| the result of the execution of this statement is undefined, even |
| if they are defined by the same data description entry. (See |
| the section "Overlapping Operands" earlier in this |
| chapter.) |
| |
|8. NATIONAL and NATIONAL-EDITED fields can be initialized with |
| national character values. |
| |
________________________________________________________________________
The INSPECT Statement
Function
The INSPECT statement provides the ability to tally (Format 1), replace
(Format 2), tally and replace (Format 3) or convert (Format 4) (ANS85)
occurrences of single characters or group of characters in a data item.
General Formats
Format 1
Format 2
Format 3
Syntax Rules
All Formats
1. Identifier-1 must reference either a group item or any category of
elementary item, described (either implicitly or explicitly) as
USAGE IS DISPLAY.
2. Identifier-3 ... identifier-n must reference either an elementary
alphabetic, alphanumeric or numeric item described (either
implicitly or explicitly) as USAGE IS DISPLAY.
3. Each literal must be nonnumeric and can be any figurative
constant, except ALL. If literal-1, literal-2 or literal-4 is a
figurative constant, it refers to an implicit one character data
item.
4. No more than one BEFORE phrase and/ (ANS85) or one AFTER phrase
can be specified for any one ALL, LEADING, CHARACTERS, FIRST or
CONVERTING (ANS85) phrase.
5. Literal-1, literal-2, literal-3, literal-4, and literal-5, and the
data items referenced by identifier-3, identifier-4, identifier-5,
identifier-6, and identifier-7 can be any number of characters in
length up to the limit allowed for literals or data items.
________________________________________________________________________
|(ANS85) |
| |
| |
| |
|6. All identifiers, except identifier-2 (the TALLYING field), can be|
| external floating-point items. External floating-point items are|
| treated as if redefined as alphanumeric with the INSPECT |
| statement referring to the alphanumeric item. |
| |
________________________________________________________________________
Formats 1 and 3
7. Identifier-2 must reference an elementary numeric data item.
Formats 2 and 3
8. The size of the data referenced by literal-3 or identifier-5 must be
equal to the size of the data referenced by literal-1 or
identifier-3. When a figurative constant is used as literal-3, the
size of the figurative constant is equal to the size of literal-1 or
the size of the data item referenced by identifier-3.
9. When the CHARACTERS phrase is used, literal-3 or the size of the
data item referenced by identifier-5 must be one character in
length.
________________________________________________________________________
|(ANS85) This restriction does not apply to literal-2 or identifier-4. |
________________________________________________________________________
________________________________________________________________________
|(ANS85) |
| |
|Format 4 Only |
| |
| |
| |
|10. The size of literal-5 or the data item referenced by identifier-7|
| must be equal to the size of literal-4 or the data item |
| referenced by identifier-6. When a figurative constant is used |
| as literal-5, the size of the figurative constant is equal to the|
| size of literal-4 or the size of the data item referenced by |
| identifier-6. |
| |
|11. The same character must not appear more than once either in |
| literal-4 or in the data item referenced by identifier-6. |
| |
________________________________________________________________________
General Rules
All Formats
________________________________________________________________________
|(ANS85) |
| |
| |
| |
|1. For the purpose of determining its length, identifier-1 is |
| treated as if it were a sending data item. (See the section "The|
| OCCURS Clause" in this chapter.) |
| |
________________________________________________________________________
2. Inspection (which includes the comparison cycle, the establishment
of boundaries for the BEFORE or AFTER phrase, and the mechanism for
tallying and/or replacing) begins at the leftmost character position
of the data item referenced by identifier-1, regardless of its
class, and proceeds from left to right to the rightmost character
position as described in General Rules 6, 7 and 8.
3. For use in the INSPECT statement, the contents of the data item
referenced by identifier-1, identifier-3, identifier-4,
identifier-5, identifier-6 or identifier-7 will be treated as
follows:
a. If any of identifier-1, identifier-3, identifier-4,
identifier-5, identifier-6 or identifier-7 is described as
alphanumeric, the INSPECT statement treats the contents of
each such identifier as a character-string.
b. If any of identifier-1, identifier-3, identifier-4,
identifier-5, identifier-6 or identifier-7 is described as
alphanumeric edited, numeric edited or unsigned numeric, the
data item is inspected as though it had been redefined as
alphanumeric (see General Rule 3a.) and the INSPECT
statement had been written to reference the redefined data
item.
c. If any of identifier-1, identifier-3, identifier-4,
identifier-5, identifier-6 or identifier-7 is described as
signed numeric, the data item is inspected as though it had
been moved to an unsigned numeric data item with length equal
to the length of the signed item excluding any separate sign
position and then the rules in General Rule 3b. had been
applied. (See the section "The MOVE Statement" later in
this chapter.)
4. In General Rules 6 through 19, all references to literal-1,
literal-2, literal-3, literal-4, and literal-5 apply equally to the
contents of the data item referenced by identifier-3, identifier-4,
identifier-5, identifier-6, and identifier-7, respectively.
5. If any identifier is subscripted or is a function-identifier,
(ANS85) the subscript or function-identifier (ANS85) is evaluated
only once as the first operation in the execution of the INSPECT
statement.
Format 1
________________________________________________________________________
| |
| 6. Identifier-1 is a sending data item. (ANS85) |
| |
________________________________________________________________________
7. The required words ALL and LEADING are adjectives that apply to each
succeeding literal-1 until the next adjective appears.
8. The contents of the data item referenced by identifier-2 are not
initialized by the execution of the INSPECT statement.
9. The rules for tallying are as follows:
a. If the ALL phrase is specified, the contents of the data item
referenced by identifier-2 are incremented by one for each
occurrence of literal-1 matched within the contents of the
data item referenced by identifier-1.
b. If the LEADING phrase is specified, the contents of the data
item referenced by identifier-2 are incremented by one for
the first and each subsequent contiguous occurrence of
literal-1 matched within the contents of the data item
referenced by identifier-1, provided that the leftmost such
occurrence is at the point where comparison began in the
first comparison cycle in which literal-1 was eligible to
participate.
c. If the CHARACTERS phrase is specified, the contents of the
data item referenced by identifier-2 are incremented by one
for each character matched, in the sense of Format 1 and 2,
General Rule 7e, within the contents of the data item
referenced by identifier-1.
10. If identifier-1, identifier-3 or identifier-4 occupies the same
storage area as identifier-2, the result of the execution of this
statement is undefined, even if they are defined by the same data
description entry. (See the section "Overlapping Operands"
earlier in this chapter.)
Formats 1 and 2
11. During inspection of the contents of the data item referenced by
identifier-1, each properly matched occurrence of literal-1 is
tallied (Format 1) or replaced by literal-3 (Format 2).
12. The comparison operation to determine the occurrences of literal-1
to be tallied or to be replaced, occurs as follows:
a. The operands of the TALLYING or REPLACING phrases are
considered in the order they are specified in the INSPECT
statement from left to right. The first literal-1 is
compared to an equal number of contiguous characters,
starting with the leftmost character position in the data
item referenced by identifier-1. Literal-1 matches that
portion of the contents of the data item referenced by
identifier-1 if, and only if, they are equal, character for
character, and:
1. If neither LEADING nor FIRST is specified, or:
2. If the LEADING adjective applies to literal-1 and
literal-1 is a leading occurrence as defined in
General Rules 12 and 15, or:
3. If the FIRST adjective applies to literal-1 and
literal-1 is the first occurrence as defined in
General Rule 12.
b. If no match occurs in the comparison of the first literal-1,
the comparison is repeated with each successive literal-1, if
any, until either a match is found or there is no next
successive literal-1. When there is no next successive
literal-1, the character position in the data item referenced
by identifier-1 immediately to the right of the leftmost
character position considered in the last comparison cycle is
considered as the leftmost character position, and the
comparison cycle begins again with the first literal-1.
c. Whenever a match occurs, tallying and/or replacing takes
place as described in General Rules 12 and 15. The character
position in the data item referenced by identifier-1
immediately to the right of the rightmost character position
that participated in the match is now considered to be the
leftmost character position of the data item referenced by
identifier-1, and the comparison cycle starts again with the
first literal-1.
d. The comparison operation continues until the rightmost
character position of the data item referenced by
identifier-1 has participated in a match or has been
considered as the leftmost character position. When this
occurs, inspection is terminated.
e. If the CHARACTERS phrase is specified, an implied one
character operand participates in the cycle described in
paragraphs 7a. through 7d. above, except that no comparison
to the contents of the data item referenced by identifier-1
takes place. This implied character is considered always to
match the leftmost character of the contents of the data item
referenced by identifier-1 participating in the current
comparison cycle.
13. The comparison operation defined in General Rule 7 is affected by
the BEFORE and AFTER phrases as follows:
a. If neither the BEFORE nor the AFTER phrase is specified,
literal-1 or the implied operand of the CHARACTERS phrase is
first eligible to participate in matching at the leftmost
character position of identifier-1.
b. If the BEFORE phrase is specified, the associated literal-1,
or the implied operand of the CHARACTERS phrase participates
only in those comparison cycles which involve that portion of
the contents of the data item referenced by identifier-1 from
its leftmost character position up to, but not including, the
first occurrence of literal-2, within the contents of the
data item referenced by identifier-1.
The position of this first occurrence is determined before
the first cycle of the comparison operation described in
General Rule 7 is begun. If, on any comparison cycle,
literal-1, or the implied operand of the CHARACTERS phrase is
not eligible to participate, it is considered not to match
the contents of the data item referenced by identifier-1. If
there is no occurrence of literal-2, within the contents of
the data item referenced by identifier-1, its associated
literal-1, or the implied operand of the CHARACTERS phrase
participates in the comparison operation as though the BEFORE
phrase had not been specified.
c. If the AFTER phrase is specified, the associated literal-1,
or the implied operand of the CHARACTERS phrase can
participate only in those comparison cycles which involve
that portion of the contents of the data item referenced by
identifier-1 from the character position immediately to the
right of the rightmost character position of the first
occurrence of literal-2, within the contents of the data item
referenced by identifier-1 to the rightmost character
position of the data item referenced by identifier-1.
The position of this first occurrence is determined before
the first cycle of the comparison operation described in
General Rule 7 is begun. If, on any comparison cycle,
literal-1, or the implied operand of the CHARACTERS phrase is
not eligible to participate, it is considered not to match
the contents of the data item referenced by identifier-1. If
there is no occurrence of literal-2, within the contents of
the data item referenced by identifier-1, its associated
literal-1, or the implied operand of the CHARACTERS phrase is
never eligible to participate in the comparison operation.
Format 2
14. The required words ALL, LEADING and FIRST are adjectives that apply
to each succeeding BY phrase until the next adjective appears.
15. The rules for replacement are as follows:
a. When the CHARACTERS phrase is specified, each character
matched in the sense of Format 1 and 2, General Rule 7e. in
the contents of the data item referenced by identifier-1, is
replaced by literal-3.
b. When the adjective ALL is specified, each occurrence of
literal-1 matched in the contents of the data item referenced
by identifier-1 is replaced by literal-3.
c. When the adjective LEADING is specified, the first and each
subsequent contiguous occurrence of literal-1 matched in the
contents of the data item referenced by identifier-1 is
replaced by literal-3, provided that the leftmost occurrence
is at the point where comparison began in the first
comparison cycle in which literal-1 was eligible to
participate.
d. When the adjective FIRST is specified, the leftmost
occurrence of literal-1 matched within the contents of the
data item referenced by identifier-1 is replaced by
literal-3.
16. If identifier-3, identifier-4 or identifier-5 occupies the same
storage area as identifier-1, the result of the execution of this
statement is undefined, even if they are defined by the same data
description entry. (See the section "Overlapping Operands"
earlier in this chapter.)
Format 3
17. A Format 3 INSPECT statement is interpreted and executed as though
two successive INSPECT statements specifying the same identifier-1
had been written with one statement being a Format 1 statement with
TALLYING phrases identical to those specified in the Format 3
statement, and the other statement being a Format 2 statement with
REPLACING phrases identical to those specified in the Format 3
statement. The General Rules given for matching and counting apply
to the Format 1 statement and the General Rules given for matching
and replacing apply to the Format 2 statement.
________________________________________________________________________
|(ANS85) |
| |
|Format 4 |
| |
| |
| |
|18. A Format 4 INSPECT statement is interpreted and executed as |
| though a Format 2 INSPECT statement specifying the same |
| identifier-1 had been written with a series of ALL phrases, one |
| for each character of literal-4. The effect is as if each of |
| these ALL phrases referenced, as literal-1, a single character of|
| literal-4 and referenced, as literal-3, the corresponding single |
| character of literal-5. Correspondence between the characters of|
| literal-4 and the characters of literal-5 is by ordinal position |
| within the data item. |
| |
|19. If identifier-4, identifier-6 or identifier-7 occupies the same |
| storage area as identifier-1, the result of the execution of this|
| statement is undefined, even if they are defined by the same data|
| description entry. |
| |
________________________________________________________________________
Examples
Seven examples of the use of the INSPECT statement follow. In each case,
it is assumed that the TALLYING fields have value zero before the
statement is executed.
1. INSPECT word TALLYING count FOR LEADING "L" BEFORE INITIAL "A",
count-1 FOR LEADING "A" BEFORE INITIAL "L".
Where word = LARGE, count = 1, count-1 = 0.
Where word = ANALYST, count = 0, count-1 = 1.
2. INSPECT word TALLYING count FOR ALL "L", REPLACING LEADING "A" BY
"E" AFTER INITIAL "L".
Where word = CALLAR, count = 2, word = CALLAR.
Where word = SALAMI, count = 1, word = SALEMI.
Where word = LATTER, count = 1, word = LETTER.
3. INSPECT word REPLACING ALL "A" BY "G" BEFORE INITIAL "X".
Where word = ARXAX, word = GRXAX.
Where word = HANDAX, word = HGNDGX.
4. INSPECT word TALLYING count FOR CHARACTERS AFTER INITIAL "J"
REPLACING ALL "A" BY "B".
Where word = ADJECTIVE, count = 6, word = BDJECTIVE.
Where word = JACK, count = 3, word = JBCK.
Where word = JUJMAB, count = 5, word = JUJMBB.
5. INSPECT word REPLACING ALL "X" BY "Y", "B" BY "Z", "W" BY "Q"
AFTER INITIAL "R".
Where word = RXXBQWY, word = RYYZQQY.
Where word = YZACDWBR, word = YZACDWZR.
Where word = RAWRXEB, word = RAQRYEZ.
6. INSPECT word REPLACING CHARACTERS BY "B" BEFORE INITIAL "A " .
word before: 12XZABCD
word after: BBBBABCD
7. INSPECT item CONVERTING "ABCD" TO "XYZX" AFTER QUOTE BEFORE "#"
The above INSPECT is equivalent to the following INSPECT:
INSPECT item REPLACING
ALL "A" BY "X" AFTER QUOTE BEFORE "#"
ALL "B" BY "Y" AFTER QUOTE BEFORE "#"
ALL "C" BY "Z" AFTER QUOTE BEFORE "#"
ALL "D" BY "X" AFTER QUOTE BEFORE "#"
word before: AC"AEBDFBCD#AB"
word after: AC"XEYXFYZX#AB"
MPE/iX 5.0 Documentation