Optimizing Data Definitions

Defining data items appropriately and aligning them to give the best performance.

The performance of your program is affected by the data type, size and alignment of the data items. Using the correct data type increases efficiency, particularly in arithmetic operations.

Use COMP-5 or COMP-X numeric data items; preferably COMP-5 (where possible).

COMP-5 usage is defined for binary storage with the value stored in the native byte sequence of the processor. This makes it ideal for arithmetic efficiency. However, it is not suitable for data stored in files or passed to other machines over a network as the data is not accessible by programs running in an environment in which COMP-5 is stored in a different sequence. In these cases use COMP-X.

In managed code programs, some COBOL numeric fields are optimised to 32-bit or 64-bit binary fields, regardless of their definition in the COBOL source. For example, fields defined as DISPLAY or COMP-3 and that do not form part of a group may be stored as binary fields. The Compiler inserts code necessary to make the behaviour of these fields the same as if they had not been optimised.

The speed in which data items are processed varies according to the type of data item.

Addition and subtraction on non-integer data items is fastest if the items are COMP-5 and the decimal alignment is the same in both.

Mixing different data types in the same statement is less efficient than using the same data types throughout. The main exception to this is mixing COMP-5 and COMP-X items, where there is very little impact on performance.

Use only numeric items that occupy one, two, four or eight bytes of storage.

The fastest and smallest code is produced for operations on items that contain up to nine digits, or four bytes for binary items.

Operations on numeric items that contain more than nine digits, or more than four bytes for binary items, produce the slowest and largest code.

Align items on even-byte boundaries, in general.

Do not redefine COMP-5 items to access individual bytes. If access to individual bytes is required, use COMP-X.

Use edited items only when necessary.