Computational Items | USAGE Clause


Computational items refer to data items used for arithmetic calculations. These items are typically defined with the USAGE clause to specify their internal representation.

The USAGE clause defines how data is stored in memory and how calculations on that data should be performed. Different USAGE modes, such as BINARY, PACKED-DECIMAL, and DISPLAY, specify the internal representation of the data. The USAGE mode can impact storage requirements and the efficiency of arithmetic operations.

Notes -

  • The USAGE clause is used to reduce the storage space and increase the efficiency of the program.
  • Every variable declared in COBOL has a USAGE clause directly or indirectly.
  • It can be coded with any level number other than 66 or 88.

Syntax -

USAGE Clause Syntax

DISPLAY


DISPLAY computation uses the character form. In character form, one character equals one byte (8 bits) of storage. If no usage clause is used, then DISPLAY usage will be applied by default.

It applies to the Numeric, Alphabetic and Alphanumeric data types. For example -

01 WS-VAR.
   05 WS-VAR1          PIC 9(06) USAGE DISPLAY.
   05 WS-VAR2          PIC 9(06).

BINARY | COMP | COMPUTATION


COMP (BINARY) is used to store signed decimal numbers in pure binary format and applicable to numeric data items. This format is often used for arithmetic operations as it provides efficient storage and fast computation. The below table represents the storage occupied based on the number of digits in the PICTURE clause –

Digits in PICTURE clauseStorage occupied
1 through 42 bytes (halfword)
5 through 94 bytes (full word)
10 through 188 bytes (doubleword)
For example -

01 WS-VAR.
   05 WS-VAR1   PIC 9(5) USAGE IS COMP.
   05 WS-VAR2   PIC 9(8) COMP.

Both WS-VAR1 and WS-VAR2 occupies 4 bytes of memory.

COMP-1 | COMPUTATION-1


COMP-1 is used to store single-precision (32 bit) floating-point numbers and applicable to numeric data items. It has no PICTURE clause, which is 4 bytes long (FULL WORD). COMP-1 data is stored in the format of mantissa and exponent.

Digits in PICTURE clause Storage occupied
1 through 16 4 bytes (FULL WORD)
For example -

01 WS-VAR.
   05 WS-PI        USAGE IS COMP-1.
   05 WS-RADIUS    USAGE IS COMP-1.

COMP-2 | COMPUTATION-2


COMP-2 is a USAGE type used to store internal double-precision (64 bit) floating-point numbers and applicable to numeric data items. It has no PICTURE clause, and it is 8 bytes long (DOUBLE WORD). COMP-2 data is stored in the format of mantissa and exponent.

Digits in PICTURE clauseStorage occupied
1 through 328 bytes (DOUBLE WORD)
For example -

01 WS-VAR.
   05 WS-PI        USAGE IS COMP-2.
   05 WS-RADIUS    USAGE IS COMP-2.

COMP-3 | COMPUTATION-3


COMP-3 (or Packed Decimal or Packed Numeric) is used to represent decimal numbers in a compact binary-coded decimal (BCD) format and applicable to numeric data items. COMP-3 variable contains any of the digits 0 through 9, a sign. It can have a value not exceeding 18 decimal digits.

The formula for memory calculation of the COMP-3 with n digits (variable length + 1 byte for SIGN if exists) in the declaration is -

  • No. of bytes = Round ((n + 1)/2) - Where n is an odd number.
  • No. of bytes = Round (n/2) - Where n is an even number.
For example -

01 WS-VAR.
   05 WS-WIDTH     PIC S9(02) USAGE IS COMP-3.
   05 WS-AREA      PIC S9(06) COMP-3.

WS-AREA variable is declared as COMP-3, with a signed byte plus 6 digits. A total of 7 bytes and the (n+1)/2 formula will apply as n is an odd number. So, a total of 8/2 = 4 bytes allocated for WS-AREA.

COMP-4 | COMPUTATION-4 | COMP-5 | COMPUTATION-5 -


COMPUTATION-4 or COMP-4 or COMPUTATION-5 or COMP-5 is the equivalent of COMP or BINARY. The data items are represented in storage as binary data.

Learn More?