HP 3000 Manuals

General Formats [ Micro Focus COBOL Language Reference ] MPE/iX 5.0 Documentation


Micro Focus COBOL Language Reference

General Formats 

Format 1 

[]
Format 2
[]
The generic term procedure division header is decribed in the next section, Procedure Division Header. The declarative sentence shown above is a USE statement (see the section later in this chapter and the chapters Debug Module and Report Writer in your Language Reference - Additional Topics). It specifies when the section is to be executed. A procedure comprises a paragraph or group of paragraphs, or a section or group of sections in the Procedure Division. If one paragraph is in a section, all must be. This rule is not enforced (for MF, OSVS, and VSC1 only). A paragraph comprises a paragraph-name followed by a period and a space, and any number of sentences. It is terminated either immediately before the next paragraph-name or section-name or at the end of the Procedure Division, or, in the declaratives portion, with END DECLARATIVES. A section comprises a section header followed by any number of paragraphs. It is terminated either immediately before the next section or at the end of the Procedure Division, or, in the declaratives portion, with END DECLARATIVES. For MF and VSC2 only: 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.) . For MF and VSC1 only: Sentences that are not explicitly contained within a named paragraph as described above are considered to be contained within an unnamed implicit paragraph. Paragraphs that are not explicitly contained within a section are considered to be contained within an implicit, unnamed section. In a program definition, execution begins with the first statement in the Procedure Division, excluding declaratives. Statements are then executed in the order in which they are written, except where some other order is indicated. For MF only: In a call prototype the Procedures Division is never executed. This segment of the chapter deals with arithmetic and conditional expressions, common and input/output phrases, intrinsic functions and COBOL verbs. For MF only: The procedure-division-header is optional in Format 2 of the Procedure Division. However, it is only optional if there are no divisions coded before this and if the Procedure Division begins with a COBOL sentence (not a section header, paragraph header, or Declarative Sectio). The PROCEDURE DIVISION Header The Procedure Division is identified by and must begin with a header in one of the following formats: General Format. Format 1.
[]
For MF only: Format 2.
[]
Directives. 1. In addition to system directives which provide flagging and modify the reserved word list, the following directives may impact either the syntax or semantics described in this section. See your COBOL System Reference for details. * DEFAULTCALLS - sets the default calling convention if none is explicitly coded in the Procedure Division header. * STICKY-LINKAGE - controls whether addressability to Linkage Section items is maintained between calls to different entry points in the same program. Syntax Rules. Syntax rules marked with an asterisk (*) are common to the Procedure Division header and the ENTRY statement. In these rules, where "Procedure Division header or ENTRY statement" are specified you should read "Procedure Division header" or "ENTRY statement" when applying the rules to the Procedure Division header or the ENTRY statement, respectively. All Formats. 1. For MF only: Mnemonic-name is necessary only if the object program is being invoked by another program and that program is using a calling convention other than that used as default by your COBOL system. Typically, the default COBOL calling convention is consistent with that used by a significant implementation of a non-COBOL language for the run-time environment. Mnemonic-name must be defined in the SPECIAL-NAMES paragraph. See the section The Special-Names Paragraph earlier in this chapter for details of how to do this and your COBOL System Reference for details of which calling conventions are supported in your run time environment. 2. For MF only: CHAINING and USING are equivalent. 3. *The USING phrase is necessary only if the object program, the called program, is being invoked by another program, the calling program, that passes parameters. If the calling program is COBOL, parameters are passed if the called program is invoked by the CALL statement or the CHAIN statement (for MF only) and that statement includes a USING phrase. If the calling program is not COBOL then see the documentation for that language to determine if parameters are passed. 4. *The USING phrase of the Procedure Division header or ENTRY statement identifies the names used by the called program for any parameters passed to it by the calling program. If the calling program is COBOL, the parameters passed to a called program are identified in the USING phrase of the calling program's CALL or CHAIN (for MF only) statement. The correspondence between the two lists of names is established on a positional basis (see the CALL statement) , subject to any variation implied by mnemonic-name specified in the called program's Procedure Division header or the calling program's CALL statement. (For MF only.) 5. For MF and only: *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. For MF only: 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. Format 1. 6. *Data-name-1 must be defined as a level 01 or a level 77 entry in the Linkage Section File Section or Working-Storage Section (MF only) of the called program. A particular user-defined word must not appear more than once as data-name-1. It may appear more than once. (OSVS, VSC2 and MF only) The data description entry for data-name-1 must not contain a REDEFINES clause. It may contain a redefines clause. (OSVS, VSC2 and MF only.) Data-name-1 may, however, be the object of a REDEFINES clause elsewhere in the Linkage Section. 7. For MF only: *Data-name-2 must be defined as a level 01 or a level 77 entry in the Linkage Section, File Section or Working-Storage Section of the called program. For MF only: Format 2. 8. *Format 2 can only be used in a program in which the EXTERNAL clause is specified in the PROGRAM-ID paragraph, that is a call prototype. 9. *Data-name-1 and data-name-2 must be defined as 01 level records in the LINKAGE SECTION. 10. *Typedef-name-1, typedef-name-2, and typedef-name-3 must be previously defined in the same source file as a programmer-defined usage by means of a TYPEDEF clause. General Rules. General rules marked with an asterisk (*) are common to the Procedure Division header and the ENTRY statement. In these rules, where "Procedure Division header or ENTRY statement" are specified you should read "Procedure Division header" or "ENTRY statement" when applying the rules to the Procedure Division header or the ENTRY statement, respectively. All Formats. 1. *Up to five data-names are permitted in the USING phrase of the Procedure Division header and in the USING phrase of the CALL statement. For MF only: Up to sixty two data-names are permitted in the USING phrase of the Procedure Division header, the USING phrase of the CALL statement (XOPEN only) and in the USING phrase of the ENTRY statement. 2. *For MF only: The BY REFERENCE and BY VALUE phrases are transitive across the parameters that follow them until another BY REFERENCE or BY VALUE phrase is encountered. If no BY REFERENCE or BY VALUE phrase is specified prior to the first parameter, the BY REFERENCE phrase is assumed. Format 1. 3. Mnemonic-name identifies the calling convention that this program will assume has been adopted by the calling program that invokes it, whether it is invoked by program-name or by entry-name. If the calling convention actually used is different to that implied by mnemonic-name, then the COBOL system may become corrupt. 4. *If data-name-1 is defined as a level 01 or a level 77 entry in the File Section or Working-Storage Section then the object program operates as if a data item had been declared in the Linkage Section with the same data declaration as data-name-1 and the contents of that data item were moved to data-name-1 prior to executimg the first statemetn in the called program. In an initial program, these values are overwritten by the initialization of the program's Working-Storage data and are therefore not available to the called program. 5. *If the calling program is COBOL the following rules apply. If the calling program is not COBOL see your COBOL System Reference for details of when you need to use the BY REFERENCE or BY VALUE clauses. 6. *The sequence of appearance of the operands in the USING phrase of the Procedure Division header or ENTRY statement in the called program and in the corresponding USING phrase in the CALL statement or CHAIN statement or parameter list if the calling program is not COBOL (for MF only) in the calling program determines the correspondence between the data-names used by the called and calling programs. This correspondence is positional and not by name equivalence; the first operand in the called program's USING phrase corresponds to the first operand in the calling program's USING phrase or parameter list, the second to the second, etc. If the correspondence cannot be completed because the numbers of operands are different, then if the remaining unmatched operands are in the CALL statement they are ignored and if they are in the Procedure Division header or ENTRY statement then they must not be referenced within the called program. The positional correspondence may vary depending on the non-COBOL calling conventions implied by mnemonic-name. Any mismatch in the number of the operands specified in the USING phrases of the called and calling programs will only be apparent at run time and so the directive FLAG will not cause this extension to be flagged. 7. *For each data item in the USING phrase of the Procedure Division header or ENTRY statement (MF only) , if the reference to the corresponding data item in the CALL or CHAIN (MF only) statement of the calling program declares the parameter to be passed by content or by reference then the BY REFERENCE phrase must be declared or implied in the called program. If the reference to the corresponding data item in the CALL statement of the calling program declares the parameter to be passed by value then the BY VALUE phrase must be declared or implied in the called program. 8. *If the reference to the corresponding data item in the CALL or CHAIN (MF only) statement of the calling program declares the parameter to be passed by content, the value of the item is moved when the CALL statement is executed and placed into a COBOL system-defined storage item possessing the attributes described in the general rules of the CALL statement. The object program then operates as if this COBOL system-defined storage item were passed by reference, occupying the same storage area as the corresponding data item in the called program. The data description of each COBOL system-defined data item corresponding to each parameter in the BY CONTENT phrase of the CALL statement must be the same, meaning no conversion or extension or truncation, as the data description of the corresponding parameter in the USING phrase of the Procedure Division header or ENTRY statement (MF only). 9. *If the reference to the corresponding data item in the CALL or CHAIN (MF only) statement of the calling program declares the parameter to be passed by reference, the object program operates as ifthe data item in the called program occupies the same storage area asthe data item in the calling program. The description of the data item in the called program must describe the same number of character positions as described by the description of the corresponding data item in the calling program. 10. *For MF only: If the reference to the corresponding data item in the CALL statement of the calling program declares the parameter to be passed by value, the value of the item is moved when the CALL statement is executed, and placed into a system area possessing the attributes described in the general rules of the CALL statement. The object program then operates as if this system area were passed by reference, occupying the same storage area as the corresponding data item in the called program. The data description of each system area corresponding to each parameter with the BY VALUE phrase of the CALL statement must be the same, meaning no conversion or extension or truncation, as the data description of the corresponding parameter in the USING phrase of the Procedure Division header or ENTRY statement. 11. *At all times in the called program, references to data-name-1 and data-name-2 (MF only) are resolved in accordance with the description of the item given in the Linkage Section of the called program. If this description defines a greater number of character positions than the corresponding data item in the calling program, unpredictable results can occur. Failure to comply with this rule or exceeding the maximum allowed size of the system area for a particular run time environment (see your COBOL System Reference) may result in the system becoming catastrophically corrupt. 12. *Data items defined in the Linkage Section of the called program may be referenced within the Procedure Division of that program if, and only if, they satisfy one of the following conditions: a. They are operands of the USING phrase of the Procedure Division header or ENTRY statement (MF only) b. They are subordinate to operands of the USING phrase of the Procedure Division header or ENTRY statement (MF only) c. They are defined with a REDEFINES or RENAMES clause, the object of which satisfies the above conditions. d. They are items subordinate to any item which satisfies the previous condition. e. They are condition-names or index-names associated with data items that satisfy any of the above conditions. 13. *For MF only: When a program is called and a BY REFERENCE operand in the USING phrase corresponds to a parameter in the calling program, a referential connection is established and endures until control is returned to the calling program. If the program is called a second time, without any intervening cancel of the program, and that same BY REFERENCE operand does not correspond to a parameter in the calling program, then you must not reference that operand unless the STICKY-LINKAGE directive is specified. 14. *If the USING phrase is specified, the INITIAL clause must not be present in any CD entry. (See the section The Communication Description - The Complete Entry Skeleton in the chapter Communication in your Language Reference - Additional Topics.) For MF only: Format 2. 15. If a call prototype (program with the EXTERNAL clause in the PROGRAM-ID paragraph) contains a format 2 PROCEDURE DIVISION header and another program in the same source file includes a CALL literal statement referencing the program-name of this call prototype, then the following rules apply: a. If a call convention is specified in the CALL statement, it must match that specified (implicitly or explicitly) in the prototype. If no call convention is specified in the CALL statement, the call convention specified (implicitly or explicitly) in the prototype is used. b. The number of parameters specified in the CALL statement must equal the number of parameters specified in the prototype, except as allowed by the REPEATED phrase. c. For each parameter specified in the CALL statement, the following rules apply: a. If there is a BYREFERENCE or a BYCONTENT phrase associated with the parameter, the corresponding parameter in the prototype must be specified BYREFERENCE. b. If there is a BY VALUE phrase associated with the parameter, the corresponding parameter in the prototype must be specified BY VALUE. c. If the parameter in the CALL statement has no BYREFERENCE, BYCONTENT or BYVALUE phrase, the phrase specified (implicitly or explicitly) in the prototype is used. d. This rule overrides the rules that apply when no matching call prototype is found. In other words, when no call prototype is used, all parameters up to the first BY phrase are treated as if BYREFERENCE were specified and all parameters after any BY phrase but that do not themselves have an explicit BY phrase use the last one in effect. However, when a matching call prototype is found, its definitions for the BY phrases take precedence. e. If the parameter in the prototype is of class numeric, or it is a pointer or index data-item, then the parameter in the CALL must have the same data definition. f. If the parameter in the prototype is of class alphanumeric, the parameter in the CALL must also be of class alphanumeric and be at least as long as the parameter in the prototype. g. If ANY is specified in the prototype, the parameter in the CALL statement can be of any class. d. If the CALL statement includes the GIVING or RETURNING clause, the prototype must also include the clause, and vice versa. The data definition of the data item specified in the CALL must be the same as that of the data item specified in the prototype. e. The DELIMITED BY SIZE phrase in the prototype can be used only for alphanumeric parameters. In this case, the corresponding parameter in the CALL statement is moved to an implicitly allocated data area, and a binary 0 (x"00") character is placed immediately following this copy of the data. If the BY SIZE phrase is omitted, the corresponding parameter in the CALL statement is moved to an implicitly allocated data area, and a binary 0 (x"00") character is placed immediately following the last non space character in the copy data. The intention is to help in interfacing to languages such as C, which use null terminated text strings. f. The REPEATED phrase indicates that there must be at least integer-1 and no more than integer-2 repetitions of the final parameter. If integer-1 TO integer-2 is not specified, integer-1 will be taken as 0 and integer-2 as infinite Arithmetic Expressions 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 4-7. 1. In the following discussion when a numeric data item is referenced, a floating-point data item can also be used (OSVS)(VSC2)(MF). 2. In the following discussion when a numeric literal is referenced, a floating-point literal can also be used (OSVS)(VSC2)(MF). 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 4-7 : Combination Of Symbols In Arithmetic Expressions ------------------------------------------------------------------- | | | | | Second Symbol | | First | | | 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. Five binary arithmetic operators and two unary arithmetic operators 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.


MPE/iX 5.0 Documentation