When to use COMP,COMP-3 variables?
When to use COMP,COMP-3 variables?
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?
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?
- Robert Sample
- Global Moderator

- Posts: 1905
- Joined: Fri Jun 28, 2013 1:22 am
- Location: Dubuque Iowa
Re: When to use COMP,COMP-3 variables?
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?
What difference you're talking about here?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.
- Robert Sample
- Global Moderator

- Posts: 1905
- Joined: Fri Jun 28, 2013 1:22 am
- Location: Dubuque Iowa
Re: When to use COMP,COMP-3 variables?
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?
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...
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...
- Robert Sample
- Global Moderator

- Posts: 1905
- Joined: Fri Jun 28, 2013 1:22 am
- Location: Dubuque Iowa
Re: When to use COMP,COMP-3 variables?
An amount field implies accumulation and / or arithmetic so use COMP-3.
Create an account or sign in to join the discussion
You need to be a member in order to post a reply
Create an account
Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute