HP 3000 Manuals

Procedure Division [ 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 

General Formats 

Format 1 

[]
Format 2
[]
The declarative sentence shown above is a USE statement (see Chapter 5 , File Input and Output, chapter 8, Debug and Interactive Debugging, and chapter 10, Report Writer). It specifies when the section is to be executed. ________________________________________________________________________ |(MF) | |However, a section in the DECLARATIVES need not have a | |declarative-sentence; it can be invoked by a PERFORM statement. (See | |the section "The PERFORM Statement" later in this chapter for | |details of the PERFORM statement.) | ________________________________________________________________________ The PROCEDURE DIVISION Header The Procedure Division is identified by and must begin with the following header: General Formats Format 1
[]
[]
Syntax Rules Format 1 1. The USING phrase of the PROCEDURE DIVISION header is specified only if: a. the object program is to function under the control of a CALL statement, and the CALL statement in the calling program contains a USING phrase. ________________________________________________________________________ |(MF) | | | | | | | |b. the object program is to receive data resulting from a CHAIN | | statement, and the CHAIN statement in the chaining program | | contains a USING phrase. | | | | CHAINING and USING are equivalent. | | | ________________________________________________________________________ ________________________________________________________________________ |Format 2 | | | |(MF) | | | | | | | |2. Mnemonic-name is defined in the SPECIAL-NAMES paragraph and | | defines the parameter passing convention to be used on entry to | | this subprogram. See the section "The Special-Names Paragraph" | | earlier in this chapter for details. | | | ________________________________________________________________________ ________________________________________________________________________ |(MF) | | | | | | | |3. Mnemonic-name applies to the whole of the program in which this | | statement appears, including any entry-points. | | | |4. Items used in the BY VALUE phrase are restricted to numeric values| | that are | | | | | | a. Binary (USAGE Binary, COMP, COMP-4, COMP-5, and COMP-X) | | | | b. integers | | | | c. pointers (USAGE POINTER or PROCEDURE-POINTER) | | | | d. ADDRESS OF identifier (any ADDRESS OF special register) | | | | e. LENGTH OF identifier (any LENGTH OF special register) | | | |5. The size of VALUE fields is limited to four bytes. Specific | | operating systems or COBOL implementations can have different | | limits. See your COBOL System Reference for additional | | information. | | | ________________________________________________________________________ Formats 1 and 2 6. Each of the data items in the USING phrase of the PROCEDURE DIVISION header must be defined either as 01 level or 77 level entries in the Linkage Section , File or Working-Storage Section (MF) of the program in which this header occurs. The data descriptions for these entries must not contain a REDEFINES or an EXTERNAL clause. ________________________________________________________________________ |(OSVS) (VSC2) | | | | | | | |7. A data item which is the object of a REDEFINES clause can be | | used. | | | ________________________________________________________________________ ________________________________________________________________________ |(MF) (VSC2) | | | | | | | |8. An item in the USING phrase can be the name of a data item with | | USAGE IS POINTER, provided that the corresponding item in | | the USING phrase of the CALL statement is also either the | | name of a USAGE IS POINTER data item or an ADDRESS special | | register. | | | ________________________________________________________________________ ________________________________________________________________________ |(MF) | |An item in the USING phrase can be the name of a data item with USAGE | |IS PROCEDURE-POINTER provided that the corresponding item in the USING| |phrase of the CALL statement is also the name of a USAGE IS | |PROCEDURE-POINTER data item. | ________________________________________________________________________ ________________________________________________________________________ |(OSVS) (VSC2) | | | | | | | |9. A data item in the USING phrase of the PROCEDURE DIVISION header | | or ENTRY USING statement can have a REDEFINES clause in its data | | description entry. | | | ________________________________________________________________________ ________________________________________________________________________ |(MF) | | | | | | | |10. Data-name-1 must be defined as a data item in the Linkage Section | | of the program in which this header appears. | | | |11. The size of the entry is defined by the number of bytes defined | | for data-name-1 in its PICTURE clause and USAGE. | | | |12. Data-name-1 of the PROCEDURE DIVISION header in the called program| | and data-name-1 in the calling program must define an equal number| | of character positions, although their names need not be the same.| | If their definitions are not identical, unpredictable results can | | occur as the data space which is not allocated to the data item | | can be corrupted. | | | ________________________________________________________________________ General Rules ________________________________________________________________________ |(MF) | | | |Format 2 | | | | | | 1. 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 ENTRY USING statement if | | the VALUE field is defined as BINARY, COMP, COMP-4, or | | COMP-X. | | | | 2. 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 may | | currently give the desired results, but upward compatibility is| | not guaranteed. | ________________________________________________________________________ Format 1 and 2 3. The Linkage Section data items are processed according to their data descriptions given in the invoked program. 4. When the USING phrase is present, a match is made between data-name-1 of the PROCEDURE DIVISION header in the invoked program and data-name-1 in the USING phrase of the CALL or CHAIN (MF) statement in the invoking program. Their descriptions must define an equal number of character positions; however, they need not be the same name. Similarly, there is an equivalent relationship between data-name-2, ..., in the USING phrase of the invoked program and data-name-2, ... in the USING phrase of the CALL or CHAIN (MF) statement in the invoking program. A data-name must not appear more than once in the USING phrase of the PROCEDURE DIVISION header of the invoked program; however, a given data-name can appear more than once in the same USING phrase of a CALL or CHAIN (MF) statement. 5. If any data-name in the USING phrase of the PROCEDURE DIVISION header is described in the Linkage Section, the CALL or CHAIN (MF) operation sets that data-name to refer to the corresponding data item in the invoking program, and not to any data item in the called program. Thus, any operation on that data- name in the invoked program operates on the data item in the invoking program. ________________________________________________________________________ |(MF) | | | | | | | |6. If any data-name in the USING phrase of the PROCEDURE DIVISION | | header is described in the File Section or Working-Storage | | Section, the CALL or CHAIN operation will cause the value of the | | corresponding data item in the invoking program to be moved to the| | data item it references. Changes made to the data in the | | invoked program will not affect the data in the invoking | | program. | | | |7. The number of operands in the PROCEDURE DIVISION USING phrase and | | the CALL USING or CHAIN USING phrase can be different. If they | | are different, then the operands in the two statements are matched| | from left to right until the shorter list of operands is | | exhausted. | | | | If the remaining unmatched operands are in the CALL or CHAIN | | statement, then they are ignored. If the remaining unmatched | | operands are in the PROCEDURE DIVISION header and are Linkage | | Section items, they are unavailable to the program. If they are | | referenced at run time, a run-time error will occur. | | | | As any mismatch of operands will be detected only at run time, | | the directive "FLAG" will not cause this extension to be | | flagged. | | | ________________________________________________________________________ ________________________________________________________________________ |(OSVS) (VSC2) (MF) | | | | | | | |8. The setting of the STICKY-LINKAGE directive affects whether you | | can address items in the Linkage Section which were included in | | previously used ENTRY statements, but not the current one. See | | your COBOL System Reference for details. | | | ________________________________________________________________________ 9. If the USING phrase is specified, the INITIAL clause must not be present in any CD entry. (See the section The Communication Description - Complete Entry Skeleton in the chapter Communication.) Arithmetic Expressions Definition of an Arithmetic Expression. An arithmetic expression can be an identifier of a numeric elementary item, a numeric literal, such identifiers and literals separated by arithmetic operators, two arithmetic expressions separated by an arithmetic operator, or an arithmetic expression enclosed in parentheses. Any arithmetic expression can be preceded by a unary operator. The permissible combinations of variables, numeric literals, arithmetic operator and parentheses are given in Table 3-7 . ________________________________________________________________________ |(OSVS) (VSC2) (MF) | | | | | | | |1. In the following discussion when a numeric data item is | | referenced, a floating-point data item can also be used. | | | |2. In the following discussion when a numeric literal is referenced, | | a floating-point literal can also be used. | | | ________________________________________________________________________ Those identifiers and literals appearing in an arithmetic expression must represent either numeric elementary items or numeric literals on which arithmetic can be performed. Table 3-7. Combination Of Symbols In Arithmetic Expressions --------------------------------------------------------------------------------- | | | | First | Second Symbol | | Symbol | | | | | --------------------------------------------------------------------------------- | | | | | | | | | Variable | * / ** + - | Unary + - | ( | ) | | | | | | | | --------------------------------------------------------------------------------- | | | | | | | | Variable | - | P | - | - | P | | | | | | | | --------------------------------------------------------------------------------- | | | | | | | | * / ** + - | P | - | P | P | - | | | | | | | | --------------------------------------------------------------------------------- | | | | | | | | Unary + - | P | - | - | P | - | | | | | | | | --------------------------------------------------------------------------------- | | | | | | | | ( | P | - | P | P | - | | | | | | | | --------------------------------------------------------------------------------- | | | | | | | | ) | - | P | - | - | P | | | | | | | | --------------------------------------------------------------------------------- P indicates a permissible pair of symbols - indicates an invalid pair Variable indicates an identifier or literal Arithmetic Operators. There are five binary arithmetic operators and two unary arithmetic operators that can be used in arithmetic expressions. They are represented by specific characters that must be preceded by a space and followed by a space. Binary Arithmetic Operators Meaning + Addition - Subtraction * Multiplication / Division ** Exponentiation Unary Arithmetic Operators Meaning + The effect of multiplication by numeric literal +1 - The effect of multiplication by numeric literal -1. Formation and Evaluation Rules. 1. Parentheses can be used in arithmetic expressions to specify the order in which elements are to be evaluated. Expressions within parentheses are evaluated first, and within nested parentheses, evaluation proceeds from the least inclusive set to the most inclusive set. When parentheses are not used, or parenthesized expressions are at the same level of inclusiveness, the following hierarchical order of execution is implied: 1st - Unary plus and minus 2nd - Exponentiation 3rd - Multiplication and division 4th - Addition and subtraction 2. Parentheses are used either to eliminate ambiguities in logic where consecutive operations of the same hierarchical level appear or to modify the normal hierarchical sequence of execution in expressions where it is necessary to have some deviation from the normal precedence. When the sequence of execution is not specified by parentheses, the order of execution of consecutive operations of the same hierarchical level is from left to right. 3. An arithmetic expression can only begin with the symbol "(", "+", "-", or a variable and can only end with a ")" or a variable. There must be a one-to-one correspondence between left and right parenthesis of an arithmetic expression such that each left parenthesis is to the left of its corresponding right parenthesis. 4. Arithmetic expressions allow the user to combine arithmetic operations without the restrictions on composite of operands and/or receiving data items. See, for example, Syntax Rule 3 of "The ADD Statement" in this chapter. Conditional Expressions Conditional expressions identify conditions that are tested to enable the object program to select between alternate paths of control depending upon the truth value of the condition. Conditional expressions are specified in the EVALUATE, (ANS85) IF, PERFORM and SEARCH statements. There are two categories of conditions associated with conditional expressions: simple conditions and complex conditions. Each can be enclosed within any number of paired parentheses, in which case its category is not changed. ________________________________________________________________________ |(OSVS) | |If the OSVS system directive (see your COBOL System Reference ) is | |set, reference modification cannot be used within a conditional | |expression. | ________________________________________________________________________ Simple Conditions. The simple conditions are the relation, class, condition-name, switch-status, and sign conditions. A simple condition has a truth value of "true" or "false". The inclusion in parentheses of simple conditions does not change the simple truth value. Relation Condition. A relation condition causes a comparison of two operands, each of which can be the data item referenced by an identifier, a literal or the value resulting from an arithmetic expression. A relation condition has a truth value of "true" if the relation exists between the operands. Comparison of two numeric operands is permitted regardless of the formats specified in their respective USAGE clauses. However, for all other comparisons the operands must have the same usage. If either of the operands is a group item, the nonnumeric comparison rules apply. The general format of a relation condition is as follows:
[]
Note that the required relational characters "<" , ">", and "=" are not underlined to avoid confusion with other symbols such as ">=" . ________________________________________________________________________ |(OSVS) | |Note that "= TO", "> THAN" and "< THAN" will be accepted. | ________________________________________________________________________ [REV BEG] The first operand (identifier-1, literal-1 or arithmetic-expression-1) is called the subject of the condition; the second operand (identifier-2 or literal-2 or arithmetic-expression-2) is called the object of the condition. The relation condition must contain at least one reference to a variable.[REV END] The relational operator specifies the type of comparison to be made in a relation condition. A space must precede and follow each reserved word comprising the relational operator. When used, "NOT" and the next key word or relation character are one relational operator that defines the comparison to be executed for truth value; for example, "NOT EQUAL" is a truth test for an "unequal" comparison; "NOT GREATER" is a truth test for an "equal" or "less" comparison. The meaning of the relational operators is as shown in Table 3-8 . The following relational operators are equivalent: IS EQUAL TO and EQUALS; IS NOT EQUAL TO and IS UNEQUAL TO; IS GREATER THAN and EXCEEDS; IS NOT GREATER THAN and IS LESS THAN OR EQUAL TO; IS NOT LESS THAN and IS GREATER THAN OR EQUAL TO. Table 3-8. Relational Operators
[]
Comparison of Numeric Operands For operands whose class is numeric a comparison is made with respect to the algebraic value of the operands. The length of the literal or arithmetic expression operands in terms of number of digits represented, is not significant. Zero is considered a unique value regardless of the sign. Comparison of these operands is permitted regardless of the manner in which their usage is described. Unsigned numeric operands are considered positive for purposes of comparison. Comparison of Nonnumeric Operands For nonnumeric operands, or one numeric and one nonnumeric operand, a comparison is made with respect to a specified collating sequence of characters (see the section "The Object-Computer Paragraph" earlier in this chapter). If one of the operands is specified as numeric, it must be an integer data item or an integer literal and: 1. If the nonnumeric operand is an elementary data item or a nonnumeric 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 (in terms of standard data format characters), and the contents of this alphanumeric data item were then compared to the nonnumeric operand. (See the section "The MOVE Statement" in this chapter and the PICTURE character "P" in the section Symbols Used earlier in this chapter.) 2. 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 (in terms of standard data format characters), and the contents of this group item were then compared to the nonnumeric operand. (See the section "The MOVE Statement" in this chapter, and the PICTURE character "P" in the section Symbols Used earlier in this chapter.) 3. A non-integer numeric operand cannot be compared to a nonnumeric operand. The size of an operand is the total number of standard data format characters in the operand. ________________________________________________________________________ |(MF) | |Numeric and nonnumeric operands can be compared when their usage is | |not the same. The numeric operand is treated as if it were moved to a| |USAGE DISPLAY item of the same size (in terms of standard data format | |characters), and the contents of this were then compared to the | |nonnumeric operand. | ________________________________________________________________________ There are two cases to consider: 1. Operands of equal size - if the operands are of equal size, comparison effectively proceeds by comparing characters in corresponding character positions starting from the high order end and continuing until either a pair of unequal characters is encountered or the low order end of the operand is reached, whichever comes first. The operands are determined to be equal if all pairs of characters compare equally through the last pair, when the low order end is reached. The first encountered pair of unequal characters is compared to determine their relative position in the collating sequence. The operand that contains the character that is positioned higher in the collating sequence is considered to be the greater operand. 2. Operands of unequal size - if the operands are of unequal size, comparison proceeds as though the shorter operand were extended on the right by sufficient spaces to make the operands of equal size. Comparisons Involving Index-Names and/or Index Data Items Relation tests can be made only between: 1. Two index-names. The result is the same as if the corresponding occurrence numbers were compared. 2. An index-name and a numeric data item or numeric literal. The occurrence number that corresponds to the value of the index-name is compared to the data item or literal. 3. An index data item and an index-name or another index data item. The actual values are compared without conversion. ________________________________________________________________________ |(VSC2) (OSVS) | | | | | | | |4. An index-name can be compared with an arithmetic expression. The | | occurrence number that corresponds to the value of the index-name | | is compared to the computed value of the expression. | | | ________________________________________________________________________ 5. The result of the comparison of an index data item with any data item or literal not specified above is undefined. ________________________________________________________________________ |Comparisons Involving Data Items with USAGE POINTER | | | |(VSC2) (MF) | | | |Two items whose USAGE is either implicitly or explicitly POINTER can | |be compared. Only the relational operators which test for exact | |equality or inequality are permitted in pointer comparisons. | ________________________________________________________________________ General Format
[]
________________________________________________________________________ |(VSC2) (MF) | | | |Syntax Rules | | | | | | 1. Identifier-1 and identifier-3 refer to an 01 or 77 level items | | in the Linkage Section. | | | | | | | |2. Identifier-1 and identifier-3 can refer to any data items defined| | in the Data Division. (MF) | | | |3. Identifier-2 and identifier-4 refer to items with USAGE IS | | POINTER. | | | | Note that only one operand in the comparison can be the | | figurative constant NULL. | | | | The operands are equal if the two addresses are the same, | | otherwise they are unequal. | | | | This type of relation condition is allowed in IF, PERFORM, | | EVALUATE and SEARCH (Format 1) statements. It is not allowed in | | SEARCH (Format 2) statements (SEARCH ALL) because no meaningful | | ordering can be applied to pointer data items. | | | ________________________________________________________________________ ________________________________________________________________________ |Comparisons Involving Data Items with USAGE PROCEDURE-POINTER | | | |(VSC2) (MF) | | | |Two items whose USAGE is PROCEDURE-POINTER can be compared. | ________________________________________________________________________ General Format
[]
________________________________________________________________________ |(VSC2) (MF) | | | |Syntax Rule | | | |Identifier-1 and identifier-2 refer to items with USAGE IS | |PROCEDURE-POINTER. | | | |Note that only one operand in the comparison can be the figurative | |constant NULL. | | | |The operands are equal if the two addresses are the same, otherwise | |they are unequal. | | | |This type of relation condition is allowed in IF, PERFORM, EVALUATE | |and SEARCH (Format 1) statements. It is not allowed in SEARCH (Format| |2) statements (SEARCH ALL) because no meaningful ordering can be | |applied to pointer data items. | ________________________________________________________________________


MPE/iX 5.0 Documentation