HP OpenVMS Systems Documentation
The following information is in this chapter:
Items in a COBOL program belong to any of the following three data classes:
The data description of an item specifies which class that item belongs to.
Classes are further subdivided into categories. Alphanumeric items can be numeric edited, alphanumeric edited, or alphanumeric. Every elementary item, except for an index data item, belongs to one of the classes and its categories. The class of a group item is treated as alphanumeric regardless of the classes of subordinate elementary items.
If the data description of an alphanumeric item specifies that certain editing operations be performed on any value that is moved into it, that item is called an alphanumeric edited item.
As you read this chapter, keep in mind the distinction between the class or category of a data item and the actual value that the item contains.
Sometimes the text refers to alphabetic, alphanumeric, and alphanumeric edited data items as nonnumeric data items to distinguish them from items that are specifically numeric.
Regardless of the class of an item, it is usually possible at run time
to store an invalid value in the item. Thus, nonnumeric ASCII
characters can be placed in an item described as numeric, and an
alphabetic item can be loaded with nonalphabetic characters. Invalid
values can cause errors in output or run-time errors.
3.2 Data Organization
An HP COBOL record consists of a set of data description entries that describe record characteristics; it must have an 01 or 77 level number. A data description entry can be either a group item or an elementary item.
All of the records used by HP COBOL programs (except for certain registers and switches) must be described in the source program's Data Division. The compiler allocates memory space for these items (except for Linkage Section items) and fixes their size at compilation time.
The following sections explain how the compiler sets up storage for
group and elementary data items.
3.2.1 Group Items
The size of a group item is the sum of the sizes of its
subordinate elementary items. The compiler considers all group items to
be alphanumeric DISPLAY items regardless of the class and usage of
their subordinate elementary items.
3.2.2 Elementary Items
The size of an elementary item is determined by the number of symbols that represent character positions contained in the PICTURE character-string. For example, consider this record description:
01 TRANREC. 03 FIELD-1 PIC X(7). 03 FIELD-2 PIC S9(5)V99.
Both elementary items require seven bytes of memory; however, item FIELD-1 contains seven alphanumeric characters while item FIELD-2 contains seven decimal digits, an operational sign, and an implied decimal point. Operations on such items are independent of the mapping of the item into memory words (32-bit words that hold four 8-bit bytes). An item can begin in the leftmost or rightmost byte of a word with no effect on the function of any operation that refers to that item. (However, the position of items in memory can have an effect on run-time performance.)
In effect, the compiler sees memory as a continuous array of bytes, not words. This becomes particularly important when you are defining a table using the OCCURS clause (see Chapter 4).
In HP COBOL, all records, and elementary items with level 01 or 77, begin at an address that is a multiple of 8 bytes (a quadword boundary). By default, the HP COBOL compiler will locate a subordinate data item at the next unassigned byte location.
HP COBOL allows you to handle any of the 128 characters of the ASCII character set as alphanumeric data, even though many of the characters are control characters, which usually direct input/output devices. Generally, alphanumeric data manipulations attach no meaning to the 8th bit of an 8-bit byte. Thus, you can move and compare these control characters in the same manner as alphabetic and numeric characters.
Some control characters have 0 in the high-order bit and are part of the ASCII character set, while others have 1 in the high order bit and are not part of the ASCII character set.
Although the object program can manipulate all ASCII characters, certain control characters cannot appear in nonnumeric literals because the compiler uses them to delimit the source text.
You can place special characters into items of the object program by defining symbolic characters in the SPECIAL-NAMES paragraph or by using the EXTERNAL clause. Refer to the HP COBOL Reference Manual for information on these two topics.
The ASCII character set listed in the HP COBOL Reference Manual indicates the
decimal value for any ASCII character.
3.4 Testing Nonnumeric Items
The following sections describe the relation and class tests as they
apply to nonnumeric items.
3.4.1 Relation Tests of Nonnumeric Items
An IF statement with a relation condition compares two operands. Either of these operands can be an identifier or a literal, but they cannot both be literals. If the stated relation exists between the two operands, the relation condition is true.
When coding a relational operator, leave a space before and after each reserved word. When the reserved word NOT is present, the compiler considers it and the next key word or relational character to be a single relational operator defining the comparison. Table 3-1 shows the meanings of the relational operators.
IS [NOT] GREATER THAN
IS [NOT] >
|The first operand is greater than (or not greater than) the second operand.|
IS [NOT] LESS THAN
IS [NOT] <
|The first operand is less than (or not less than) the second operand.|
IS [NOT] EQUAL TO
IS [NOT] =
|The first operand is equal to (or not equal to) the second operand.|
IS GREATER THAN OR
|The first operand is greater than or equal to the second operand.|
IS LESS THAN OR EQUAL TO
|The first operand is less than or equal to the second operand.|