HP 3000 Manuals

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.) 

Class Condition.   

Function 

The class condition determines whether the operand is numeric, or
alphabetic
________________________________________________________________________
|(ANS85)                                                               |
|or alphabetic-lower, or alphabetic-upper, or contains only the        |
|characters in the set of characters specified by the CLASS clause     |
|as defined in the SPECIAL-NAMES paragraph of the Environment          |
|Division.                                                             |
________________________________________________________________________

            

General Format 

[]
Syntax Rules 1. The class of an operand is determined as follows: a. An operand is numeric if it consists entirely of the characters 0, 1, 2, 3, ... , 9, with or without an operational sign. b. An operand is alphabetic if it consists entirely of the uppercase letters A, B, C, ... , Z, space, or the lowercase letters a, b, c, ... , z, space, (ANS85) or any combination of the uppercase and lowercase (ANS85) letters and spaces. ________________________________________________________________________ |(ANS85) | | | | | | | |c. An operand is alphabetic-lower if it consists entirely of the | | lowercase letters a, b, c, ... , z, and space. | | | |d. An operand is alphabetic-upper if it consists entirely of the | | uppercase letters A, B, C, ... , Z, and space. | | | |e. An operand is in conformance to class-name-1, if it consists | | entirely of the characters listed in the definition of | | class-name-1 in the SPECIAL-NAMES paragraph. | | | ________________________________________________________________________ 2. Identifier-1 must reference a data item whose usage is explicitly or implicitly DISPLAY, or in the case of the NUMERIC test, as DISPLAY, COMPUTATIONAL, COMPUTATIONAL-X, (MF) COMPUTATIONAL-3 (OSVS) (VSC2) (MF) (XOPEN) COMPUTATIONAL-5 (MF) or PACKED-DECIMAL. (VSC2) (MF) ________________________________________________________________________ |(ANS85) | | | | | | | |3. If identifier-1 is a function-identifier, it must reference an | | alphanumeric function. | | | ________________________________________________________________________ General Rules 1. If identifier-1 is a zero-length item, then the result of the class test is always false. It is also always false when "NOT" is used with a class test as a zero-length item. 2. When used, "NOT" and the next key word specify one class condition that defines the class test to be executed for truth value; for example, "NOT NUMERIC" is a truth test for determining that an operand is nonnumeric. 3. When the class-condition includes the word NOT, and identifier-1 is a zero-length group-item, the result of the class test is always true. 4. The NUMERIC test cannot be used with an item whose data description describes the item as alphabetic or as a group item composed of elementary items whose data description indicates the presence of operational sign(s). If the data description of the item being tested does not indicate the presence of an operational sign, the item being tested is determined to be numeric only if the contents are numeric and an operational sign is not present. If the data description of an elementary item being tested does indicate the presence of an operational sign, the item being tested is determined to be numeric only if the contents are numeric and a valid operational sign is present. Valid operational signs for data items described with the SIGN IS SEPARATE clause are the standard data format characters, "+" and "-"; valid operational signs for data items not described with the SIGN IS SEPARATE clause are described in the section "Selection of Character Representation and Radix" in the chapter COBOL Concepts. 5. The ALPHABETIC test cannot be used with an item whose data description describes the item as numeric. The item being tested is determined to be alphabetic only if the contents consist of any combination of the uppercase alphabetic characters "A" through "Z" and the space and any combination of the lowercase alphabetic characters "a" through "z" (ANS85) and the space. ________________________________________________________________________ |(OSVS) (VSC2) (MF) | |The class condition cannot be used for external floating- point (USAGE| |DISPLAY) or internal floating-point (USAGE COMP-1 and USAGE COMP-2) | |items. | ________________________________________________________________________ ________________________________________________________________________ |(ANS85) | | | | | | | |6. The ALPHABETIC-LOWER test cannot be used with an item whose data | | description describes the item as numeric. The result of the test| | is true if the content of the data item referenced by identifier-1| | consists entirely of the lowercase alphabetic characters "a" | | through "z" and space. | | | |7. The ALPHABETIC-UPPER test cannot be used with an item whose data | | description describes the item as numeric. The result of the test| | is true if the content of the data item referenced by identifier-1| | consists entirely of the uppercase alphabetic characters "A" | | through "Z" and space. | | | |8. The class-name-1 test must not be used with an item whose data | | description describes the item as numeric. | | | ________________________________________________________________________ Condition-Name Condition (Conditional Variable). Function In a condition-name condition, a conditional variable is tested to determine whether or not its value is equal to one of the values associated with a condition-name. General Format condition-name Syntax Rules ________________________________________________________________________ |(OSVS) (VSC2) (MF) | | | | | | | |1. Condition-names with DBCS and internal floating-point items are | | allowed. | | | ________________________________________________________________________ ________________________________________________________________________ |(MF) | | | | | | | |2. Condition-names with external floating-point items are allowed. | | | ________________________________________________________________________ General Rules 1. If the condition-name is associated with a range or ranges of values, then the conditional variable is tested to determine whether or not its value falls in this range, including the end values. 2. The rules for comparing a conditional variable with a condition-name value are the same as those specified for relation conditions. 3. The result of the test is true if one of the values corresponding to the condition-name equals the value of its associated conditional variable. Switch-Status Condition. A switch-status condition determines the "on" or "off" status of one of the nine (MF) COBOL switches named respectively SWITCH 0 through SWITCH 8. (MF) The value of each of these switches ("on" or "off" ) is set by the operator at the commencement of execution of the COBOL object program. (See the discussion of run-time switches in your COBOL System Reference for details.) The switch and the "on" or "off" value associated with the condition must be named in the SPECIAL-NAMES paragraph of the Environment Division in this chapter. General Format condition-name The result of the test is true if the switch is set to the specified position corresponding to the condition-name. It is not possible to use the Switch-Status Condition to test if a switch is set from within the program that sets the COBOL switches themselves. Sign Condition. The sign condition determines whether or not the algebraic value of an arithmetic expression is less than, greater than, or equal to zero. The general format for a sign condition is as follows:
[]
When used, "NOT" and the next keyword specify one sign condition that defines that algebraic test to be executed for truth value; for example, "NOT ZERO" is a truth test for a nonzero (positive or negative) value. An operand is positive if its value is greater than zero, negative if its value is less than zero, and zero if its value is equal to zero. The arithmetic expression must contain at least one reference to a variable. ________________________________________________________________________ |(OSVS) | |ZEROS or ZEROES can be used instead of ZERO in a sign test. | ________________________________________________________________________ Complex Conditions. A complex condition is formed by combining simple conditions, combined conditions and/or complex conditions with logical connectors (logical operators "AND" and "OR") or negating these conditions with logical negation (the logical operator "NOT"). The truth value of a complex condition, whether parenthesized or not, is that truth value which results from the interaction of all the stated logical operators on the individual truth values of simple conditions, or the intermediate truth values of conditions logically connected or logically negated. The logical operators and their meanings are: Operator Meaning AND Logical conjunction; the truth value is "true" if both of the conjoined conditions are true; "false" if one or both of the conjoined conditions is false. OR Logical inclusive OR; the truth value is "true" if one or both of the included conditions is true; "false" if both included conditions are false. NOT Logical negation or reversal of truth value; the truth value is "true" if the condition is false; "false" if the condition is true. The logical operators must be preceded by a space and followed by a space. Negated Simple Condition. A simple condition is negated through the use of the logical operator "NOT". The negated simple condition effects the opposite truth value for a simple condition. Thus the truth value of a negated simple condition is "true" if and only if the truth value of the simple condition is "false" ; the truth value of a negated simple condition is "false" if and only if the truth value of the simple condition is "true". The inclusion in parentheses of a negated simple condition does not change the truth value. General Format NOT simple-condition Combined and Negated Combined Condition. A combined condition results from connecting conditions with one of the logical operators "AND" or "OR". General Format
[]
Syntax Rules 1. Condition may be: * A simple condition * A negated simple condition * A combined condition * A negated combined condition; that is, the "NOT" logical operator followed by a combined condition enclosed within parentheses * Combinations of the above, specified according to the rules summarized in Table 3-9 . 2. Although parentheses need never be used when either "AND" or "OR" (but not both) is used exclusively in a combined condition, parentheses can be used to effect a final truth value when a mixture of "AND", "OR" and "NOT" is used. General Rules 1. In the absence of the relevant parenthesis in a complex condition, the precedence (that is, binding power) of the logical operators determines the conditions to which the specified logical operators apply and implies the equivalent parenthesis. The order of precedence is "NOT", "AND" , "OR". Thus, specifying "condition-1 OR NOT condition-2 AND condition-3" implies and is equivalent to specifying "condition-1 OR ((NOT condition-2) AND condition-3)". 2. Where parentheses are used in a complex condition, precedence is used to determine the binding of conditions to logical operator. Parentheses can, therefore, be used to depart from the normal precedence of logical operators as specified above. Thus, the example complex condition above can be given a different meaning by specifying it as a "(condition-1 OR (NOT condition-2)) AND condition-3". (See the section "Condition Evaluation Rules" later in this chapter.) Table 3-9 indicates the ways in which conditions and logical operators can be combined and parenthesized. There must be a one-to-one correspondence between left and right parentheses such that each left parenthesis is to the left of its corresponding right parenthesis. Table 3-9. Combinations of Conditions, Logical Operators, and Parentheses --------------------------------------------------------------------------------- | | | | | | Element | Permitted | Element can be | Element can be | | | location in | preceded by only: | followed by only: | | | conditional | | | | | expression | | | | | | | | --------------------------------------------------------------------------------- | | | | | | simple-condition | Any | OR, NOT, AND, ( | OR, AND,) | | | | | | --------------------------------------------------------------------------------- | | | | | | OR or AND | Not first or last | simple- | simple-condition, | | | | condition,) | NOT, ( | | | | | | --------------------------------------------------------------------------------- | | | | | | NOT | Not last | OR, AND, ( | simple-condition, | | | | | ( | | | | | | --------------------------------------------------------------------------------- | | | | | | ( | Not last | OR, NOT, AND, ( | simple-condition, | | | | | NOT, ( | | | | | | --------------------------------------------------------------------------------- | | | | | | ) | Not first | simple- | OR, AND,) | | | | condition,) | | | | | | | --------------------------------------------------------------------------------- Thus, the element pair "OR NOT" is permissible while the pair "NOT OR" is not permissible; "NOT (" is permissible while "NOT NOT" is not permissible. Abbreviated Combined Relation Conditions. When simple or negated simple relation conditions are combined with logical connectives in a consecutive sequence such that a succeeding relation condition contains a subject or subject and relational operator that is common with the preceding relation condition, and no parentheses are used within such a consecutive sequence, any relation condition except the first can be abbreviated by: * The omission of the subject of the relation condition, or: * The omission of the subject and relational operator of the relation condition. General Format
[]
Within a sequence of relation conditions both of the above forms of abbreviation can be used. The effect of using such abbreviations is as if the last preceding stated subject were inserted in place of the omitted subject, and the last stated relational operator were inserted in place of the omitted relational operator. The result of such implied insertion must comply with the rules of Table 3-9 . This insertion of an omitted subject and/or relational operator terminates once a complete simple condition is encountered within a complex condition. ________________________________________________________________________ |(OSVS) | |The order of evaluation of the conditions can be prioritized by the | |use of parentheses (see example below). | ________________________________________________________________________ The interpretation applied to the use of the word "NOT" in an abbreviated combined relation condition is as follows: ________________________________________________________________________ |(ANS85) | | | | | | | |1. If NOT is immediately followed by the word GREATER, >, LESS, <, | | EQUAL, or =, excluding the relational operators GREATER THAN | | OR EQUAL TO, >=, LESS THAN OR EQUAL TO, and <=, then the | | word NOT is interpreted as part of the relational operator, | | otherwise: | | | ________________________________________________________________________ 2. The "NOT" is interpreted as a logical operator and, therefore, the implied insertion of subject or relational operator results in a negated relation condition. Some examples of abbreviated combined and negated combined relation conditions and expanded equivalents follow. Abbreviated Combined Expanded Equivalent Relation Condition a > b AND NOT < c OR d ((a > b) AND (a NOT < c)) OR (a NOT < d) a NOT EQUAL b OR c (a NOT EQUAL b) OR (a NOT EQUAL c) NOT a = b OR c (NOT (a = b)) OR (a = c) NOT (a GREATER b OR < c) NOT ((a GREATER b) OR (a < c)) NOT (a NOT > b AND c AND NOT ((((a NOT > b) AND (a NOT > c)) AND (NOT NOT d (a NOT > d)))) x > a OR y AND z x > a OR (x > y AND x > z) ________________________________________________________________________ |(OSVS) | | | | | | | |x > a OR (y AND z) x > a OR (x > y AND x > z) | | | |x > (a OR y) AND z (x > a OR x > y) AND x > z | | | |x ( = a OR > b) x = a OR x > b | | | |x = a AND ( > b OR < z ) x = a AND ( x > b OR x < z ) | | | ________________________________________________________________________ a EQUAL b OR NOT GREATER OR (a EQUAL b) OR (NOT (a GREATER OR EQUAL c)) EQUAL c OR d OR (a GREATER OR EQUAL d) a EQUAL b OR NOT >=c OR d (a EQUAL b) OR (NOT (a >= c)) OR (a >= d) Condition Evaluation Rules. Parentheses can be used to specify the order in which individual conditions of complex conditions are to be evaluated when it is necessary to depart from the implied evaluation precedence. Conditions within parentheses are evaluated first, and, within nested parentheses, evaluation proceeds from the least inclusive condition to the most inclusive condition. When parentheses are not used, or parenthesized conditions are at the same level of inclusiveness, the following hierarchical order of logical evaluation is implied until the final truth value is determined: ________________________________________________________________________ |(ANS85) | | | | | | | |1. Values are established for arithmetic expressions and functions if| | and when the conditions containing them are evaluated. Similarly,| | negated conditions are evaluated if and when it is necessary to | | evaluate the complex condition that they represent. (See | | "Formation and Evaluation Rules" in the section Arithmetic | | Expressions in this chapter.) | | | ________________________________________________________________________ 2. Truth values for simple conditions are established in the following order: relation (following the expansion of any abbreviated relation condition) class condition-name switch-status sign 3. Truth values for negated conditions are established. 4. Truth values for combined conditions are established: "AND" logical operators, followed by "OR" logical operators. 5. Truth values for negated combined conditions are established. 6. When the sequence of evaluation is not completely specified by parentheses, the order of evaluation of consecutive operations of the same hierarchical level is from left to right. Common Phrases and General Rules for Statement Formats In the statement descriptions that follow, several phrases appear frequently: the ROUNDED phrase, the ON SIZE ERROR phrase the NOT ON SIZE ERROR phrase (ANS85) and the CORRESPONDING phrase. Each of these phrases is discussed below. In the following paragraphs, the term "resultant- identifier" refers to that identifier associated with the result of an arithmetic operation. The ROUNDED Phrase. If, after decimal point alignment, the number of places in the fraction of the result of an arithmetic operation is greater than the number of places provided for the fraction of the resultant-identifier, truncation is relative to the size provided for the resultant- identifier. When rounding is requested, the absolute value of the resultant-identifier is increased by one whenever the most significant digit of the excess is greater than or equal to five. When the low-order integer positions in a resultant- identifier are represented by the character "P" in the PICTURE for the resultant- identifier, rounding or truncation occurs relative to the rightmost integer position for which storage is allocated. ________________________________________________________________________ |(OSVS) (VSC2) (MF) | |In a floating-point arithmetic operation, the ROUNDED phrase is | |treated as documentary; the result of a floating-point operation is | |always rounded. | ________________________________________________________________________ The ON SIZE ERROR Phraseand NOT ON SIZE ERROR Phrase (ANS85). If, after decimal point alignment, the absolute value of a result of an arithmetic operation exceeds the largest value that can be contained in the associated resultant-identifier, a size error condition exists. Division by zero always causes a size error condition.[REV BEG] Note that the results of division by zero when no ON SIZE ERROR phrase is specified, are unpredictable. [REV END] The size error condition applies only to the final results, except in MULTIPLY and DIVIDE statements, in which case the size error condition applies to the intermediate results as well. ________________________________________________________________________ |(ANS85) | |Violation of the rules for the evaluation of exponentiation always | |terminates the arithmetic operation and always causes a size error | |condition. | ________________________________________________________________________ If the ROUNDED phrase is specified, rounding takes place before checking for size error. When such a size error condition occurs, the subsequent action depends on whether or not the SIZE ERROR phrase is specified, as follows: ON SIZE ERROR Phrase Not Specified When a size error condition occurs, the value of those resultant- identifier(s) affected is undefined. Values of resultant-identifier(s) for which no size error condition occurs are unaffected by size errors that occur for other resultant-identifier(s) during execution of this operation. ________________________________________________________________________ |(ANS85) | |After completion of the arithmetic operation, control is transferred | |to the end of the arithmetic statement and the NOT ON SIZE phrase, if | |specified, is ignored. | ________________________________________________________________________ Results of division by zero, when no ON SIZE ERROR is specified, are unpredictable. You can avoid this by using the CHECKDIV compiler directive. See your COBOL System Reference for details. ON SIZE ERROR Phrase Specified When a size error condition occurs, then the values of resultant- identifier(s) affected by the size errors are not altered. Values of resultant-identifier(s) for which no size error condition occurs are unaffected by size errors that occur for other resultant-identifier(s) during execution of this operation. After completion of the execution of this operation, the imperative statement in the SIZE ERROR phrase is executed. For the ADD statement with the CORRESPONDING phrase and the SUBTRACT statement with the CORRESPONDING phrase, if any of the individual operations produces a size error condition, the imperative statement in the ON SIZE ERROR phrase is not executed until all of the individual additions or subtractions are completed. ________________________________________________________________________ |(ANS85) | |The NOT ON SIZE ERROR phrase, if specified, is ignored. | ________________________________________________________________________ ________________________________________________________________________ |The NOT ON SIZE ERROR Phrase | | | |(ANS85) | | | |If the NOT ON SIZE ERROR phrase is specified for an arithmetic | |operation statement, and after execution of that statement a size | |error condition (as defined above) does not exist, then the NOT ON | |SIZE ERROR phrase, if specified is executed. The ON SIZE ERROR | |phrase, if specified, is ignored, and the imperative statement | |associated with it is not executed. | | | |If an ON SIZE ERROR condition occurs, any NOT ON SIZE ERROR | |phrase is ignored whether or not an ON SIZE ERROR phrase is | |specified. | | | |When both ON SIZE ERROR and NOT ON SIZE ERROR phrases are specified, | |and the statement in the phrase that is executed does not contain any | |explicit transfer of control, then, if necessary, an implicit transfer| |of control is made after execution of the phrase to the end of the | |arithmetic statement. | ________________________________________________________________________ The CORRESPONDING Phrase. In the text that follows d1 and d2 must each be identifiers that refer to group items. A pair of data items, one from d1 and one from d2 correspond if the following conditions exist: 1. A data item in d1 and a data item in d2 are not designated by the key word FILLER and have the same data-name and the same qualifiers up to, but not including, d1 and d2. 2. At least one of the data items is an elementary data item and the resulting move is legal according to the move rules in the case of a MOVE statement with the CORRESPONDING phrase, and both of the data items are elementary numeric data items in the case of the ADD statement with the CORRESPONDING phrase or the SUBTRACT statement with the CORRESPONDING phrase. 3. The description of d1 and d2 must not contain level-number 66, 77, 78 (MF) or 88 or the USAGE IS INDEX clause. 4. A data item that is subordinate to d1 or d2 and contains a REDEFINES, RENAMES, OCCURS, USAGE IS INDEX or USAGE IS PROCEDURE-POINTER or USAGE IS POINTER (MF) (VSC2) clause is ignored, as well as those data items subordinate to the data item that contains the REDEFINES, RENAMES, OCCURS, USAGE IS INDEX or USAGE IS POINTER (MF) (VSC2) clause. However, d1 and d2 can have REDEFINES or OCCURS clauses or be subordinate to data items with REDEFINES or OCCURS clauses. ________________________________________________________________________ |Neither d1 or d2 can be reference modified. (ANS85) | ________________________________________________________________________ 5. The name of each data item which satisfies the above conditions must be unique after application of the implied qualifiers. Arithmetic Statements. The arithmetic statements are the ADD, COMPUTE, DIVIDE, MULTIPLY and SUBTRACT statements. Common features are as follows: 1. The data descriptions of the operands need not be the same; any necessary conversion and decimal point alignment are supplied throughout the calculation. 2. The maximum size of each operand is 18 decimal digits. The composite of operands, which is a hypothetical data item resulting from the superimposition of specified operands in a statement aligned on their decimal points (see the sections "The ADD Statement" , "The DIVIDE Statement" , "The MULTIPLY Statement" and "The SUBTRACT Statement" later in this chapter) must not contain more than 18 decimal digits. Overlapping Operands. When a sending and a receiving item in any statement share a part of their storage areas, the result of the execution of such a statement is undefined. Multiple Results in Arithmetic Statements. The ADD, COMPUTE, DIVIDE, MULTIPLY and SUBTRACT statements can have multiple results. Such statements behave as though they had been written in the following way: 1. A statement which accesses all data items that are part of the initial evaluation of the statement, performs all arithmetic necessary to arrive at the result to be stored in the receiving items, and stores that result in a temporary storage location. 2. A sequence of statements transferring or combining the value of this temporary location with each single resultant data item. These statements are considered to be written in the same left-to-right sequence in which the multiple results are listed. The result of the statement: ADD a, b, c TO c, d (c), e is equivalent to: ADD a, b, c GIVING temp ADD temp TO c ADD temp TO d (c) ADD temp TO e and the result of the statement: MULTIPLY a(i) BY i, a(i) is equivalent to: MOVE a(i) to temp MULTIPLY temp by i MULTIPLY temp BY a(i) where temp is an intermediate result item provided by your COBOL system. Incompatible Data. Except for the class condition (see the section Class Condition in this chapter), when the contents of a data item are referenced in the Procedure Division and the contents of that data item are not compatible with the class specified for that data item by its PICTURE clause or function definition (ANS85) then the result of such a reference is undefined. ________________________________________________________________________ |[REV BEG](MF) | |The results of referencing a numeric field that contains nonnumeric, | |or otherwise invalid data, are undefined. Such conditions may be | |detected, and give an error at run-time. See your COBOL System | |Reference for details of the +F run-time switch. | | | |When an alphabetic field which contains non-alphabetic data is | |referenced, your program will continue execution, but results may be | |undefined.[REV END] | ________________________________________________________________________ Signed Receiving Items. When the receiving item in an arithmetic statement or a MOVE statement is a signed numeric or a signed numeric edited item, the sign is moved into the receiving item independently of any truncation of the absolute numeric data. It is possible, therefore, for the numeric value to be zero but for the sign to be negative.


MPE/iX 5.0 Documentation