Concepts of Classes of Data (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
Concepts of Classes of Data (cont.)
COMPUTATIONAL, COMP, BINARY, (ANS85) COMPUTATIONAL-4 or COMP-4 (MF)
(OSVS) (VSC2.
These numeric data items are held in computer storage in pure binary
two's complement representation. In this format, number values are held
in radix of 2 where each computer bit in the representation starting from
the right (least-significant) end represents the presence or absence of
an increasingly significant power of 2 in that value. Negative numbers
are represented by complementing (inverting all the bit values of) their
positive counterpart, and then adding one to the whole. Storage
requirements depend on the number of "9"s in the PICTURE clause, and
whether the numeric data item is signed or unsigned (see "The PICTURE
Clause" , The COMPUTATIONAL Clause, and "The SIGN Clause" in the
chapter The Nucleus); also your COBOL system will assign storage for
COMPUTATIONAL items in one of two modes; byte-storage and word-storage.
Byte-storage is the default storage-assignment mode for this COBOL
implementation.
Computer Memory Natural Boundaries: The fundamental natural boundaries
of a modern computer's memory are usually based on an eight-bit
character, known as a byte. Within this fundamental framework, machines
fall into two broad categories; those with no other natural boundaries,
called here byte-storage computers, and those with other natural
boundaries based upon multiples of the fundamental boundary of the byte,
called here word-storage computers.
In byte-storage mode, COBOL assigns numeric storage such that each
numeric item occupies the minimum number of bytes (see Selection Of
Character Representation And Radix in this chapter); the SYNCHRONIZED
clause has no meaning in the context and hence has no effect.
Within word-storage computers natural boundaries can occur at 2-byte,
4-byte and/or 8-byte boundaries; accordingly the COBOL language can
provide such data item storage-assignment and synchronization when the
COMPUTATIONAL clause and possibly the SYNCHRONIZED clause are used. This
word-storage assignment of COMPUTATIONAL format data is controlled by
your COBOL system directive, IBMCOMP (see your COBOL System Reference for
details of using this feature).
Table 2-5. COMP(UTATIONAL) Format Data Item Character-Position (Byte) Storage Assignment
---------------------------------------------------------------------------------
| | |
| Number of Digits (9s) in PICTURE | Character-Positions (Bytes) of |
| Representation | Storage-Assigned |
| | |
---------------------------------------------------------------------------------
| | | | |
| Signed | Unsigned | Byte-Storage | Word-Storage |
| | | Mode | Mode |
| | | | |
---------------------------------------------------------------------------------
| | | | |
| 1-2 | 1-2 | 1 | 2 |
| 3-4 | 3-4 | 2 | 2 |
| 5-6 | 5-7 | 3 | 4 |
| 7-9 | 8-9 | 4 | 4 |
| 10-11 | 10-12 | 5 | 8 |
| 12-14 | 13-14 | 6 | 8 |
| 15-16 | 15-16 | 7 | 8 |
| 17-18 | 17-18 | 8 | 8 |
| | | | |
---------------------------------------------------------------------------------
For details of how to enable the word-storage feature of your COBOL
system using the IBMCOMP system directive, see your COBOL System
Reference.
Synchronization: If a data item description contains the SYNCHRONIZED
clause, and word-storage mode is enabled, then the position of that item
within the computer storage is aligned such that the right-hand
(least-significant) end is on a natural boundary of the computer's
storage. Extra character positions (bytes) of computer storage are
reserved adjacent to synchronized items to achieve this alignment; these
bytes, known as padding bytes or implicit FILLER bytes, are normally
inaccessible to the computer program except as part of a group item.
Each elementary data item that is described as SYNCHRONIZED is aligned to
the natural storage boundary that corresponds to its data item storage
assignment (according to Table 2-5 above). Thus, in word-storage mode, a
numeric data item with a PICTURE description of S9 (5) would be assigned
4 bytes of storage (being 1 padding byte and 3 data bytes) and, if
SYNCHRONIZED was specified, would be aligned to the next nearest 4-byte
boundary (that is, with the total (4-byte) storage assignment aligned
such that the number of bytes from the beginning of the record containing
that item to the left-hand (most-significant) end of that item was a
multiple of four.) If the previous item does not end on a 4-byte
boundary, then implicit FILLER assignments are necessary to achieve this.
Other such implicit FILLER bytes can be generated by the use of
SYNCHRONIZED items in non-elementary data descriptions containing an
OCCURS clause (see "The OCCURS Clause" in the chapter The Nucleus).
This is because further extra bytes can need to be reserved for each
group item occurrence in order that the second or subsequent occurrences
have the same alignment to the natural boundaries of the computer storage
as did the first occurrence.
Implicit Synchronization: With word-storage mode enabled, all
record-level data descriptions are automatically synchronized to a full
8-byte boundary.
________________________________________________________________________
|(MF) |
|Where automatic alignment is placed, it is sensitive to the ALIGN |
|directive. See your COBOL System Reference for details. |
________________________________________________________________________
Example of Implicit FILLER Assignments: The following COBOL data
description will produce the computer storage allocation shown in Figure
2-2. An explanation of the symbols used in Figure 2-2 is given below the
figure.
01 UNSYNCHRONIZED-RECORD.
02 UNSYNCHRONIZED-DATA-1 PIC 9(3) DISPLAY.
02 UNSYNCHRONIZED-DATA-2 PIC X(2).
01 COMPOUND-REPEATED-RECORD.
02 ELEMENTARY-ITEM-1 PIC X(2).
02 GROUP-ITEM OCCURS 3 TIMES.
03 ELEMENTARY-ITEM-2 PIC X.
03 ELEMENTARY-ITEM-3 PIC S9(2) COMP SYNC.
03 ELEMENTARY-ITEM-4 PIC S9(4)V9(2) COMP SYNC.
03 ELEMENTARY-ITEM-5 PIC X(5).
Figure 2-2. Sample Computer Storage Allocation
where:
@ indicates implicit FILLER bytes allocated due to automatic
synchronization of a record (01-level) description.
# indicates implicit FILLER bytes allocated when following data
item is explicitly synchronized.
$ indicates implicit FILLER bytes allocated when a non-elementary
item is subject to an OCCURS clause.
9 indicates bytes allocated for a numeric DISPLAY character.
A indicates bytes allocated for an alphanumeric DISPLAY character.
C indicates bytes allocated for a COMPUTATIONAL data storage.
Truncation: In data items of USAGE COMP, data is held in binary format
as described in the previous sections. The storage allocated for an item
can have space for larger numbers than specifed by the PICTURE clause.
For example, an item described as PIC 99 COMP is normally assigned one
byte, which can hold numbers up to 255.
To conform with the rules of ANSI COBOL, numbers behave as decimal
numbers, regardless of their format. If, in an arithmetic statement, the
result is bigger than the PICTURE clause of a receiving item allows, this
causes a size error, and if the ON SIZE ERROR phrase is specifed the
result is not stored in the receiving item. In a non-arithmetic
statement, if this situation occurs the decimal value is truncated, on
the left to the number of digits specified in the PICTURE clause.
________________________________________________________________________
|(MF) |
|However, data in USAGE COMP items can be forced to behave as binary |
|data, that is, truncation only occurs if it is necessary in order for |
|the data to fit the space allocated. The behavior of USAGE COMP items|
|is controlled by the setting of the COBOL system directive, TRUNC. |
|(See your COBOL System Reference for details on how to invoke this |
|feature.) This directive selects whether the decimal value is |
|truncated to the picture size, or the binary value is truncated |
|to the space available. It distinguishes between results of |
|arithmetic statements, and data being moved by non-arithmetic |
|statements. |
________________________________________________________________________
Regardless of the setting of any directive, (MF) an arithmetic statement
gives the size error condition if the result has more decimal digits than
specified in the PICTURE clause of a receiving item.
____________________________________________________________________________
|(MF) |
|Example of Truncation: The TRUNC directive can change the results of |
|some operations, as demonstrated in the following examples in which |
|item A is described as PIC99 COMP. |
| |
| |
|--------------------------------------------------------------------------|
|| | ||
|| Operation | Result ||
|| | ||
|--------------------------------------------------------------------------|
|| | | | ||
|| | TRUNC | NOTRUNC | TRUNC"ANSI" ||
|| | | | ||
|| MOVE 163 TO A | 63 | 163 | 63 ||
|| | | | ||
|| MOVE 263 TO A | 63 | 7 | 63 ||
|| | | | ||
|| MOVE 13 TO A, | | | ||
|| | | | ||
|| ADD 150 TO A | 63 | 163 | undefined results ||
|| | | | ||
|| MOVE 13 TO A, | | | ||
|| | | | ||
|| ADD 250 TO A | 63 | 7 | undefined results ||
|| | | | ||
|--------------------------------------------------------------------------|
| |
| |
|Notes: |
| |
| |
| 1. This directive has no effect on the truncation of low-order |
| digits in non-integer data. This always conforms with the |
| behavior specified in ANSI COBOL. |
| |
| 2. If the IBMCOMP system directive is set, extra upper bytes may |
| be allocated to a COMP item. These are counted in the space |
| allocated. When IBMCOMP is on, padding bytes may be generated |
| before a COMP item with a SYNC clause; these are not part of |
| the item, and are never affected by data stored in the |
| item. |
| |
| 3. When a value being stored into a signed item is limited to the |
| number of digits by the PICTURE clause, it can never be big |
| enough to overwrite the sign bit. When the NOTRUNC directive |
| is set this is not true, and the value, if large enough, will |
| overwrite the sign bit. |
____________________________________________________________________________
________________________________________________________________________
|COMPUTATIONAL-1, COMPUTATIONAL-2, COMP-1, or COMP-2 Format |
| |
|(MF) (OSVS) (VSC2) |
| |
|This format is used for internal floating-point data items. Such data|
|items can be used in all syntax where a numeric data item can be used |
|and where the syntax is a part of the ANSI'74, ANSI'85, OSVS, or VSC2 |
|COBOL language definition. Such data items can not be used where |
|integer data items are required unless explicitly allowed by the rules|
|for a specific COBOL verb. An internal floating-point data item |
|can not be used in other syntax unless a specific rule allows |
|it. |
| |
|The internal storage format can differ from operating system to |
|operating system. In all storage formats, four pieces of information |
|are stored: |
| |
| |
| a. The exponent - the power of 10 to which the specific numeric |
| value is multiplied. |
| |
| b. The exponent sign - an indication of whether the specific |
| numeric value (mantissa) is multiplied by a "whole" number in |
| the series, 1, 10, 100, etc or by a fractional number in the |
| series 1/10, 1/100, 1/1000, etc. |
| |
| c. The mantissa - the specific value, which when multiplied by |
| a power of 10 provides the numeric value of the data |
| item. |
| |
| d. The mantissa sign - an indication of whether the resultant |
| value of the data item is negative or positive. |
| |
|Items that are USAGE COMPUTATIONAL-1 (COMP-1) are usually referred to |
|as single precision floating-point items while items that are USAGE |
|COMPUTATIONAL-2 (COMP-2) are usually referred to as double precision |
|floating-point items. Depending on the operating system or |
|mathematical support libraries available to this COBOL system, |
|different constraints can exist for single and double precision |
|floating-point items. There can be constraints on the maximum |
|exponent sizes, on the maximum mantissa sizes, or both. See your |
|operating system or mathematical library floating-point support |
|documentation for additional information. |
| |
|It is important to understand that internal floating-point |
|representation is not a continuous numeric spectrum. Internal |
|floating-point representations are not standard from operating system |
|to operating system. For example, in one representation of internal |
|floating-point values, the following shows internal to decimal |
|equivalence: |
________________________________________________________________________
________________________________________________________________________
|(MF) (OSVS) (VSC2) |
| |
| |
|Internal (Hexadecimal) Storageecimal Value (Scientific Notation) |
| |
|X"AD17E148" -.12345673E-23 |
|X"AD17E149" -.12345810E-23 |
| |
| |
|Therefore, any application which tested for or expected an internal |
|floating-point item with an exact decimal value of -.12345678E-23, |
|would never find it, while in some other system of internal |
|floating-point storage, that value might be found while the values |
|listed above would never exist. Therefore, any application which |
|tests for exact equivalence between internal floating-point items |
|and other numeric values (including external floating-point |
|items and floating-point literals) can not be portable and may |
|result in different logic flow even when using the same input |
|data. |
| |
|For internal floating-point items, the size of the item in storage is |
|determined by its USAGE clause. USAGE COMPUTATIONAL-1 |
________________________________________________________________________
________________________________________________________________________
|(MF) |
|When IBMCOMP is on, padding bytes can be generated before an internal |
|floating point item with a SYNC clause; these bytes are not |
|part of the item, and are never affected by data stored in the |
|item. |
________________________________________________________________________
________________________________________________________________________
|COMPUTATIONAL-3 or COMP-3 or PACKED-DECIMAL (ANS85) Format |
| |
|(OSVS) (VSC2) (MF) (XOPEN) |
| |
|This form, commonly called binary-coded-decimal form, represents |
|numeric data items in radix 10, but with each digit of the value held |
|in only one half of one computer character, as described in Table |
|2-6 below. The sign is held in a separate trailing digit |
|(half-character) position; that is, at the right-hand or least |
|significant end of the item. Any unused half bytes will be set to |
|zero. (MF) |
________________________________________________________________________
Table 2-6. COMPUTATIONAL-3 Digit Representation
-------------------------------------------------------------
| Digit Value | Digit Representation in |
| | Hexadecimal |
-------------------------------------------------------------
| | Left Half- | Right Half- |
| | Character | Character |
| | (odd digit) | (even digit) |
| 0 | X"00" | X"00" |
| 1 | X"10" | X"01" |
| 2 | X"20" | X"02" |
| 3 | X"30" | X"03" |
| 4 | X"40" | X"04" |
| 5 | X"50" | X"05" |
| 6 | X"60" | X"06" |
| 7 | X"70" | X"07" |
| 8 | X"80" | X"08" |
| 9 | X"90" | X"09" |
-------------------------------------------------------------
Note: Count even and odd starting from the right.
________________________________________________________________________
|(OSVS) (VSC2) (MF) |
|Table 2-7 shows the sign digit used for COMPUTATIONAL-3; |
|storage requirements for this format depend only on the number of |
|"9s" in the PICTURE clause of the data item as shown in Table |
|2-8. |
________________________________________________________________________
________________________________________________________________________
|(OSVS) (VSC2) (MF) (XOPEN) |
________________________________________________________________________
Table 2-7. COMPUTATIONAL-3 Sign-Digit Representation
------------------------------------------------------------
| | | |
| Sign Convention in | Sign of Data | Sign Half- |
| the | item Value | Character, in |
| PICTURE Clause | | Hexadecimal |
| | | |
------------------------------------------------------------
| | | |
| Unsigned | n/a | X"0F" |
| Signed | + | X"0C" |
| Signed | - | X"0D" |
| | | |
------------------------------------------------------------
Table 2-8. Numeric Data Storage for the COMP(UTATIONAL)-3 [or PACKED-DECIMAL] (ANS85) PICTURE Clause.
---------------------------------------------------------
| | |
| Bytes Required | Number of Digits |
| | (Signed or Unsigned) |
| | |
---------------------------------------------------------
| | |
| 1 | 1 |
| 2 | 2-3 |
| 3 | 4-5 |
| 4 | 6-7 |
| 5 | 8-9 |
| 6 | 10-11 |
| 7 | 12-13 |
| 8 | 14-15 |
| 9 | 16-17 |
| 10 | 18 |
| | |
---------------------------------------------------------
Example:
a. For COMPUTATIONAL-3 and PICTURE 9999, the number +1234 would be
stored as follows:
... 0 1 2 3 4 F
0000 0001 0010 0011 0100 1111
| | | | | |
+----v----+ +----v----+ +----v----+
1 byte 1 byte 1 byte
where F represents the non-printing plus sign.
________________________________________________________________________
|(OSVS) (VSC2) (MF) (XOPEN) |
| |
| |
| |
|2. For COMPUTATIONAL-3 and PICTURE S9999, the number + 1234 would be|
| stored as follows: |
| |
| Storage would be as in a. above except that the |
| least-significant digit would be replaced by C(1100) representing|
| the plus sign. |
| |
|3. For COMPUTATIONAL-3 and PICTURE S9999, the number -1234 would be |
| stored as follows: |
| |
| Storage would be as in a. above except that the |
| least-significant byte would be replaced by D(1101) representing |
| the minus sign. |
| |
| |
|The SYNCHRONIZED clause (with or without the LEFT or RIGHT phrase) has|
|no effect on COMPUTATIONAL-3 data declarations. |
________________________________________________________________________
________________________________________________________________________
|(MF) |
| |
|COMPUTATIONAL-X, COMP-X, COMPUTATIONAL-5, or COMP-5 Format |
| |
|This format is as for COMPUTATIONAL format. See the section |
|COMPUTATIONAL, COMP, BINARY, COMPUTATIONAL-4 Or COMP-4 Format earlier |
|in this chapter. |
| |
|It has the following differences from the COMPUTATIONAL format: |
| |
| |
| 1. The PICTURE character-string can consist of all "X"s. If it |
| does, the number of "X"s gives the length of the item in |
| bytes. |
| |
| 2. Whether the PICTURE character-string consists of "X" s or |
| "9"s, the value that can be stored is limited to the |
| largest binary number for which the allocated storage has |
| space. The item is not affected by the TRUNC, COMP, |
| and ALIGN system directives. However, there is still |
| a maximum of 18 digits which can be specified (either |
| up to eighteen "9"s or up to eight "X"s in the PICTURE |
| clause.) |
| [REV BEG] |
| |
| 3. The number of "9"s in the PICTURE character string affect |
| the program if the item is a destination field in an |
| arithmetic operation including an ON SIZE ERROR or NOT ON SIZE |
| ERROR clause: the number of "9"s will determine whether |
| or not a size error condition is deemed to have arisen |
| due to a decimal digit overflow. When either clause is |
| present, only arithmetic results falling within this range, |
| that is, not causing a size error, will be stored.[REV |
| END] |
________________________________________________________________________
________________________________________________________________________
|(MF) |
| |
| |
| |
|4. The following are the only differences between COMPUTATIONAL-X |
| and COMPUTATIONAL-5 items: |
| |
| |
| a. A COMPUTATIONAL-5 data item can be signed; a |
| COMPUTATIONAL-X data item must not be signed. When "X"s |
| are used in the PICTURE clause for a COMP-5 data item, it |
| is treated as unsigned, not signed. |
| |
| b. A COMPUTATIONAL-X item is always stored using the same |
| storage scheme as BINARY items, that is with the |
| high-order bytes stored at the lowest addresses and |
| successively lower-order bytes at successively higher |
| addresses. |
| |
| The storage of COMPUTATIONAL-5 items is operating system |
| specific. In some operating systems COMPUTATIONAL-5 items|
| are stored with the low-order bytes stored at the lowest |
| addresses and successively higher-order bytes stored at |
| successively higher addresses. For example, under |
| operating systems which store numeric items in reverse |
| order, a COMPUTATIONAL-5 item with a hexadecimal value |
| of: |
| |
| 12 34 56 78 9A |
| |
| would be stored as: |
| |
| 9A 78 56 34 12 |
| |
| while a COMPUTATIONAL-X item (or a COMPUTATIONAL-5 item on|
| an operating system without reverse numeric storage) would|
| be stored as: |
| |
| 12 34 56 78 9A |
| [REV BEG] |
| |
| c. A COMPUTATIONAL-5 item is affected by the IBMCOMP |
| system directive; a COMPUTATIONAL-X item is not.[REV |
| END] |
| |
|5. If a non-arithmetic statement attempts to store a negative |
| value in a COMPUTATIONAL-X item, the absolute value is |
| stored. |
| |
| The result of a statement attempting to store a negative value in|
| an unsigned COMPUTATIONAL-5 item is sensitive to the COMP-5 |
| system directive. See your COBOL System Reference for |
| details. |
| |
________________________________________________________________________
________________________________________________________________________
|(VSC2) (MF) |
|POINTER Format |
| |
|This COBOL system assigns four bytes of storage for POINTER format. |
|The method of data storage is machine-dependent. |
________________________________________________________________________
Uniqueness of Reference
Qualification.
Every user-specified name that defines an element in a COBOL source
program and is referenced in that program (ANS85) must be unique, either
because no other name has the identical spelling and hyphenation, or
because the name exists within a hierarchy of names such that references
to the name can be made unique by mentioning one or more of the higher
levels of the hierarchy. The higher levels are called qualifiers and the
process that specifies uniqueness is called qualification. Enough
qualification must be mentioned to make the name unique; however, it may
not be necessary to mention all levels of the hierarchy.
In the Data Division, all data-names used for qualification must be
associated with a level indicator or a level-number. Therefore, two
identical data-names must not appear as entries subordinate to a group
item unless they are capable of being made unique through qualification
or unless they are never referenced. (ANS85) In the Procedure Division
two identical paragraph-names must not appear in the same section.
In the hierarchy of qualification, names associated with a level
indicator are the most significant, followed by those names associated
with level-number 01, followed by names associated with level-number 02
through 49. A section-name is the highest (and the only) qualifier
available for a paragraph-name. Thus, the most significant name in the
hierarchy must be unique and cannot be qualified. Subscripted or indexed
data-names and conditional variables, as well as procedure-names and
data-names, can be made unique by qualification. The name of a
conditional variable can be used as a qualifier for any of its
condition-names. Regardless of the available qualification, no name can
be both a data-name and procedure-name.
Qualification is performed by following a data-name, a condition- name, a
paragraph-name, or a text-name by one or more phrases composed of a
qualifier preceded by IN or OF, which are logically equivalent.
________________________________________________________________________
|(ANS85) |
|When the resource named is a function, the function definition may |
|require the user to specify in the reference to the function a value |
|or set of values for one or more parameters which determine the value |
|of the function for that particular reference. This is accomplished |
|through the specification of arguments as described in the section |
|Function Identifier later in this chapter. |
________________________________________________________________________
The general formats for qualification are:
Format 1
Format 2
Format 3
The rules for qualification are as follows:
1. Each qualifier must be of a successively higher level and within
the same hierarchy as the name it qualifies.
2. The same name must not appear at two levels in a hierarchy if it
is explicitly referenced within the program. (ANS85)
3. If a data-name or a condition-name is assigned to more than one
data item in a source program, the data-name or condition-name
must be qualified each time it is referred to in the Procedure,
Environment, and Data Divisions (except in the REDEFINES clause,
where qualification is unnecessary and must not be used).
4. A paragraph-name must not be duplicated within a section. When a
paragraph-name is qualified by a section-name, the word SECTION
must not appear. A paragraph-name need not be qualified when
referred to from within the same section.
________________________________________________________________________
|(ANS85) |
|Neither a paragraph-name nor a section-name need be unique or capable |
|of being made unique unless explicitly referenced. |
________________________________________________________________________
5. A data-name cannot be subscripted when it is being used as a
qualifier.
6. A name can be qualified even though it does not need
qualifications; if there is more than one combination of
qualifiers that ensures uniqueness, then any such set can be used.
The complete set of qualifiers for a data-name must not be the
same as any partial set of qualifiers for another data-name.
Qualified data-names can have up to five qualifiers.
________________________________________________________________________
|(ANS85) |
|Up to fifty qualifiers are permitted. |
________________________________________________________________________
7. If more than one COBOL library is available to your COBOL system,
text-name must be qualified each time it is referenced.
________________________________________________________________________
|(MF) (VSC2) (OSVS) |
|This restriction is not enforced. |
________________________________________________________________________
Subscripting.
Subscripts can be used only when reference is made to an individual
element within a list or table of like elements that have not been
assigned individual data-names (see "The OCCURS Clause" in the
chapter The Nucleus).
The subscript can be represented either by a numeric literal that is an
integer, by a data-name, or by a data-name followed by the operator "+"
or "-" , followed by an unsigned integer numeric literal. The data-name
must be a numeric elementary item that represents an integer, and the
whole subscript must be delimited by the balanced pair of separators,
left-parenthesis and right-parenthesis.
The subscript data-name can be signed and, if signed, it must be
positive. The lowest possible subscript value is 1. This value points
to the first element of the table. The next sequential elements of the
table are pointed to by subscripts whose values are 2, 3, ... . The
highest permissible subscript value, in any particular case, is the
maximum number of occurrences of the item as specified in the OCCURS
clause.
The subscript, or set of subscripts, that identifies the table element is
delimited by the balanced pair of separators, left parenthesis and right
parenthesis following the table element data-name. The table element
data-name appended with a subscript is called a subscripted data-name or
an identifier. When more than one subscript is required, they are
written in the order of successively less inclusive dimensions of the
data organization. Up to 3 subscripts are permitted.
________________________________________________________________________
|(ANS85) Up to 7 subscripts are permitted. |
________________________________________________________________________
________________________________________________________________________
|(MF) Up to 16 subscripts are permitted. |
________________________________________________________________________
The general format for subscripting is:
Syntax Rules
1. The data description entry containing data-name-1 or the data-name
associated with condition-name-1 must contain an OCCURS clause or
must be subordinate to a data description entry which contains an
OCCURS clause.
2. Except as defined in syntax rule 4, when a reference is made to a
table element, the number of subscripts must equal the number of
OCCURS clauses in the description of the table element being
referenced. When more than one subscript is required, the
subscripts are written in the order of successively less inclusive
dimensions of the table.
3. Index-name-1 must correspond to a data description entry in the
hierarchy of the table being referenced which contains an INDEXED
BY phrase specifying that index-name. An index described for some
other table can be used instead, provided the two tables have
elements of the same size.
4. Each table element reference must be subscripted except when such
reference appears:
a. In a USE FOR DEBUGGING statement.
b. As the subject of a SEARCH or SORT statement.
c. In a REDEFINES clause.
d. In the KEY IS phrase of an OCCURS clause.
5. Data-name-2 can be qualified and must be a numeric elementary item
representing an integer.
6. Integer-1 can be signed, and if signed, it must be positive.
________________________________________________________________________
|(ANS85) |
| |
| |
| |
|7. The subscript ALL can be used only when the subscripted identifier|
| is used as a function argument and can not be used when |
| condition-name-1 is specified. (See the section "Arguments" |
| in the chapter Intrinsic Functions.) |
| |
________________________________________________________________________
________________________________________________________________________
|(OSVS) (ANS74) |
| |
| |
| |
|8. The mixing of subscripts and indices in the same identifier is |
| illegal. |
| |
________________________________________________________________________
General Rules
1. The value of the subscript must be a positive integer. The lowest
possible occurrence number represented by a subscript is 1. The
first element of any given dimension of a table is referenced by
an occcurrence number of 1. Each successive element within that
dimension of the table is referenced by occurrence numbers of 2,
3, ... . The highest permissible occurrence number for any given
dimension of the table is the maximum number of occurrences of the
item specified in the associated OCCURS clause.
________________________________________________________________________
|(MF) |
|If NOBOUND is specified, these General Rules are not applicable at |
|Run-Time. For a description of the BOUND and RDW directives, see your|
|COBOL System Reference. |
________________________________________________________________________
2. The value of the index referenced by index-name-1 corresponds to
the occurrence number of an element in the associated table.
3. The value of the index referenced by index-name-1 must be
initialized before it is used as a subscript. An index can be
given an initial value by either a PERFORM statement with the
VARYING phrase, a SEARCH statement with the ALL phrase, or a SET
statement. An index can be modified only by the PERFORM, SEARCH,
and SET statements.
4. (ANS85) If integer-2 or integer-3 is specified, the value of the
subscript is determined by incrementing by the value of integer-2
or integer-3 (when the operator + is used) or by decrementing by
the value of integer-2 or integer-3 (when the operator - is used)
either the occurrence number represented by the value of the index
referenced by index-name-1 or the value of the data item
referenced by data-name-2. (ANS85)
Indexing.
References can be made to individual elements within a table of like
elements by specifying indexing for that reference. An index is assigned
to that level of the table by using the INDEXED BY phrase in the
definition of a table. A name given in the INDEXED BY phrase is known as
an index-name and is used to refer to the assigned index. The value of
an index corresponds to the occurrence number of an element in the
associated table or any other table. An index-name must be initialized
before it is used as a table reference. An index-name can be given an
initial value by a SET statement.
Unlike a subscript, which is simply a numeric data item or literal, an
index is a special type of item that holds a representation of an
occurrence number. The form of this representation can vary; the
contents of an index cannot be regarded as a numeric value.
Direct indexing is specified by using an index-name in the form of a
subscript. Relative indexing is specified when the index-name is
followed by the operator "+" or "-", followed by an unsigned integer
numeric literal, all delimited by the balanced pair of separators left
parenthesis and right parenthesis following the table element data-name.
The occurrence number resulting from relative indexing is determined by
incrementing (where the operator "+" is used) or decrementing (where the
operator "-" is used), by the value of the literal, the occurrence number
represented by the value of the index. When more than one index-name is
required, they are written in the order of successively less inclusive
dimensions of the data organization.
A table can only be indexed by the index described in its INDEXED BY
phrase.
________________________________________________________________________
|(OSVS) (VSC2) |
|An index described for some other table can be used instead provided |
|the two tables have elements of the same size. |
________________________________________________________________________
At the time of execution of a statement which refers to an indexed table
element, the value contained in the index used to index it must neither
correspond to a value less than one nor to a value greater than the
highest permissible occurrence number of an element of the associated
table. This restriction also applies to the value resultant from
relative indexing.
________________________________________________________________________
|(MF) |
|If NOBOUND is specified, these rules are not applicable at Run-Time. |
|For a description of the BOUND and RDW directives, see your COBOL |
|System Reference. |
________________________________________________________________________
Up to 3 index-names can be used with a data-name.
________________________________________________________________________
|(ANS85) |
|Up to 7 index-names can be used with a data-name. |
________________________________________________________________________
________________________________________________________________________
|(MF) |
|Up to 16 index-names can be used with a data-name. |
________________________________________________________________________
The general format for indexing is included in the general format for
subscripting on page 2-48.
Function-Identifier.
________________________________________________________________________
|(ANS85) |
| |
|A function-identifier is a syntactically correct combination of |
|character strings and separators that uniquely references the data |
|item resulting from the evaluation of a function. |
| |
|General Format |
| |
| FUNCTION function-name-1 [({argument-1}...)] [reference-modifier]|
| |
|Syntax Rules |
| |
| |
| 1. Argument-1 must be an identifier, a literal, or an arithmetic |
| expression. Specific rules governing the number, class, and |
| category of argument-1 are given in the definition of each |
| function. (See Chapter 4 Intrinsic Functions.) |
| |
| 2. A reference modifier can be specified only for functions of the|
| category alphanumeric. |
| |
| 3. A function-identifier which references an alphanumeric function|
| can be specified anywhere in the general formats that an |
| identifier is permitted and where the rules associated with the|
| general formats do not specifically prohibit reference to |
| functions, except as follows: |
| |
| |
| a. As a receiving operand of any statement. |
| |
| b. Where the rules associated with the general formats |
| require the data item being referenced to have |
| particular characteristics (such as class and category, |
| usage, size, sign, and permissable values) and the |
| evaluation of the function according to its definition |
| and the particular arguments specified would not have |
| these characteristics. |
| [REV BEG] |
| |
| 4. A function-identifier which references an integer or numeric |
| function can be used only in an arithmetic expression, or as |
| the source of a MOVE statement. (MF)[REV END] |
| |
|General Rules |
| |
| |
| 1. The class and other characteristics of the function being |
| referenced are determined by the function definition. |
| |
| 2. At the time reference is made to a function, its arguments are |
| evaluated individually in the order specified in the list |
| of arguments, from left to right. An argument being |
| evaluated can itself be a function-identifier or can be an |
| expression containing function-identifiers. There is no |
| restriction preventing the function referenced in evaluating an|
| argument from being the same function as that for which the |
| argument is specified. In other words, recursion is |
| permitted. |
| [REV BEG] |
| |
| In this case, if the evaluation involves floating-point, |
| the operands will be rounded to the nearest integer; |
| otherwise, they will be truncated to integer-part. (MF)[REV |
| END] |
________________________________________________________________________
________________________________________________________________________
|Reference Modification |
| |
|(ANS85) |
| |
|Reference modification defines a data item by specifying a leftmost |
|character and length for the data item. Unless otherwise specified, |
|it is allowed anywhere an identifier referencing an alphanumeric data |
|item is permitted. |
| |
|The general format for reference modification is: |
| |
| {data-name-1 } |
| {FUNCTION function-name-1 [({argument-1}...)]} |
| |
| (leftmost-character-position:[length]) |
| |
| |
| |
|Note: Data-name-1 and FUNCTION function-name-1 (argument-1) are |
| shown in the above format to provide context and are not part|
| of the reference-modifier. |
| |
| |
|where: |
| |
| |
| 1. Data-name-1 must reference a data item whose usage is |
| DISPLAY. |
| |
| 2. Leftmost-character-position and length must be arithmetic |
| expressions. |
| |
| 3. Unless otherwise specified, reference modification is allowed |
| anywhere an identifier referencing a data item of the class |
| alphanumeric is permitted. |
| |
| 4. Data-name-1 can be qualified and/or subscripted. |
| |
| 5. The function referenced by function-name-1 and its arguments, |
| if any, must be an alphanumeric function. |
________________________________________________________________________
________________________________________________________________________
|(ANS85) |
| |
|The rules for reference modification are as follows: |
| |
| |
| 1. Each character of a data item referenced by data-name-1 or by |
| function-name-1 and its arguments, if any, is assigned an |
| ordinal number incrementing by one from the leftmost position |
| to the rightmost position. The leftmost position is assigned |
| the ordinal number one. If the data description entry for |
| data-name contains a SIGN IS SEPARATE clause, the sign |
| position is assigned an ordinal number within that data |
| item. |
| |
| 2. If the data item referenced by data-name-1 is described as |
| numeric, numeric edited, alphabetic, or alphanumeric |
| edited, it is operated upon for purposes of reference |
| modification as if it were redefined as an alphanumeric data |
| item of the same size as the data item referenced by |
| data-name. |
| |
| 3. Reference modification for an operand is evaluated as |
| follows: |
| |
| |
| a. If subscripting is specified for the operand, the |
| reference modification is evaluated immediately after |
| evaluation of the subscripts. If an ALL subscript is |
| specified for an operand, the reference-modifier is |
| applied to each of the implicitly specified elements of |
| the table. |
| |
| b. If subscripting is not specified for the operand, the |
| reference modification is evaluated at the time |
| subscripting would have been evaluated if subscripts had|
| been specified. |
| |
| c. If reference modification is specified in a function |
| reference, the reference modification is evaluated |
| immediately after evaluation of the function. |
| |
| 4. Reference modification creates a unique data item that is a |
| subset of the data item referenced by data-name-1 or by |
| function-name-1 and its arguments, if any. This unique data |
| item is defined as follows: |
| |
| |
| a. The evaluation of leftmost-character-position |
| specifies the ordinal position of the leftmost |
| character of the unique data item in relation to the |
| leftmost character of the data item referenced by |
| data-name-1 and its arguments, if any. Evaluation of |
| leftmost-character-position must result in a positive |
| nonzero integer less than or equal to the number of |
| characters in the data item referenced by data-name-1 |
| and its arguments, if any: |
| |
| The results are rounded if the expression is in |
| floating-point, and truncated if the expression is in |
| fixed-point. (MF) (VSC2) |
| [REV BEG] |
| |
| Evaluation of leftmost-character-position may result in |
| a positive non-integer value, greater than one, in which|
| case the value is truncated to be integer-part. |
| (MF)[REV END] |
________________________________________________________________________
________________________________________________________________________
|(ANS85) |
| |
| |
| |
| b. The evaluation of length specifies the size in bytes of |
| the data item to be used in the operation. The evaluation |
| of length must result in a positive nonzero integer. The |
| sum of leftmost-character-position and length minus |
| the value one, must be less than, or equal to, the |
| number of characters in the data item referenced by |
| data-name-1 or by function-name-1 and its arguments, if |
| any. If length is not specified, the unique data item |
| extends from and includes the character identified by |
| leftmost-character-position, up to and including the |
| rightmost character of the data item referenced by |
| data-name-1 or by function-name-1 and its arguments, if |
| any: |
| |
| The results are rounded if the expression is in |
| floating-point, and truncated if the expression is in |
| fixed-point. (MF) (VSC2) |
| |
| |
|5. The unique data item is considered an elementary data item |
| without the JUSTIFIED clause. When a function is referenced, the|
| unique data item has the class and category of alphanumeric. |
| When data-name-1 is specified, the unique data item has |
| the same class and category as that defined for the data |
| item referenced by data-name except that the categories |
| numeric, numeric edited, alphanumeric edited and external |
| floating-point (MF) (VSC2) (OSVS) are considered class and |
| category alphanumeric. |
| |
|6. If the OSVS system directive is set, reference modification |
| cannot be used in conditional expressions (see the chapter The |
| Nucleus for a description of conditional expressions). |
| (OSVS) |
| |
________________________________________________________________________
Identifier.
An identifier is a syntactically correct sequence of character-strings
and separators used to reference data uniquely.
When a data item other than a function is being referenced, identifier is
a term used to reflect that a data-name, if not unique in a program, must
be followed by a syntactically correct combination of qualifiers,
subscripts, or reference-modifiers necessary for uniqueness of reference.
Format 1
________________________________________________________________________
|(ANS85) |
| |
| function-identifier-1 |
________________________________________________________________________
Format 2
Where subscript represents either subscripting (see "Subscripting"
earlier in this section) or indexing (see "Indexing" earlier in this
section).
Rules on subscripting and indexing are:
1. The words IN and OF are equivalent.
2. A data-name must not itself be subscripted nor indexed when that
data-name is being used as an index, or subscript.
3. Indexing is not permitted where subscripting is not permitted.
4. An index can be modified only by the SET, SEARCH, and PERFORM
statements. Data items described by the USAGE IS INDEX clause
permit storage of the values associated with index-names as data.
The form in which these values are stored is dependent on
system-dependent factors. See your COBOL System Reference for
details. Such data items are called index data items.
5. Literals used as subscripts must be positive numeric integers.
Literals used for relative subscripting and indexing must be
unsigned numeric integers.
Condition-Name.
Each condition-name must be unique, or be made unique through
qualification and/or indexing, or subscripting. If qualification is used
to make a condition-name unique, the associated conditional variable can
be used as the first qualifier. If qualification is used, the hierarchy
of names associated with the conditional variable or the conditional
variable itself must be used to make the condition-name unique.
If references to a conditional variable require indexing or subscripting,
then references to any of its condition-names also require the same
combination of indexing or subscripting.
The format and restrictions on the combined use of qualification,
subscripting, and indexing of condition-names are exactly those of
"identifier" except that data-name-1 is replaced by condition-name-1.
In the general formats, "condition-name" refers to a condition-name
qualified, indexed or subscripted, as necessary.
Explicit and Implicit Specifications
There are four types of explicit and implicit specifications that occur
in COBOL source programs:
1. Explicit and implicit Procedure Division references.
2. Explicit and implicit transfers of control.
3. Explicit and implicit attributes.
________________________________________________________________________
|(ANS85) |
| |
| |
| |
|4. Explicit and implicit scope terminators. |
| |
________________________________________________________________________
Explicit and Implicit Procedure Division References.
A COBOL source program can reference data items either explicitly or
implicitly in Procedure Division statements. An explicit reference
occurs when the name of the referenced item is written in a Procedure
Division statement or when the name of the referenced item is copied into
the Procedure Division by the processing of a COPY statement. An
implicit reference occurs when the item is referenced by a Procedure
Division statement without the name of the referenced item being written
in the source statement.
An implicit reference also occurs, during the execution of a PERFORM
statement, when the index or data item referenced by the index-name or
identifier specified in the VARYING, AFTER or UNTIL phrase is
initialized, modified, or evaluated by the control mechanism associated
with that PERFORM statement. Such an implicit reference occurs if and
only if the data item contributes to the execution of the statement.
Explicit and Implicit Transfers of Control.
The mechanism that controls program flow transfers control:
1. From sentence to sentence in the sequence in which they are
written in the source program unless an explicit transfer of
control overrides this sequence or there is no next executable
sentence to which control can be passed; and
2. From statement to statement in the sequence in which they are
written in the source program unless an explicit transfer of
control overrides this sequence or there is no next executable
statement to which control can be passed.
The transfer of control from sentence to sentence and from statement to
statement within a sentence occurs without the writing of an explicit
Procedure Division statement and, therefore, is an implicit transfer of
control.
COBOL provides both explicit and implicit means of altering the implicit
control transfer mechanism.
In addition to the implicit transfer of control between consecutive
sentences and between consecutive statements, implicit transfer of
control also occurs when the normal flow is altered without the execution
of a procedure branching statement. COBOL provides the following
types of implicit control flow alterations which override the
statement-to-statement transfers of control:
1. If a paragraph is being executed under control of another COBOL
statement (for example, PERFORM, USE, SORT and MERGE) and the
paragraph is the last paragraph in the range of the controlling
statement, then an implied transfer of control occurs from the
last statement in the paragraph to the control mechanism of the
last executed controlling statement. Further, if a paragraph is
being executed under the control of a PERFORM statement which
causes iterative execution and that paragraph is the first
paragraph in the range of that PERFORM statement, an implicit
transfer of control occurs between the control mechanism
associated with that PERFORM statement and the first statement in
that paragraph for each iterative execution of the paragraph.
2. When a SORT or MERGE statement is executed, an implicit transfer
of control occurs to any associated input or output procedures.
3. When any COBOL statement is executed which results in the
execution of a declarative section, an implicit transfer of
control to the declarative section occurs. Note that another
implicit transfer of control occurs after execution of the
declarative section, as described in item 1. above.
________________________________________________________________________
|(MF) |
| |
| |
| |
|4. In any file operation (including OPEN and CLOSE), if a file does |
| not have a FILE STATUS data item declared for it and the file is |
| not explicitly covered by a USE statement, then it is covered by |
| an implicit USE statement. The implied USE procedure is |
| equivalent to: |
| |
| USE AFTER ERROR PROCEDURE ON file-name |
| IF status-key-1 > 3 |
| DISPLAY error-message UPON CONSOLE |
| STOP RUN. |
| |
| See your Error Messages for the definition of error-message. |
| |
________________________________________________________________________
An explicit transfer of control consists of an alteration of the implicit
control transfer mechanism by the execution of a procedure branching or
conditional statement. An explicit transfer of control between
statements can be caused only by the execution of a procedure branching
or conditional statement. An explicit transfer of control between
sentences can be caused only by the execution of the NEXT SENTENCE phrase
of an IF or SEARCH statement. The execution of the procedure branching
statement ALTER does not in itself constitute an explicit transfer of
control, but affects the explicit transfer of control that occurs when
the associated GO TO statement is executed. The procedure branching
statement EXIT PROGRAM causes an explicit transfer of control when the
statement is executed in a called program.
The term "next executable sentence" is used to refer to the next COBOL
sentence to which control is implicitly transferred according to the
rules above or explicitly transferred as a result of execution of the
NEXT SENTENCE phrase. The next executable sentence is the first sentence
following the separator period that terminates the current sentence.
There is no next executable sentence when there is no next executable
statement as described below.
The term "next executable statement" is used to refer to the next COBOL
statement to which control is transferred according to the rules above
and the rules associated with each language element in the Procedure
Division.
There is no next executable statement following:
1. The last statement in a declarative section when the paragraph in
which it appears is not being executed under the control of some
other COBOL statement.
2. The last statement in a program when the paragraph in which it
appears is not being executed under the control of some other
COBOL statement.
[REV BEG]
3. The last statement in a declarative section, when the statement is
in the range of an active PERFORM statement executed in a
different section, and this last statement of the declarative
section is not also the last statement of the procedure that is
the exit of the active PERFORM statement.
4. A STOP RUN statement or EXIT PROGRAM statement that transfers
control outside the COBOL program.
5. The end program header.[REV END]
Explicit and Implicit Attributes.
Attributes can be implicitly or explicitly specified. Any attribute
which has been explicitly specified is called an explicit attribute. If
an attribute has not been specified explicitly, then the attribute takes
on the default specification. Such an attribute is known as an implicit
attribute.
For example, the usage of a data item need not be specified, in which
case a data item's usage is DISPLAY.
Explicit and Implicit Scope Terminators.
________________________________________________________________________
|(ANS85) |
|Scope terminators delimit the scope of certain Procedure Division |
|statements (delimited scope statements), and are of two types: |
|explicit and implicit. |
| |
|The explicit scope terminators are listed below. Note that in some |
|cases the delimited scope statement with which an explicit scope |
|delimitor is paired, is determined differently for different COBOL |
|language specifications. |
| |
|The following is the list of valid explicit scope terminators: |
| |
| |
|END-ADD END-PERFORM |
|END-ACCEPT (MF) (XOPEN) END-READ |
|END-CALL END-RECEIVE[REV BEG] |
|END-CHAIN END-RETURN[REV END] |
|END-COMPUTE END-REWRITE |
|END-DELETE END-SEARCH |
|END-DISPLAY (MF) (XOPEN) END-START |
|END-DIVIDE END-STRING |
|END-EVALUATE END-SUBTRACT |
|END-IF END-UNSTRING |
|END-MULTIPLY END-WRITE |
| |
| |
|Implicit scope termination occurs: |
| |
| |
| 1. At the end of any sentence, where the separator period |
| terminates the scope of all previous statements not yet |
| terminated. |
| |
| 2. Within any statement containing another statement, the |
| next phrase of the containing statement (for example, |
| ELSE, WHEN, AT END, and so on) following the contained |
| statement terminates the scope of any unterminated contained |
| statement. |
________________________________________________________________________
MPE/iX 5.0 Documentation