HP 3000 Manuals

File Section (Continued) [ Micro Focus COBOL Language Reference ] MPE/iX 5.0 Documentation


Micro Focus COBOL Language Reference

File Section (Continued) 

The USAGE Clause 

Function.   

The USAGE clause specifies the format of a data item in the computer
storage.

General Format.   

[]
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. * COBOL370 - controls whether four or eight bytes of storage are allocated to USAGE PROCEDURE-POINTER data items. * COMP-5 - controls the handling of the operational sign when storing into a USAGE COMP-5 data item. * IBMCOMP- controls the storage allocated for USAGE COMP and USAGE COMP-5 data items. Syntax Rules. 1. The USAGE clause may be written in any data description entry with an entry-number other than 66 or 88. 2. If the USAGE clause is written in the data description entry for a group item, it may also be written in the data description entry for any subordinate elementary item or group item, but the same usage must be specified in both entries. 3. An elementary data item whose declaration contains, or an elementary data item subordinate to a group item whose declaration contains, a USAGE clause specifying COMPUTATIONAL For ANS85 only: , BINARY, PACKED-DECIMAL For OSVS, VSC2, MF, XOPEN only: , COMPUTATIONAL-3 For OSVS, VSC2, MF only: , COMPUTATIONAL-4 For MF and XOPEN only: , or COMPUTATIONAL-5 must be declared with a PICTURE character-string that describes a numeric item (i.e. a PICTURE character-string that contains only the symbols "P", "S", "V", and "9"). See the section The PICTURE Clause earlier in this chapter. For MF only: An elementary data item whose declaration contains no USAGE clause and that is subordinate to a group item whose declaration contains a USAGE clause specifying a format from the list may be declared with a PICTURE character-string that describes an alphabetic, alphanumeric, alphanumeric-edited or numeric-edited data item. 4. For MF and XOPEN only: An elementary data item whose declaration contains, or an elementary data item subordinate to a group item whose declaration contains, a USAGE clause specifying COMPUTATIONAL-5 or COMPUTATIONAL-X (MF only) must be declared with a picture character-string that describes a numeric item For MF only: or describes an alphanumeric item with a size of between one and eight bytes inclusive. If it describes an alphanumeric item of size 1, 2, 3, 4, 5, 6, 7, or 8 bytes, then this is equivalent to specifying an integer item with 2, 4, 7, 9, 12, 14, 16 or 18 decimal digit positions respectively. For MF only: When COMPUTATIONAL-X is specified and the PICTURE character-string describes a numeric item, then that item must be unsigned. 5. The BLANK WHEN ZERO, JUSTIFIED and SIGN clauses must not be specified for data items whose usage is not explicitly or implicitly DISPLAY. 6. The PICTURE clause must not be specified for data items whose usage is COMPUTATIONAL-1, COMPUTATIONAL-2,(OSVS, VSC2, MF only) INDEX , POINTER (VSC2, MF only) or PROCEDURE-POINTER (MF only) 7. The SYNCHRONIZED and VALUE clauses must not be specified for data items whose usage is INDEX. For OSVS, VSC2, and MF only: The SYNCHRONIZED clause can be specified for data items whose usage is INDEX. 8. COMP is an abbreviation for COMPUTATIONAL. For OSVS, VSC2, and MF only: COMP-1 is an abbreviation for COMPUTATIONAL-1. COMP-2 is an abbreviation for COMPUTATIONAL-2. For OSVS, VSC2, XOPEN and MF only: COMP-3 is an abbreviation for COMPUTATIONAL-3. For OSVS, VSC2, and MF only: COMP-4 is an abbreviation for COMPUTATIONAL-4. For MF and XOPEN only: COMP-5 is an abbreviation for COMPUTATIONAL-5. For MF only: COMP-X is an abbreviation for COMPUTATIONAL-X. 9. An index item can be referenced explicitly only in a SEARCH or SET statement, a relation condition, the USING phrase of a Procedure Division, the USING statement of an ENTRY statement, (OSVS, VSC2, MF) or the USING phrase of a CALL statement. 10. For VSC2 and MF only: A pointer or procedure-pointer (MF only) item can be referenced explicitly only in a SET statement, a relation condition, the USING phrase of a CALL statement, the USING phrase of a Procedure Division, the USING statement of an ENTRY statement or the GIVING phrase of a CALL statement. (MF only) 11. An elementary data item described with a USAGE IS INDEX, USAGE IS POINTER, (VSC2 and MF only) or USAGE IS PROCEDURE-POINTER (MF only) clause must not be a conditonal variable. 12. For MF only: Typedef-name-1 must be previously defined in the same source file as a record with the TYPEDEF clause. 13. For MF only: If USAGE typedef-name-1 is specified, the following clauses cannot also be specified: * BLANK * JUSTIFIED * PICTURE * SIGN * SYNCHRONIZED * VALUE 14. For MF only: It is an error to specify USAGE typedef-name-1 if there is an explicit USAGE clause at a higher level in the same hierarchy. 15. For MF only: It is an error to specify any subordinate items (items with a higher level number other than 78) immediately following an item defined with USAGE typedef-name-1. General Rules. 1. If the USAGE clause is written at the group level, it applies to each elementary item in the group except when there is a PICTURE clause and the data item described is non-numeric.(MF only) 2. The USAGE clause specifies the manner in which a data item is represented in the storage of the computer. It does not affect the use of the data item, although the specifications for some statements in the Procedure Division may restrict the USAGE clause of the operands referred to. The USAGE clause may affect the radix or type of character representation of the item. See the section Selection of Character Representation and Radix in the chapter Concepts of the COBOL Language for more details of the format of each usage. 3. The USAGE IS BINARY clause specifies that a radix of 2 is used to represent a numeric item in the storage of the computer. This clause is equivalent to specifying USAGE IS COMPUTATIONAL. 4. The USAGE IS PACKED-DECIMAL clause specifies that a radix of 10 is used to represent a numeric item in the storage of the computer. Furthermore, this clause specifies that each digit position must occupy the minimum possible configuration in computer storage. For OSVS, VSC2, XOPEN and MF only: This clause is equivalent to specifying USAGE IS COMPUTATIONAL-3. 5. The USAGE IS DISPLAY clause (whether specified explicitly or implicitly) specifies that a standard data format is used to represent a data item in the storage of the computer, and that the data item is aligned on a character boundary. 6. For OSVS, VSC2, and MF only: The USAGE IS DISPLAY clause is valid for the following types of items: * Alphabetic * Alphanumeric * Alphanumeric edited * Numeric edited * External floating-point * External decimal (numeric) 7. If the USAGE clause is not specified for an elementary item, or for any group to which the item belongs, the USAGE is implicitly DISPLAY. 8. The USAGE IS INDEX clause specifies that a data item is an index data item and contains a value which must correspond to an occurrence number of a table element. 9. When a MOVE statement or an input-output statement that references a group item that contains an index, pointer, (VSC2, MF only) or procedure-pointer (MF only) data item is executed, no conversion of the index, pointer (VSC2, MF only) or procedure-pointer (MF only) data item takes place. 10. For OSVS, VSC2, and MF only: The USAGE IS COMPUTATIONAL-4 clause is equivalent to specifying USAGE IS COMPUTATIONAL. 11. For MF and VSC2 only: The USAGE IS POINTER clause identifies a data item in which you can store the address of a data item (see the section The SET Statement in this chapter). 12. For MF only: The USAGE IS PROCEDURE-POINTER clause specifies that a data item is a procedure pointer data item in which you can store the address of a procedure. (See the SET statement in this chapter.) The procedure can be written in any language: if COBOL, it represents the Procedure Division of a program that is not nested and identified by either: * the program-name of the PROGRAM-ID paragraph; or * the entry-name of an ENTRY statement. 13. For MF only: If typedef-name-1 was specified as an elementary item, then the USAGE typedef-name-1 clause specifies an elementary item with the same attributes as the programmer-defined usage referenced by typedef-name-1. 14. For MF only: If typedef-name-1 was specified as a group item, then the USAGE typedef-name-1 clause specifies a group item with an identical structure. The effect is as if the data declarations subordinate to the data description entry identified by typedef-name-1 had been specified identically, subordinate to the item declared with the USAGE typedef-name-1 clause. Data-names of the subordinate data items are identical to those declared within the programmer-defined structure referenced by typedef-name-1 and can be uniquely referenced using qualification. The VALUE Clause Function. The VALUE clause defines the value of constants, the initial value of working storage items, and the values associated with a condition name. Examples:. An example of using the NEXT clause is provided in the Examples chapter in your Additional Topics. General Formats. Format 1.
[]
Format 2.
[]
Format3.
[]
Syntax Rules. All Formats. 1. A signed numeric literal must have a signed numeric PICTURE character-string associated with it. 2. All numeric literals in a VALUE clause of an item must have values which are within the range of values indicated by the PICTURE clause, and must not have a value which would require truncation of nonzero digits. Nonnumeric literals in a VALUE clause of an item must not exceed the size indicated by the PICTURE clause. 3. A figurative constant can be substituted in both Format 1 and Format 2 wherever a literal is specified. Format 1. 4. For OSVS only: VALUES ARE can be used with format 1. 5. For OSVS, MF, and VSC2 only: The VALUE clause may no be used with external floating-point data items. For MF only: The VALUE clause may be used with external floating-point data. 6. For OSVS, MF, and VSC2 only: The VALUE clause may be used for an internal floating-point data item, that is an item defined with USAGE COMP-1 or USAGE COMP-2. In this case literal-1 must either be a floating-point literal, the figurative constant ZERO, or a numeric literal representing the value zero. Format 2. 7. The words THRU and THROUGH are equivalent. 8. Any number of Format 2 entries can be written for a data item. 9. Format 2 must be used only in connection with a condition-name. 10. In a condition-name entry, the VALUE clause is required. The VALUE clause and the condition-name itself are the only two clauses permitted in the entry. 11. Literal-2 must be less than literal-3. 12. For OSVS, MF, and VSC2 only: Format 2 may be used to define a conditional-variable associated with an internal floating-point data item, but not an external floating-point data item. In this case, literal-2 and literal-3 must be floating-point literals, the figurative constant ZERO, or numeric literals representing the value zero. For MF only: Format 2 may be used to define a condition-variable associated with an external floating-point data item. 13. Literal-4 must not be equal to any literal-2, and in any literal-2 THROUGH literal-3 pair, literal-4 cannot be greater than or equal to literal-2 and less than or equal to literal-3 (MF). For MF only: Format 3. 14. All identifiers must have been defined before the declaration of the level 78 item. If either identifier-1 or identifier-3 (LENGTH parameters) is a group item, the definition of that group must have been completed before the level 78 declaration, by the appearance of another data item at the same or lower level number. 15. If literal-5 is followed by an operator, literal-5 must be a non-negative integer. 16. Literal-5 and integer-1 must not be floating-point values. General Rules. Formats 1 and 2. 1. The VALUE clause must not conflict with other clauses in the data description of the item or in the data description within the hierarchy of the item. The following rules apply: a. If the category of the item is numeric, all literals in the VALUE clause must be numeric. If the literal defines the value of a working storage item, the literal is aligned in the data item according to the standard alignment rules. (See the section Standard Alignment Rules in the chapter Concepts of the COBOL Language.) b. If the category of the item is alphabetic, alphanumeric, alphanumeric edited or numeric edited all literals in the VALUE clause must be nonnumeric. The literal is aligned in the data item as if the data item had been described as alphanumeric. (See the section Standard Alignment Rules in the chapter Concepts of the COBOL Language.) Editing characters in the PICTURE clause are included in determining the size of the data item (see the section The PICTURE Clause earlier in this chapter) but have no effect on initialization of the data item. Therefore, the VALUE for an edited item is presented in an edited form. c. For MF only: If the item is numeric edited, the value can be a numeric literal or a nonnumeric literal. If the value is a numeric literal, the value contained in the item will be the same as if the numeric literal were moved to the numeric edited item. d. Initialization takes place independent of any BLANK WHEN ZERO or JUSTIFIED clause that can be specified. Data Description Entries Other than Condition-Names and Constant-Names. (MF) (Format 1) 2. Rules governing the use of the VALUE clause differ with the respective sections of the Data Division: a. In the File Section, the VALUE clause must be used in condition-name entries only. b. In the Working-Storage Section and the Communication Section, the VALUE clause must be used in condition-name entries. The VALUE clause can also be used to specify the initial value of a data item, in which case the clause causes the item to assume the specified value at the start of the object program. If the VALUE clause is not used in an item's description, the initial value of that data item is undefined. c. In the Linkage Section, the VALUE clause must be used in condition-name entries only. 3. For OSVS, MF, and VSC2 only: In the File Section and the Linkage Section, and Local-Storage Section(MF), the VALUE clause can be used in data item entries, but is documentary only. 4. The VALUE clause must not be stated in a data description entry that contains a REDEFINES clause, or in an entry that is subordinate to an entry containing a REDEFINES clause. This rule does not apply to condition-name entries. 5. If the VALUE clause is used in an entry at the group level, the literal must be a figurative constant or a nonnumeric literal, and the group area is initialized without consideration for the individual elementary or group items contained within this group. The VALUE clause cannot be stated at the subordinate levels within this group. 6. The VALUE clause must not be written for a group containing items with descriptions, including JUSTIFIED, SYNCHRONIZED, or USAGE (other than USAGE IS DISPLAY). 7. For VSC2 and MF only: The figurative constant NULL can be specified in the VALUE clause only if the data item is defined with USAGE POINTER or USAGE PROCEDURE-POINTER. This is the only value you can specify in the VALUE clause for such an item. The effect is to set the pointer in such a way that it is guaranteed not to point to any data item. 8. For ANS85 only: A VALUE clause specified in a data description entry that contains an OCCURS clause, or in an entry that is subordinate to an OCCURS clause, causes every occurrence of the associated data item to be assigned the specified value. 9. For ANS85 only: If a VALUE clause is specified in a data description entry of a data item which is associated with a variable occurrence data item, the initialization of the data item behaves as if the value of the data item referenced by the DEPENDING ON phrase in the OCCURS clause specified for the variable occurrence data item is set to the maximum number of occurrences as specified by that OCCURS clause. A data item is associated with a variable occurrence data item in any of the following cases: a. It is a group data item which contains a variable occurrence data item. b. It is a variable occurrence data item. c. It is a data item that is subordinate to a variable occurrence data item. If a VALUE clause is associated with the data item referenced by a DEPENDING ON phrase, that value is considered to be placed in the data item after the variable occurrence data item is initialized. Condition-Name Rules (Format 2). 10. In a condition-name entry, the VALUE clause is required. The VALUE clause and the condition-name itself are the only two clauses permitted in the entry. The characteristics of a condition-name are implicitly those of its conditional variable. 11. Format 2 can be used only in connection with condition- names. Wherever the THRU phrase is used, literal-2 must be less than literal-3. 12. For MF only: The FALSE phrase is meaningful only if the associated condition-name is referenced in a SET condition-name TO FALSE statement. (See the section The SET Statement later in this chapter.) For MF only: Constant-Name Rules (Format 3). 13. Format 3 can be used only in a constant-name entry. 14. If literal-5 is specified and not followed by an operator, the characteristic of the constant-name is that of literal-5. Otherwise, the charcateristic of the constant-name is that of an integer. 15. Any number of arithmetic or logical operatorscan be used. The result is evaluated using integer arithmetic in strict left to right order. No parentheses can be used. If any intermediate result is less than zero, the final value is undefined. A constant-name may be used in place of integer-1. 16. The logical operations AND and OR act on the binary representation in a bit-wise manner. 17. LENGTH of identifier-1 or identifier-3 is the size of the storage allocated for identifier-1 or identifier-3, respectively. If the identifier is a group item, the length includes all subordinate data items. 18. The value returned by NEXT is the offset at which the next byte of storage occurs after the previous data declaration. If that data declaration was of a table defined with an OCCURS clause, he value returned by NEXT is the offset at which the next byte of storage occurs after the first element of the table. 19. START of identifier-2 or identifier-4 is the offset at which identifier-2 or identifier-4 begins, respectively. 20. For rules 22 and 23, the offset is defined as follows: * If the identifier is part of an EXTERNAL record or a LINKAGE record, the offset is calculated from the start of the associated 01-level; * If the identifier is defined in LOCAL-STORAGE, the offset is calculated from the start of the LOCAL-STORAGE SECTION; * Otherwise the offset is calculated from the start of the DATA DIVISION. 21. Offsets are not portable across different COBOL implementations and no reliance should be placed on particular values outside this compilation unit.


MPE/iX 5.0 Documentation