beautypg.com

2 data organization – Compaq COBOL AAQ2G1FTK User Manual

Page 112

background image

Handling Nonnumeric Data
3.1 Storage of Nonnumeric Data

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

A Compaq 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 Compaq 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

A group item is a data item that is followed by one or more elementary items or
other group items, all of which have higher-valued level numbers than the group
to which they are subordinate.

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

An elementary item is a data item that has no subordinate data item.

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).

3–2 Handling Nonnumeric Data