Concepts of Classes of Data (Continued) [ Micro Focus COBOL Language Reference ] MPE/iX 5.0 Documentation
Micro Focus COBOL Language Reference
Concepts of Classes of Data (Continued)
COMPUTATIONAL-1, COMPUTATIONAL-2, Format (MF, OSVS, VSC2 only)
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 cannot 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 cannot 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 encoded:
1. the exponent - the power of 10 to which the specific numeric value
is multiplied.
2. the exponent sign - an indication of whether the specific numeric
value (mantissa) is multiplied by a "whole" number in the series,
1, 10, 100, and so on, or by a fractional number in the series
1/10, 1/100, 1/1000, and so on.
3. the mantissa - the specific value, which when multiplied by a
power of 10 provides the numeric value of the data item.
4. 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 refered to as
single precision floating-point items while items that are USAGE
COMPUTATIONAL- (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.
COMPUTATIONAL-1 and COMPUTATIONAL-2 are equivalent to Single Format and
Double Format, respectively, for operating systems that conform t
ANSI/IEEE Std 754-1985, IEEE Standard for Binary Floating-Point
Arithmetic.
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:
Internal (Hexadecimal) Decimal Value
Storage (Scientific Notation)
---------------------------------------------------------------------------------------
x"AD17E148" -0.12345673E-23
x"AD17E149" -0.12345810E-23
Therefore, any application which tested for or expected an internal
floating-point item with an exact decimal value of -0.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) cannot 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 reserves 4 bytes
of storage for the item; USAGE COMPUTATIONAL-2 reserves 8 bytes of
storage.
For MF only: When the IBMCOMP system directive 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.
For MF, OSVS, VSC2 and XOPEN only: COMPUTATIONAL-3 or PACKED-DECIMAL
(ANS85) Format
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.
For MF only: Any unused half bytes will be set to zero.
Table 2-6: COMPUTATIONAL-3 Digit Representation
----------------------------------------------------------------
| | |
| | Digit Representation in Hexadecimal |
| | |
| Digit Value | |
| | |
----------------------------------------------------------------
| | | |
| | 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.
For MF, OSVS and VSC2 only: 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.
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), 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 |
| | |
-----------------------------------------------------------
For OSVS, VSC2, MF and XOPEN only: Example:.
a. For COMPUTATIONAL-3 and PICTURE 9999, the number + 1234 would be
stored as follows:
| 1 byte | 1 byte | 1 byte
| | |
... | 0 1 | 2 3 | 4 F
| | |
| 0000 0001 | 0010 0011 | 0100 1111
| | |
where F represents the non-printing plus sign.
b. For COMPUTATIONAL-3 and PICTURE 9999, the number + 1234 would be
stored as follows:
| 1 byte | 1 byte | 1 byte
| | |
... | 0 1 | 2 3 | 4 C
| | |
| 0000 0001 | 0010 0011 | 0100 1110
| | |
where C represents the plus sign.
c. For COMPUTATIONAL-3 and PICTURE 9999, the number + 1234 would be
stored as follows:
| 1 byte | 1 byte | 1 byte
| | |
... | 0 1 | 2 3 | 4 D
| | |
| 0000 0001 | 0010 0011 | 0100 1101
| | |
where D represents the minus sign.
The SYNCHRONIZED clause (with or without the LEFT or RIGHT phrase) has no
effect on COMPUTATIONAL-3 data declarations.
For MF only: COMPUTATIONAL-X, COMPUTATIONAL-5 Format
These formats are as for COMPUTATIONAL format. Except the differences
geven below. See the section COMPUTATIONAL, BINARY, COMPUTATIONAL-4
Format earlier in this chapter.
They both differs in the following ways from the COMPUTATIONAL format:
* 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.
* 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).
* 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.
* The following are the only differences between COMPUTATIONAL-X and
COMPUTATIONAL-5 formats:
* A COMPUTATIONAL-5data item can be signed; a
COMPUTATIONAL-Xdata 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.
* 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 in the same format as COMPUTATION-X items and in
others they 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 PIC X(5) COMPUTATIONAL-5 item with a
hexadecimal value of:
h "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
* A COMPUTATIONAL-5 item is affected by the IBMCOMP system
directive; a COMPUTATIONAL-X item is not.
* If a non-arithmetic statement attempts to store a negative value
in a COMPUTATIONAL-X item or unsigned COMPUTATIONAL-5 item, the
value is stored in two's complement, as if the item had been
signed.
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.
For MF and VSC2 only: POINTER Format
The POINTER format holds a value that represents the memory address of an
available data item. If the data item becomes unavailable (for example,
because it is in a program that has been canceled) then the POINTER
format is considered to hold a value that is incompatible with the
format.
The default amount of stoarage allocated for the POINTER format may vary
depending on the operating environment but will be at least four bytes.
Your COBOL System Reference will detail if the default is other than four
bytes. The method of representation of the memory address varies between
environments and will in general be consisten with the representation
used in non-COBOl languages. Check with your COBOL System Reference for
any details.
For MF and COB/370 only: PROCEDURE-POINTER Format
The PROCEDURE-POINTER format holds a value that represents the memory
address of an available procedure. If the procedure becomes unavailable
(for example, because it is in a program that has been canceled) then the
PROCEDURE-POINTER format is considered to hold a value that is
incompatible with the format.
The default amount of storage allocated for the PROCEDURE-POINTER format
may vary depending on the operating environment but will be at least four
bytes. Your COBOL System Reference will detail if the default is other
than four bytes. If the COBOL370 directive is specified, then eight
bytes of storage are allocated. The method of representation of the
memory address varies between environments and will in general be
consisten with the representation used in non-COBOL languages. Check
with your COBOL System Reference for any details.
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.
For ANS85 only: 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.
Format 4 (MF)(XOPEN).
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 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.
For ANS85 only: 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 when it does not need qualification;
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.
For ANS85 only: 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.
For MF, VSC2 and OSVS only: This restriction is not enforced.
MPE/iX 5.0 Documentation