HP 3000 Manuals

Simple Conditions [ HP COBOL II/XL Reference Manual ] MPE/iX 5.0 Documentation


HP COBOL II/XL Reference Manual

Simple Conditions 

The six simple conditions are:

   *   Sign condition.

   *   Class condition.

   *   Switch-status condition.

   *   Relation condition.

   *   Condition name condition.

   *   Intrinsic relation conditions.  Intrinsic relation conditions are
       an HP extension to the ANSI COBOL standard.

Sign Condition 

The sign condition tests whether or not the algebraic value of an
arithmetic expression is less than, greater than, or equal to zero.  The
sign condition has the following format:

[]
Parameters arithmetic-expression any valid arithmetic expression, as described on the preceding pages. It must contain at least one reference to a variable. NOT coupled with one of the next keywords, algebraically tests arithmetic-expression. If NOT POSITIVE is specified, return a value of "true" if arithmetic-expression is negative or equal to zero; return a value of "false" otherwise. If NOT NEGATIVE is specified, return a value of "true" if arithmetic-expression is equal to zero or positive; return a value of "false" otherwise. If NOT ZERO is specified, return a value of "true" if arithmetic-expression is positive or negative; return a value of "false" if arithmetic-expression is equal to zero. POSITIVE, NEGATIVE, and each used without the NOT keyword, ZERO algebraically tests arithmetic-expression. If POSITIVE is specified, return a value of "true" if arithmetic-expression is greater than zero; return a value of "false" otherwise. If NEGATIVE is specified, return a value of "true" if arithmetic-expression is less than zero; return a value of "false" otherwise. If ZERO is specified, return a value of "true" if arithmetic-expression is equal to zero; return a value of "false" otherwise. Example Assume that the variable A identifies the numeric value -5. IF A IS ZERO NEXT SENTENCE ELSE DIVIDE A INTO SUMS. In this example, because A is not zero, the statement DIVIDE A INTO SUMS is executed. If A were zero, the sentence immediately following the condition sentence would be executed. Class Condition The class condition determines whether an operand consists entirely of numbers and an operational sign, or letters, or a user-defined class. Syntax.
[]
Parameters. identifier-1 names the operand to be tested. It must be described implicitly or explicitly as USAGE IS DISPLAY. Other restrictions apply if the keyword NUMERIC is used. HP COBOL II allows PACKED-DECIMAL items to be tested for NUMERIC as an HP extension to the ANSI COBOL standard.[REV BEG] If identifier-1 is a function-identifier, it must reference an alphanumeric function.[REV END] NOT coupled with one of the next keywords negates the condition. ALPHABETIC means a value of "true" is returned if the operand consists entirely of characters selected from the letters a through z, A through Z, and a space. Otherwise a value of "false" is returned. NUMERIC means a value of "true" is returned if the operand consists entirely of numerals selected from the set 0 through 9 and a single operational sign. Otherwise a value of "false" is returned. ALPHABETIC-LOWER means a value of "true" is returned if the operand consists entirely of the lowercase letters a through z and space. Otherwise a value of "false" is returned. ALPHABETIC-UPPER means a value of "true" is returned if the operand consists entirely of the uppercase letters A throuth Z and space. Otherwise a value of "false" is returned. class-name-1 means a value of "true" is returned if the operand consists entirely of the characters listed in the definition of class-name-1 in the SPECIAL-NAMES paragraph of the ENVIRONMENT DIVISION. Description. You cannot use a NUMERIC test if the operand has a data description defining it as alphabetic, or as a group item composed of elementary items whose data descriptions indicate the presence of an operational sign or signs. If the data description of the operand does not indicate the presence of an operational sign, the operand is considered numeric only if it consists of numerals, and has no operational sign. If the data description of the operand does indicate an operational sign, the operand is considered numeric only if it consists of numerals from the set 0 through 9, and a single valid operational sign. Valid operational signs are determined by the presence or absence of the SIGN IS SEPARATE clause in the data description of the operand. If the SIGN IS SEPARATE clause is present, the valid operational signs are the standard data format characters, + and -. If the SIGN IS SEPARATE clause is not present, the valid operational signs in standard data format are shown in Table 7-7 under the heading, USAGE IS DISPLAY. The ALPHABETIC, ALPHABETIC-LOWER, ALPHABETIC-UPPER, and class name tests cannot be used with an operand whose data description describes it as numeric. To illustrate the class condition, the following example uses an operand which, in standard data format, is 35798D. Data description of operand: 01 FIRST-NUMBER PIC S9(6) SIGN IS TRAILING. Condition test: FIRST-NUMBER IS NUMERIC In this case, the test returns a value of "true", since D is a valid operational sign. D has the value +4, thus making the numeral 35798D equivalent to +357984. Switch-Status Condition A switch-status condition determines the on or off status of a defined switch. The function name and the on or off value associated with the condition must be specified in the SPECIAL-NAMES paragraph of the ENVIRONMENT DIVISION. The Switch-Status condition has the following format: condition-name-1 Parameter condition-name-1 the name associated with the function name in the SPECIAL-NAMES paragraph of the ENVIRONMENT DIVISION. The result of the test is true if the switch is set to the specified position corresponding to condition-name-1. Example ENVIRONMENT DIVISION SPECIAL-NAMES. SW0, OFF STATUS IS NOADD, ON STATUS IS ADDONE. : PROCEDURE DIVISION. PRINT-ROUTINE. IF NOADD THEN PERFORM OTHER-ACTION. : In the above example, if the status of switch SW0 is "off", then a routine named OTHER-ACTION is performed. If the status of switch SW0 is "on", then OTHER-ACTION is not performed, and control passes to the next executable statement. Relation Conditions There are two types of relation conditions in HP COBOL II. One is ANSI standard; the other is used for checking condition codes after intrinsic calls. The intrinsic relation condition is described following the description of ANSI standard relation conditions. ANSI Standard Relation Conditions. A relation condition compares two operands, each of which may be a data item referenced by an identifier, a literal, or the value resulting from an arithmetic statement. If a specified relation exists between the two operands, the relation condition value is "TRUE". You may compare two numeric operands, regardless of their respective usages; however, if you want to compare two operands and one of them is not numeric, then both must have the same usage. Note that since group items are treated as alphanumeric, nonnumeric comparison rules apply. A relation condition must contain at least one reference to a variable. Relation conditions have the following format:
[]

