Page 1 of 1

When would you advise to use COMP and COMP-3 variables?

Posted: Tue Jan 05, 2016 2:36 pm
by Naveen Kumar
Hi ,

When would you advise to use COMP and COMP-3 variables? In today's world what are the advantage of these variables have over PIC X() Usage DISPLAY variables when memory is not a problem?

Interviewer has already mentioned about memory and that was the answer I wanted to say; now what can be the advanatage ?

Re: When would you advise to use COMP and COMP-3 variables?

Posted: Tue Jan 05, 2016 4:53 pm
by William Collins
Memory was never, or rarely, a problem which would lead to the use of binary or packed-decimals. Disk space more so, but not really.

The benefits of binary and packed-decimal were, and remain, performance. A USAGE DISPLAY (the default if no usage specified) field has to be converted if arithmetic is carried out with it, then converted back if a result is to be stored there.

Also, when using a field for subscripting, USAGE DISPLAY will be converted to binary.

So, to avoid the conversions, you define the field as how it will be used.