Page 1 of 1

When to use COMP,COMP-3 variables?

Posted: Sat Mar 29, 2014 1:10 am
by KavalJeet
Hi ,

I'm not sure what answer is best suitable when someone asks :: When should we go for COMP,COMP-3 variables? What advantage these variables have over Usage DISPLAY variables other than Memory size?

Re: When to use COMP,COMP-3 variables?

Posted: Sat Mar 29, 2014 4:22 am
by Robert Sample
COMP and COMP-3 variables are best when doing arithmetic with the variables. COMP works better for indexing / subscripting while COMP-3 is typically how COBOL does mathematical operations. However, the difference between these variables and zoned decimal variables will be negligible unless you are doing BILLIONS of operations in your program.

Re: When to use COMP,COMP-3 variables?

Posted: Sat Mar 29, 2014 11:24 am
by KavalJeet
Robert Sample wrote: However, the difference between these variables and zoned decimal variables will be negligible unless you are doing BILLIONS of operations in your program.
What difference you're talking about here?

Re: When to use COMP,COMP-3 variables?

Posted: Sat Mar 29, 2014 5:23 pm
by Robert Sample
Using COMP variables for subscripts and COMP-3 variables for arithmetic is SLIGHTLY more efficient (less CPU time) than zoned decimal. However, to see any CPU difference in COMP / COMP-3 versus zoned decimal, you have to be doing a LOT of calculations / subscripts. In general, unless you have a known issue with performance, you could code your program without any COMP / COMP-3 variables and you would not see any difference in CPU time.

Re: When to use COMP,COMP-3 variables?

Posted: Wed Apr 02, 2014 5:14 pm
by KavalJeet
Thanks you Robert.

In a recent interview I told the same to the interviewer but he asked leave it and in general how the "amount filed" will be defined comp or comp-3... :?

Re: When to use COMP,COMP-3 variables?

Posted: Wed Apr 02, 2014 5:32 pm
by Robert Sample
An amount field implies accumulation and / or arithmetic so use COMP-3.