NOTE The required relational characters '>' , '<' , '=' , '<=' , '>=' , and '<>' are not underlined to avoid confusion with other symbols such as '>=' (greater than or equal to).
Parameters. identifier-1 the subject of the condition. or literal-1 or arithmetic-expression-1 or index-name-1 identifier-2 the object of the condition. or literal-2 or arithmetic-expression-2 or index-name-2 [NOT] GREATER THAN equivalent to [NOT] > [NOT] LESS THAN equivalent to [NOT] < [NOT] EQUAL TO equivalent to [NOT] = or < > (< > is an HP extension to the ANSI COBOL standard.) NOT coupled with the next keyword or relation character has the following meaning: NOT GREATER or NOT > means less than or equal; NOT LESS or NOT < means greater than or equal; NOT EQUAL or NOT = means greater than or less than. GREATER THAN OR EQUAL TO is equivalent to >=. LESS THAN OR EQUAL TO is equivalent to <=. Comparison of Numeric Operands.. For operands belonging to the numeric class, a comparison is made with respect to the algebraic values of the operands. The number of digits in an operand is not significant. Also, no distinction is made between a signed or unsigned value of zero. Comparison of numeric operands is not affected by their usages. Unsigned numeric operands are considered to be positive when they are used as operands in a comparison. Comparisons Using Index Names and Index Data Items.. Relation tests may be made using any of the index names and index data items described below. * Two index names. The result is the same as if the corresponding occurrence numbers were compared. * An index name and a data item (other than an index data item) or literal. The occurrence number corresponding to the value of the index name is compared to the data item or literal. * An index data item and an index name or another index data item. The actual values are compared without conversion. An index data item should only be compared with another index data item or an index name. Comparison of an index data item with any other data item or a literal gives an undefined result. Comparison of Nonnumeric Operands.. For nonnumeric operands, or one nonnumeric operand and one numeric operand, a comparison is made with respect to the specified collating sequence (refer to "OBJECT-COMPUTER Paragraph" in Chapter 6 ). If one of the operands is numeric, it must be an integer data item or an integer literal. It must also have the same usage as the nonnumeric operand. If the nonnumeric operand is an elementary data item or a literal, the numeric operand is treated as though it were moved to an elementary alphanumeric data item of the same size as the numeric data item. The contents of this alphanumeric data item are then compared to the nonnumeric operand. If the nonnumeric operand is a group item, the numeric operand is treated as though it were moved to a group item of the same size as the numeric data item. The contents of this group item are then compared to the nonnumeric operand. Remember, a group item is always classified as alphanumeric.
NOTE In the previous paragraphs, "the same size as the numeric data item" means the size of the numeric data item in standard data format. If the P character of the PICTURE clause is included in the description for numeric operand, it must not be included in determining the size of the operand.
The size of an operand is the total number of standard data format characters in the operand. When operands are of unequal size, comparison proceeds as though the shorter operand is extended on the right by sufficient spaces to make the operands of equal size. When operands are of equal size (or have been adjusted as described in the preceding paragraph), the comparison proceeds on a character-by-character basis, starting with each leftmost character and continuing until either the last character of each operand has been compared, or a pair of unmatched characters is found. The operands are considered equal if each pair of characters match, from the leftmost to the rightmost. The first time a pair of characters is found to be unequal (that is, do not match), their positions in the program collating sequence, and the character having the numerically larger index in the collating sequence, is considered to be greater than the other character. Example 01 SUBJECT PIC X(06) VALUE 'FLAXEN'. 01 OBJECT PIC X(07) VALUE 'FLATTER'. The relative condition is: SUBJECT IS EQUAL TO OBJECT The comparison takes place as follows: F matches F; therefore, proceed. L matches L; therefore, proceed. A matches A; therefore, proceed. X does not match T; therefore find the indices of each in the ASCII collating sequence; Index of X: 88 Index of T: 84 X is greater than T; thus, FLAXEN is greater than FLATTER, and the relation condition above returns a "false" value. Condition Name Conditions 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 condition-name. Condition names have the following format: condition-name-1 Parameter condition-name-1 an identifier described under an 88 level data description entry in the DATA DIVISION. If condition-name is associated with a range of values, then the conditional variable is tested to determine whether or not its value falls in this range, including the end values. The rules for comparing a conditional variable with a condition name are the same as those specified for relation conditions. The result of such a comparison is true if one of the values of condition-name equals the value of its associated conditional variable. Example DATA DIVISION. 01 CON-VAR PICTURE 999. 88 CON-NAME1 VALUES ARE 001 THRU 100. : PROCEDURE DIVISION. : IF CON-NAME1 THEN PERFORM UNDER-VALUE ELSE NEXT SENTENCE. : In the above example, the test is performed to see if CON-VAR has a value of 1, 100, or any number between 1 and 100. If it does, a procedure named UNDER-VALUE is performed. Otherwise, the next sentence is executed. Intrinsic Relation Conditions Intrinsic relation conditions are an HP extension to the ANSI COBOL standard. Intrinsic relation conditions are used only to test the condition codes returned by HP operating system intrinsics after they have been called with the CALL INTRINSIC statement. Syntax Intrinsic relation conditions have the following format:
[]

