Data Description Entries (continued) [ HP COBOL II/XL Reference Manual ] MPE/iX 5.0 Documentation
HP COBOL II/XL Reference Manual
Data Description Entries (continued)
SIGN Clause
The SIGN clause is only used with a signed numeric data description item
or description entry whose usage is DISPLAY, or a group item containing
at least one such data description entry.
It states the position of the sign, whether leading or trailing, as well
as whether the sign was formed by overpunching in the first or last
character of the data item (see the USAGE IS DISPLAY clause, below) or
was formed separately.
Syntax.
Parameters.
LEADING and indicates that the sign is at the beginning or end,
TRAILING respectively, of the item.
SEPARATE indicates that the sign is not overpunched; that is, the
sign exclusively occupies the first or last character of
this item.
Description.
Only one sign clause may be used per given numeric data description
entry.
Also, if the CODE-SET clause is specified in a file description, any
signed numeric data description entry associated with that file must be
described with the SIGN IS SEPARATE clause.
Valid signs for data items, and their representations when overpunching
is used, are shown in the table under the USAGE IS DISPLAY heading on the
following pages.
For a SIGN IS SEPARATE designation, the two valid operational signs
(whether LEADING or TRAILING) are + or - for positive and negative
quantities, respectively.
For a signed numeric data description entry having no SIGN clause
associated with it, the default is equivalent to SIGN IS TRAILING. That
is, the sign is assumed to be overpunched in the last character of the
item.
In either the default case, or the case when the optional SEPARATE
CHARACTER phrase is not used, the letter "S" in the PICTURE CLAUSE is not
counted in determining the size of the item when represented in standard
data format. To illustrate the SIGN clause:
* The data to be entered is 123489F
In this case, no SIGN clause is required because the default is
SIGN IS TRAILING. However, if the PICTURE clause for this data
item is PICTURE S9(7), the size of the data item is seven
characters.
* The data to be entered is +1409748
In this case, the SIGN clause should be: SIGN IS LEADING SEPARATE
CHARACTER
Also, since the sign is separate, the PICTURE clause for this data
item, PICTURE S9(7) defines the data item to be eight characters
long in order to hold the separate sign.
SYNCHRONIZED Clause
The SYNCHRONIZED clause is used to align items defined as USAGE IS
COMPUTATIONAL or BINARY on word boundaries in order to facilitate
arithmetic operations. A word size is defined by the operating[REV BEG]
system environment (a word is 32 bits on MPE XL).[REV END]
All other items are aligned on byte boundaries. Because the character
(byte) is the smallest directly addressable unit within the COBOL
language, the SYNCHRONIZED clause has no meaning when applied to an item
with any usage other than COMPUTATIONAL. It is treated as a comment for
items described as DISPLAY, INDEX, COMPUTATIONAL-3, or PACKED-DECIMAL.
Syntax.
Description.
Because of the word structure used on HP computers, the LEFT and RIGHT
options are irrelevant and are treated as comments by the compiler.
The words SYNCHRONIZED and SYNC are equivalent.
The compiler always aligns all level 01 and level 77 items on word
boundaries[REV BEG] except in the LINKAGE section (see the section
"OPTFEATURES" in Appendix G for details).[REV END]
When the SYNCHRONIZED clause is specified for a data item whose
description also contains an OCCURS clause, or in a data description
entry of a data item subordinate to a description entry containing an
OCCURS clause, each occurrence of the data item is synchronized. Any
implicit filler (see "Slack Bytes", below) generated for other data items
within that same table are generated for each occurrence of those data
items.
Slack Bytes.
The SYNCHRONIZED clause specifies that the data described is to be
aligned on word boundaries. If the SYNCHRONIZED item does not fall
naturally on a word boundary, the compiler assigns the next highest
boundary address to the item.
The effect of adding a byte (or bytes) is equivalent to providing extra
FILLER characters, known as slack bytes, just before the SYNCHRONIZED
item.
These slack bytes are not used for any other data item and are not
counted in the size of the items. They are, however, included in the
size of any group item or items to which the elementary item belongs, and
are included in the character positions redefined when the SYNCHRONIZED
item is the object of a REDEFINES clause. Therefore, when you use the
REDEFINES clause in a data description that also contains a SYNCHRONIZED
clause, you must ensure that the redefined item has the proper boundary
alignment for the item that redefines it.
The computation of boundary addresses is affected by the $CONTROL SYNC
option. This option changes the alignment of SYNCHRONIZED data items,
which affects the number of slack bytes generated in a record. Items
with the SYNC clause are aligned along 16-bit (2 characters) boundaries,
if SYNC16 is in effect. Items with the SYNC clause are aligned along
32-bit (4 character) boundaries, if SYNC32 is in effect. (Refer to the
description of DATA DIVISION language dependencies and $CONTROL
SYNC16/SYNC32 in "MPE XL System Dependencies" in Appendix H for
synchronization alignment specifics.) This option may be coded more than
once in a program to align one record along 16-bit boundaries, and
another record along 32-bit boundaries. Alignment cannot be changed
within a record, only between records.
This option is especially useful to develop files to be used on
other computer architectures, or to read files developed on other
architectures.
Whenever a SYNCHRONIZED item is referenced in your program, the original
size of the item, as shown in the PICTURE clause, is used in determining
any action that depends on size. Such actions include justification,
truncation, or overflow.
If the SYNCHRONIZED clause is not used, no space is reserved for slack
bytes, and when a computation is performed on a data item described as
COMPUTATIONAL, the compiler provides the code and space required to move
the data item from its storage area to a work area. This work area has
the alignment required to perform the computation.
As an illustration of slack bytes (assuming 16-bit synchronization),
consider the following data description entries:
01 ITEM-LIST.
02 ITEM-NUMBER PICTURE X(3).
02 ITEM-1 PICTURE X(4).
02 ITEM-2 REDEFINES ITEM-1 PICTURE S9(6) USAGE COMP SYNC.
The above is an example of not taking into account the slack byte
required because of the REDEFINES clause. To correct it, the description
of ITEM-LIST should include an extra byte prior to ITEM-1:
01 ITEM-LIST.
02 ITEM-NUMBER PICTURE X(3).
02 SLACK-BYTE PICTURE X.
02 ITEM-1 PICTURE X(4).
02 ITEM-2 REDEFINES ITEM-1 PICTURE S9(6) USAGE COMP SYNC.
This change is all that was needed, since all 01 level entries are
aligned on word boundaries[REV BEG] except in the LINKAGE section (see
the section "OPTFEATURES" in Appendix H for details).[REV END]
Example.
The following illustrates the use of $CONTROL SYNC:
$CONTROL SYNC32
01 OUT-REC.
05 A PIC X.
05 B PIC S9999 BINARY SYNC.
05 C PIC X.
$CONTROL SYNC16
01 IN-REC.
05 A PIC X.
05 B PIC S9999 BINARY SYNC.
05 C PIC X.
In the above example, three slack bytes are inserted before B of OUT-REC.
One slack byte is inserted before B of IN-REC.
NOTE [REV BEG]
Due to the $CONTROL SYNC option,[REV END] boundary alignment within
a record is constant. It only changes between records.
USAGE Clause
The USAGE clause specifies how the data item being described is stored
internally. When used with index, the USAGE clause specifies that the
data item being described contains a value equal to the value of an index
name associated with an occurrence number for a table element.
Syntax.
Parameters.
PACKED-DECIMAL, equivalent; they specify packed-decimal format.
COMPUTATIONAL-3,
and COMP-3 The words COMPUTATIONAL-3 and COMP-3 are an HP
extension to the 1985 ANSI COBOL standard.
BINARY, equivalent; they specify two's complement binary
COMPUTATIONAL, and integer format.
COMP
DISPLAY the default usage if no USAGE clause is specified.
It specifies that data is to be stored internally as
ASCII characters.
INDEX specifies an index data item.
Description.
This clause is optional, with a USAGE IS DISPLAY being used by your
program for any data item having no USAGE clause as part of its
description, or as part of the description of a data item to which it is
subordinate.
You may use the USAGE clause at any level of organization. However, if
written at a group level, the USAGE clause applies to each elementary
item in the group, and any USAGE clause specified at the elementary level
must be the same as at the group level.
Although a USAGE clause does not affect the use of a data item, some of
the statements in the PROCEDURE DIVISION may restrict the USAGE clause of
the operands used.
USAGE IS DISPLAY.
When usage of a data item is defined (implicitly or explicitly) as
DISPLAY, the data is stored internally as ASCII characters.
This means that each character of data is stored as an 8-bit byte.
If you are using the data item in a noncomputational manner (that is,
printing or displaying it), this is the appropriate type of usage to be
specified.
However, for optimum use of your COBOL program, you should specify USAGE
IS COMPUTATIONAL, or BINARY, COMPUTATIONAL-3, or PACKED-DECIMAL for
data items intended for use in computations. This is because data items
described as USAGE IS DISPLAY must be converted to two's-complement
binary or packed-decimal format before they can be used in computations,
and this conversion takes time. Also, if you intend to use signed
numeric data items for computational purposes, you must specify a sign
(by using the S symbol) in the PICTURE clause for that item (see USAGE IS
COMPUTATIONAL on the following page), whether its usage is specified as
DISPLAY or otherwise.
An unsigned numeric data item whose description specifies the USAGE IS
DISPLAY clause is assumed to be positive.
Numeric DISPLAY items without a clause that designates SIGN IS SEPARATE
are represented in ASCII coded (8-bit) decimal digits (0 through 9)
except for the units digit which carries the sign of the data item. The
units digit, with the sign of its associated number being positive,
negative, or no sign (absolute value) respectively, is represented in
ASCII code as shown in Table 7-7 .
Note that using signed numeric DISPLAY data items for computational
purposes is more efficient than using unsigned numeric data items.
Table 7-7. Overpunch Characters for Rightmost Digit in ASCII Coded Decimal Numbers
---------------------------------------------------------
- Units Digit - Internal Representation (ASCII) -
---------------------------------------------------------
- - Positive - Negative - No Sign -
---------------------------------------------------------
- 0 - { - } - 0 -
---------------------------------------------------------
- 1 - A - J - 1 -
---------------------------------------------------------
- 2 - B - K - 2 -
---------------------------------------------------------
- 3 - C - L - 3 -
---------------------------------------------------------
- 4 - D - M - 4 -
---------------------------------------------------------
- 5 - E - N - 5 -
---------------------------------------------------------
- 6 - F - O - 6 -
---------------------------------------------------------
- 7 - G - P - 7 -
---------------------------------------------------------
- 8 - H - Q - 8 -
---------------------------------------------------------
- 9 - I - R - 9 -
---------------------------------------------------------
Signed decimal fields entered through punched cards are known as
zone-signed fields. To represent a positive value, an overpunch is
placed in the 12-zone above the rightmost digit of the field. To
represent a negative value, an overpunch is placed in the 11-zone above
the rightmost digit of the field. If no sign is desired, only the digits
need be punched.
Zone signs cause the signed digit to have the same punch configuration as
certain other characters. This is the purpose of the S symbol in the
PICTURE clause; it informs the compiler that the last digit in the field
is to be interpreted as a number and a sign, and not as the character
that it would otherwise represent. Table 7-7 shows the data
character equivalents to each possible rightmost digit sharing a zone
sign.
USAGE IS BINARY or COMPUTATIONAL.
When usage of a data item is defined as BINARY or COMPUTATIONAL, the
data must be numeric. It is stored in two's-complement binary integer
form, consisting of either two, four, or eight bytes each. The number of
bytes used depends upon the size of the data item, as shown in Table 7-8
below.
Table 7-8. Number of Bytes Used to Contain a BINARY Data Item
---------------------------------------------------------------------------------------------
- PICTURE - Number of Bytes -
---------------------------------------------------------------------------------------------
- S9 to S9(4) - 2 -
- S9(5) to S9(9) - 4 -
- S9(9) to S9(18) - 8 -
---------------------------------------------------------------------------------------------
A data item whose usage is defined as BINARY or COMPUTATIONAL must have
an unedited numeric PICTURE clause associated with it. It may contain up
to 18 digits plus a sign. Also, if a group item is described as BINARY
or COMPUTATIONAL, all of the elementary items in the group are
computational and may be used in computations. However, the group item
itself may not be used in computations because it is considered
alphanumeric. A numeric data item that does not have a sign associated
with it is assumed to be positive.
As with numeric DISPLAY data items, a signed numeric data item whose
USAGE IS BINARY is more efficient than an unsigned numeric data item
with the same USAGE.
USAGE IS PACKED-DECIMAL or COMPUTATIONAL-3.
Data items described as PACKED-DECIMAL or COMPUTATIONAL-3 are subject to
the same restrictions and are used in the same way as data items
described as COMPUTATIONAL. Such items are, however, stored in
packed-decimal format. In this format, there are two digits per byte,
with a sign in the low order 4-bits of the rightmost byte.
Each PACKED-DECIMAL or COMPUTATIONAL-3 item may contain up to 18 digits
plus a sign. If the picture for the item does not contain a sign, the
sign position in the data field is occupied by a bit configuration that
is interpreted as positive. Table 7-9 illustrates the bit
configurations used to represent signs in packed-decimal fields. Notice
that the bit configuration 1100 specifies a positive value and that the
4-bit configuration 1111 represents the unsigned (assumed positive) value
when an unsigned picture is specified. For negative values, the 4-bit
configuration is 1101.
Table 7-9. COMPUTATIONAL-3 or PACKED-DECIMAL Sign Configuration
----------------------------------------------------------------------------------------------
| | Bit | Hexadecimal |
| Sign | Configuration | Value |
----------------------------------------------------------------------------------------------
- + - 1100 - C -
----------------------------------------------------------------------------------------------
- - - 1101 - D -
----------------------------------------------------------------------------------------------
- Unsigned - 1111 - F -
----------------------------------------------------------------------------------------------
Table 7-10 gives a graphic illustration of packed-decimal fields as
they might appear in memory or in a file. Notice that these items follow
the normal rules for truncation, even though the field may include an
unused half-byte position. The contents of this half-byte are
unpredictable when data is interchanged with other computer systems. In
the table below, each box in the result column represents a byte.
Table 7-10. PACKED-DECIMAL Fields in Memory or in a File
-------------------------------------------------------------------------------------------------------
| Value to be | PICTURE of | Result |
| Stored | Result | |
-------------------------------------------------------------------------------------------------------
- +1234. - S9999 - - 01 - 23 - 4C -
-------------------------------------------------------------------------------------------------------
- +12345. - S99999 - - 12 - 34 - 5C -
-------------------------------------------------------------------------------------------------------
- 12345 - S9999 - - 12 - 34 - 5F -
-------------------------------------------------------------------------------------------------------
- -1.2 - S999V999 - 00 - 01 - 20 - 0D -
-------------------------------------------------------------------------------------------------------
- -.5 - S999V999 - 00 - 00 - 50 - 0D -
-------------------------------------------------------------------------------------------------------
- +1.22172 - S999V999 - 00 - 01 - 22 - 1C -
-------------------------------------------------------------------------------------------------------
- -12345. - 99999 - - 12 - 34 - 5F -
-------------------------------------------------------------------------------------------------------
Note that the third and last number in the table were stored as unsigned
(assumed positive) numbers because the receiving field is unsigned
according to its PICTURE.
USAGE IS INDEX.
An elementary data item whose usage is defined as INDEX is called an
index data item. Its purpose is to hold the contents of a table index
while the table is being processed. Therefore, any value within the
index data item must correspond to an occurrence number of an element in
a table. An index data item is stored as a synchronized unsigned
computational integer, both internally and externally. (Refer to "System
Dependencies" in Appendix H for the correct size of an index data
item.) An index data item cannot be a conditional variable, and can only
be referenced explicitly in a SEARCH or SET statement, a relation
condition, the USING phrase of the PROCEDURE DIVISION header, or USING
phrase of a CALL statement.
Do not use the SYNCHRONIZED, JUSTIFIED, PICTURE, VALUE, and BLANK WHEN
ZERO clauses to describe a group of elementary items whose usage is
defined as INDEX. Index data items are automatically SYNCHRONIZED.
In ANSI COBOL'85, if a group item is described with a USAGE IS INDEX
clause, all of its elementary items are index data items, but the group
itself is not an index data item and cannot be used in the SEARCH or SET
statements, or in an alphanumeric comparison in the PROCEDURE DIVISION.
As an HP extension to the ANSI COBOL standard, HP COBOL II allows a group
item described with USAGE IS INDEX to be used in an alphanumeric
comparison.
VALUE Clause
The VALUE clause is used to define the values of constants and to
initialize the values of WORKING-STORAGE data items. For information on
VALUE clauses in condition names, refer to "Condition Names" later in
this chapter.
Syntax.
[VALUE IS literal-1]
Parameters.
literal-1 the value assigned to the data item being described.
Description.
The above format for the VALUE clause can only be used in the
WORKING-STORAGE SECTION. If used, the VALUE clause causes the item to
which it is associated to assume the specified value at the start of the
object program, irrespective of any BLANK WHEN ZERO or JUSTIFIED clause.
If the VALUE clause is not used in an item's description, the initial
value of the item is undefined.
A VALUE clause may be used with data items (or descendants of data
items) containing an OCCURS clause to initialize tables.
A VALUE clause (VALUE is literal-1) 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 specific value.
If a VALUE clause is specified in a data description entry of a data
item that is associated with a variable occurrence data item, {{the
initialization of the data item behaves as if the value of the DEPENDING
ON phrase in the OCCURS clause is set to the maximum number of
occurrences specified by that OCCURS clause.
A data item is associated with a variable occurrence data item in any of
the following cases:
* When it is a group data item that contains a variable occurrence
data item.
* When it is a variable occurrence data item.
* When 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.
Restrictions on the Use of the VALUE Clause.
The following restrictions apply to the use of the VALUE clause. They
also apply to the VALUE clause in condition names.
* The VALUE clause cannot be used in a data description entry
containing a REDEFINES clause (except when used with a condition
name), or in an entry subordinate to an entry containing a
REDEFINES clause. Nor can it be used for a group containing items
with descriptions including JUSTIFIED, SYNCHRONIZED, or USAGE
(except USAGE IS DISPLAY).
* The VALUE clause must not conflict with any other clauses in the
data description of the item, or in the data description within
the hierarchy of the item.
* The VALUE clause must not be used with any external record, except
for condition-name entries associated with external records.
Literals in the VALUE Clause.
The literals used in the VALUE clause are subject to the following rules:
* Figurative constants may be substituted for literals.
* A signed numeric literal must have a signed numeric PICTURE and
character string associated with it.
* All numeric literals must have a value 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
must not exceed the size indicated by the PICTURE clause.
* If the category of the item being described 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.
* If the category of the item being described is any other than
numeric, 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. Editing characters in the PICTURE
clause are included in determining the size of the data item, but
have no effect on initialization. Therefore, the VALUE for an
edited item must be presented in an edited form.
* 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 the group.
A VALUE clause cannot be used for elements of a group that has a
VALUE clause assigned to it at the group level.
RENAMES Clause
The RENAMES clause permits alternative, possibly overlapping groupings of
elementary items. This clause is always associated with a 66 level
entry.
Syntax.
The level number (66) and data-name-1 are not part of the RENAMES clause,
but are used to clarify the purpose of the clause.
Parameters.
THROUGH and equivalent.
THRU
data-name-1 the name used to rename the item or items referenced by
data-name-2 and data-name-3. It cannot be a qualifier,
and can only be qualified by the names of the associated
01, FD, or SD level entries.
data-name-2 and must be names of elementary items or groups of
data-name-3 elementary items in the same logical record. They must
not be the same name, and neither may have an OCCURS
clause in its data description, or be subordinate to an
item that has an OCCURS clause in its description.
Furthermore, no item within the range of the portion of
the logical record being renamed can be variable in
size, or can contain such an item. Data-name-2 and
data-name-3 may be qualified.
If data-name-2 is used alone (that is, the optional
THROUGH phrase is unused), data-name-2 can be either a
group or an elementary item.
Description.
When data-name-2 is a group item, data-name-1 is treated as a group item;
when data-name-2 is an elementary item, data-name-1 is treated as an
elementary item.
If the THROUGH phrase is used, data-name-1 is a group item that includes
all elementary items starting from data-name-2 and concluding with
elementary item data-name-3. Or, if data-name-2 and data-name-3 are also
group names, data-name-1 is a group name that begins with the first
elementary item in data-name-2 and concludes with the last elementary
item in data-name-3.
Because of the way in which data-name-1 is defined, there are
restrictions on the area described by data-name-2 and data-name-3. That
is, the area described by data-name-3 must not begin to the left of the
first character in the area described by data-name-2, and it must end to
the right of the last character of the area of data-name-2.
Example.
01 STUDENT-REC.
03 NAME PIC X(20).
03 ID-NO PIC X(9).
03 MAJOR PIC X(3).
03 CLASSES OCCURS 5 TIMES.
05 CLASS-ID PIC X(3).
05 DEPT PIC X(3).
66 STUD-INFO RENAMES NAME THRU MAJOR.
66 MAJOR-DEPT RENAMES MAJOR.
In the above example, CLASSES, CLASS-ID, and DEPT may not be named in a
RENAMES clause because of the OCCURS clause.
NOTE The above paragraph implies that data-name-3 cannot be subordinate
to data-name-2.
You can use more than one RENAMES entry for a single logical record.
However, all RENAMES entries referring to data items within a given
logical record must immediately follow the last data description entry of
the associated record description entry. You cannot use a level 66 entry
to rename another level 66 entry or a 77, 88, or 01 level entry.
Condition Names
A condition name is always subordinate to another data item called the
conditional variable. The level number 88 is used to describe it. The
characteristics of a condition name are implicitly those of its
conditional variable. This must be reflected in the value or values
assigned to the condition name.
A condition name is assigned one or more values. The condition name can
later be used to specify comparison with the conditional variable (see
Chapter 8 , "PROCEDURE DIVISION", for information on condition name
conditions).
Syntax.
The VALUE clause in a condition name has the following format:
Parameters.
condition-name- any valid user-defined COBOL word.
1
literal-1 and the values assigned to the condition name.
literal-2
THROUGH and equivalent and can be used interchangeably.
THRU
Description.
The VALUE clause and the condition name itself are the only two clauses
permitted in the data description entry.
The VALUE clause can be used in any of the sections of the DATA DIVISION
and must be used for condition names.
Wherever the THROUGH phrase is used, literal-1 must be less than
literal-2.
When a VALUE clause is used in a level 88 entry, you can specify no more
than 127 ranges of values for the related condition name. A range of
values is either a single literal or two literals related by the THROUGH
(or THRU) keyword.
Additional rules applying to the VALUE clause in condition names are
described under the headings "Restrictions on the Use of the VALUE
Clause" and "Literals in the VALUE Clause", earlier in this chapter.
The condition name entries for a particular conditional variable must
follow the entry describing the item with which the condition name is
associated (that is, the conditional variable). Each condition name in
your program must have a separate level 88 entry associated with it. A
condition name cannot be associated with any data description entry
containing a level number 66, another condition name, or a group item
with descriptions including JUSTIFIED, SYNCHRONIZED, or USAGE (other than
DISPLAY).
Example.
01 CONDVAR PIC 9(5) USAGE DISPLAY.
88 COND1 VALUE 10 THRU 25, 100 THRU 250.
01 ALPHAVAR PIC A.
88 ALPHACOND VALUE "A" , "M" THROUGH "Z".
MPE/iX 5.0 Documentation