VOOZH about

URL: https://www.geeksforgeeks.org/cobol/comp-2-in-cobol/

⇱ COMP-2 in COBOL - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

COMP-2 in COBOL

Last Updated : 8 Aug, 2022

In COMP Usage data will get stored in the complete binary form. Based on the usage the data will get stored either in HALF-WORD or FULL-WORD. HALF-WORD which is nothing but 2-bytes data and FULL-WORD is nothing but 4 bytes of data.

When comes COMP-2, is similar to COMP-1. In COMP-1 data will get stored in one word in the floating point form whereas in COMP-2 data will get stored or represented in two words of storage.

Features:

  • We need not specifically use the PICTURE Clause for COMP-2 variables similar to COMP-1, Because PIC will help to create a relation between data name and data type but in COMP-2 data is numeric and the data type is already pre-defined as two words.  
  • COMP-2 is comparatively more precise than COMP-1 because this will make the data more significant

Example:

Output:

👁 Image
 

Explanation:

In this example, we are displaying the comparison example for COMP and COMP-2. So we can see that the length of the COMP variables are varying based on the input data but for the COMP-2 variable length is 8 bytes and also we are not specifying the PICTURE Clause.

Comment
Article Tags: