Concepts of Classes of Data (Cont.) [ Micro Focus COBOL Language Reference ] MPE/iX 5.0 Documentation
Micro Focus COBOL Language Reference
Concepts of Classes of Data (Cont.)
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 section The OCCURS Clause in the
chapter Program Definition).
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, 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.
For ANS85 only: Up to 7 subscripts are permitted
For MF only: Up to 16 subscripts are permitted.
General Format.
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 7, 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. For ANS85 only: The subscript ALLcan be used only when the
subscripted identifier is used as a function argument and cannot
be used when condition-name-1 is specified. (See the section
Arguments in the chapter Program Definition.)
4. Integer-1 can be signed, and if signed, must be positive.
5. Data-name-2 can be qualified and must be a numeric elementary item
representing an integer.
6. 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.
7. Each table element reference must be subscriptedexcept 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.
8. For OSVS and ANS74 only: The mixing of subscripts and indices in
the same identifier is illegal.
General Rules.
For MF only: If NOBOUND system directive is specified, these General
Rules are not applicable at run time. For a description of the BOUND
directive, see your COBOL System Reference.
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.
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. If integer-2 (ANS85) or integer-3 is specified, the value of the
subscript is determined by incrementing by the value of
integer-2(ANS85) or integer-3 (when the operator "+" is used) or
by decrementing by the value of integer-2 (ANS85) or integer-3
(when the operator "-" is used), either (ANS85) 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 and 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 be indexed only by the index described in its INDEXED BY
phrase.
For OSVS and VSC2 only: 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 resulting from
relative indexing.
For MF only: If NOBOUND is specified, this rule is not applicable at run
time. For a description of the BOUND directive, see your COBOL System
Reference. Up to 3 index-names can be used with a data-name.
For ANS85 only: Up to 7 index-names can be used with a data-name.
For MF only: 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 earlier in this chapter.
For ANS85 only: Function-identifier
A function-identifieris 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 the section Intrinsic Functions in the chapter
Program Definition.)
2. A reference modifier can be specified only for functions of the
category alphanumeric.
3. A function-identifier that 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:
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.
4. A function-identifier that references an integer or numeric
functioncan be used only in an arithmetic expression , or as the
source of a MOVE statement (MF) .
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.
For MF only: If a function is expecting an interger argument,
then if a floating-point arguement is provided, the value will be
rounded to the nearest integer, otherwise andy franctional part
will be truncated.
For ANS85 only: Reference Modification
Reference modificationdefines a data item by specifying a leftmost
character and length for the data item. Unless otherwise specified, it
is allowed anywhere an identifierreferencing an alphanumeric data item is
permitted.
General Format.
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.
Syntax Rules.
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.
General Rules.
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, external floating-point (MF, VSC2 and OSVS only) numeric
edited, alphabetic, or alphanumeric edited, it is operated upon
for purposes of reference modificationas 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 subscriptis specified for an
operand, the reference-modifieris 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 or
function-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 or by
function-name-1 and its arguments, if any:
For MF and VSC2 only: The results are rounded if the
expression is in floating-point, and truncated if the
expression is in fixed-point.
For MF only: 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.
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.
For MF and VSC2 only: The results are rounded if the
expression is in floating-point, and truncated if the
expression is in fixed-point.
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 and
OSVS) are considered class and category alphanumeric.
6. For OSVS only: If the OSVS system directiveis set, reference
modificationcannot be used in conditional expressions (see the
chapter Program Definition for a description of conditional
expressions).
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-modifiersnecessary for uniqueness of reference.
General Formats.
Format 1 (ANS85 only).
Format 2.
Where subscript represents either subscripting (see the section
Subscripting earlier in this section) or indexing (see the section
Indexing earlier in this section).
Rules on subscripting and indexing are:
1. The words IN and OF are equivalent.
2. A data-name must neither be subscripted nor indexed when it 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 system-dependent.
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.
MPE/iX 5.0 Documentation