# CONST variables in multiple tasks

**URL:** https://tech-community.robotics.abb.com/t/const-variables-in-multiple-tasks/6188
**Category:** Robot Controller
**Tags:** constant, initialisation
**Created:** [June 17, 2014, 10:48pm UTC](https://tech-community.robotics.abb.com/t/const-variables-in-multiple-tasks/6188 "2014-06-17T22:48:05Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![alexandrewillame](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/alexandrewillame/32/4387_2.png) [@alexandrewillame](https://tech-community.robotics.abb.com/u/alexandrewillame)
#### Post date: [June 17, 2014, 10:48pm UTC](https://tech-community.robotics.abb.com/t/const-variables-in-multiple-tasks/6188/1 "2014-06-17T22:48:05Z")

</div>

Hello,

I have two tasks. Each uses a constant value initialized in task1:

CONST num sizebuffer := 1000;

I need to use this constant value in task2. Problem is, I have to declare sizebuffer in task 2 in order to compile. But the compiler refuse just to initialize the variable without value

CONST num sizebuffer;  
Syntax error(135): Expected ‘:=’

If I initialize the sizebuffer in task2

CONST num sizebuffer := 1000;  
The program compile. But the value can be different if it is initialized differently in the two tasks! How is it possible to fix that?

Thank you for youtr help,

---

<div class="post-metadata">

### Author: ![Micky](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@Micky](https://tech-community.robotics.abb.com/u/Micky)
#### Post date: [June 23, 2014, 9:20am UTC](https://tech-community.robotics.abb.com/t/const-variables-in-multiple-tasks/6188/2 "2014-06-23T09:20:40Z")

</div>

Hi,

constant declarations can only be used in the task in which they are defined, other tasks have no access.

If you want use the data which are defined in another task, you have to declare them as persistent instead of constant.

In the task T\_ROB1 you have to define:

PERS num nSizeBuffer:=1000;

And in your task2:

PERS num nSizeBuffer;

In this case only the value of the task T\_ROB1 will be used to initialize the persistent.

/BR

Micky

---

<div class="post-metadata">

### Author: ![alexandrewillame](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/alexandrewillame/32/4387_2.png) [@alexandrewillame](https://tech-community.robotics.abb.com/u/alexandrewillame)
#### Post date: [June 25, 2014, 4:29pm UTC](https://tech-community.robotics.abb.com/t/const-variables-in-multiple-tasks/6188/3 "2014-06-25T16:29:55Z")

</div>

Hello,

Thank you for your answer. I forgot to mention, the variavle sizebuffer is used to specify the size of an array of jointtarget.

CONST num sizebuffer := 1000; ! Size of the cyclic buffer  
PERS jointtarget cyclicbuffer{sizebuffer};

RAPID programming does not allow to use non-constant variables to specify the size of an array; using PERS num nSizeBuffer:=1000 thus generate an error. How can I specify the size of an array so that the variable containing the size of the array is only initialized once for multiple tasks^

Thank you

---

<div class="post-metadata">

### Author: ![Micky](https://avatars.discourse-cdn.com/v4/letter/m/a5b964/32.png) [@Micky](https://tech-community.robotics.abb.com/u/Micky)
#### Post date: [June 26, 2014, 8:46am UTC](https://tech-community.robotics.abb.com/t/const-variables-in-multiple-tasks/6188/4 "2014-06-26T08:46:24Z")

</div>

Hello,

maybe you can define this constant declaration in a separate module and load it shared via “automatic loading of modules” (sys.cfg) into your memory.

If a module is loaded as shared, all data declarations are available in all tasks.

Best regards

Micky

---

<div class="post-metadata">

### Author: ![Toby](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/toby/32/882_2.png) [@Toby](https://tech-community.robotics.abb.com/u/Toby)
#### Post date: [July 9, 2021, 4:09pm UTC](https://tech-community.robotics.abb.com/t/const-variables-in-multiple-tasks/6188/5 "2021-07-09T16:09:20Z")

</div>

I know this is an old Post but did you ever figure a way to do this? I am trying to do the same thing…