NOTE The required relational characters '>' , '<' , and '=' are not underlined to avoid confusion with other symbols.
Parameter. mnemonic-name a user-defined name that represents the CONDITION-CODE function. It must be defined in the SPECIAL-NAMES paragraph of the ENVIRONMENT DIVISION. Description. If mnemonic-name is zero, execution of the intrinsic was successful. If mnemonic-name is not zero, then an error probably occurred. Specific meanings are numerous, since they vary from intrinsic to intrinsic. Refer to the MPE Intrinsics Reference Manual for your system for meanings of the values returned. Mnemonic-name should be tested immediately after the intrinsic call, since the value may be altered by the execution of subsequent instructions.
NOTE When using CALLs to operating system intrinsics, the condition code returned is not saved by COBOL and as such is only available until an instruction is executed that changes the condition code. The condition code can be successfully tested with the following examples that illustrate possible correct and incorrect methods.
Examples The following are correct and incorrect examples of intrinsic relation conditions. Correct Example. The generated code for the example below causes control to branch to the following test only if the test result is FALSE and to the next sentence if the test result is TRUE. This method does not allow any intermediate operations, since such operations may cause the state of the condition code to change, thereby causing incorrect program logic flow. IF CC = 0 DISPLAY " CC = " ELSE IF CC > 0 DISPLAY " CC > " ELSE IF CC < 0 DISPLAY " CC < ". Incorrect Examples. The generated code for the incorrect case below causes incorrect condition code status branching for subsequent tests when the test result of the prior test is TRUE, causing execution of the DISPLAY statement. IF CC = 0 DISPLAY " CC = ". IF CC > 0 DISPLAY " CC > ". IF CC < 0 DISPLAY " CC < ". The generated code for the incorrect case below causes incorrect condition code status branching for subsequent tests when the OR condition test is required, as the operations needed to test the condition causes changes to the condition code. IF CC > 0 OR FLAG-TRUE DISPLAY "CC > OR FLAG-TRUE" ELSE IF CC = 0 DISPLAY " CC = " ELSE IF CC < 0 DISPLAY " CC < ".


MPE/iX 5.0 Documentation