USAGE IS DISPLAY
This is the most common form of internal data. The data item is stored in ASCII format and each character will take 1 byte. It is default usage and a data item is stored in a couple of contiguous bytes. The following example calculates the number of bytes required:
01 WS-NUM PIC S9(5)V9(3) USAGE IS DISPLAY. It requires 8 bytes as sign and decimal doesn't require any byte. 01 WS-NUM PIC 9(5) USAGE IS DISPLAY. It requires 5 bytes as sign.
Data item is stored in binary format. Here, data items must be integer. While allocating the space, for COMP fields, the compiler will allocate space in multiples of word, that is, it can be halfword (2 bytes), full word or word (4 bytes), double word (8 bytes)
The following example calculates the number of bytes required:
01 WS-NUM PIC S9(n) USAGE IS COMP. If 'n' = 1 to 4, it takes 2 bytes. If 'n' = 5 to 9, it takes 4 bytes. If 'n' = 10 to 18, it takes 8 bytes.
COMP-1
The data item is similar to Real or Float and is represented as a single precision floating point number. Internally, data is stored in hexadecimal format. COMP-1 does not accept PIC clause. Here 1 word is equal to 4 bytes. This representation is suitable for arithmetic operations.
COMP-2
Data item is similar to Long or Double and is represented as double precision floating point number. Internally, data is stored in hexadecimal format. COMP-2 does not specify PIC clause. Here 2 word is equal to 8 bytes.
COMP-3
COMP-3 enables the computer to store two digits in each storage position, except for the rightmost position, which holds the sign. The sign is stored separately as the rightmost half-a-byte regardless of whether S is specified in the PIC or not. Data item is stored in packed decimal format. Each digit occupies half a byte (1 nibble) and the sign is stored at the rightmost nibble. The following example calculates the number of bytes required:
The hexadecimal number C or F denotes a positive sign and the hexadecimal number D denotes a negative sign.
Suppose if you move 1234567 into a field defined 9(7). In DISPLAY mode, which is the default, this field will use 7 storage positions. If you define the field with PIC 9(7) COMP-3, it will, however, use only four positions
12 34 56 7+
We can save a significant amount of storage by using the USAGE-COMP-3
01 WS-NUM PIC 9(n) USAGE IS COMP. Number of bytes = n/2 (If n is even) Number of bytes = n/2 + 1(If n is odd, consider only integer part) 01 WS-NUM PIC 9(4) USAGE IS COMP-3 VALUE 21. It requires 2 bytes of storage as each digit occupies half a byte. 01 WS-NUM PIC 9(5) USAGE IS COMP-3 VALUE 21. It requires 3 bytes of storage as each digit occupies half a byte.
Use COMP if the data item is a
If you will use Usage Display data items for computation then the additional overhead is required to convert the data item to the proper type both before and after the computation.
PACKED-DECIMAL (COMP-3)
While using COMP-3 for computation then use 15 or fewer digits in PIC clause to avoid the use of library routines for multiplication and division. Using a signed data item with an odd number of digits produces more efficient code since this uses an integral multiple of bytes in storage for the data item.
Fixed-Point vs Floating-Point
When conversions are necessary, binary (COMP) and packed decimal (COMP-3) data with nine or fewer digits require the least amount of overhead when being converted to or from floating-point (COMP-1 or COMP-2) data.
COBOL Blog: Click Here IBM Reference: Click Here
A well-maintained product backlog is crucial for successful product development. It serves as a single…
Incremental value to the customer refers to the gradual delivery of small, functional parts of…
A Product Market refers to the group of potential customers who might be interested in…
The Professional Agile Leadership - Evidence-Based Management (PAL-EBM) certification offered by Scrum.org is designed for…
The Professional Agile Leadership (PAL I) certification, offered by Scrum.org, is designed to equip leaders…
Choosing the right Scrum Master Certification depends on your current experience and career goals. If…