# RAPID Syntax Error

**URL:** <https://tech-community.robotics.abb.com/t/rapid-syntax-error/10016>\
**Category:** RAPID Programming\
**Created:** [February 25, 2021, 6:36am UTC](https://tech-community.robotics.abb.com/t/rapid-syntax-error/10016 "2021-02-25T06:36:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![innebandy](https://avatars.discourse-cdn.com/v4/letter/i/67e7ee/32.png) [@innebandy](https://tech-community.robotics.abb.com/u/innebandy)\
**Post date:** [February 25, 2021, 6:36am UTC](https://tech-community.robotics.abb.com/t/rapid-syntax-error/10016/1 "2021-02-25T06:36:11Z")

</div>

Hello,  
I’d like to use a FOR loop to reduce the number of instructions. However, a syntax error occurs when I coded a routine as below. Can anyone help implement it?  
THX.

PERS jointtarget jpos0:=[[8.64979E-6,2.03798E-6,-6.139E-6,2.2349E-5,20,-2.23871E-5],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];  
PERS jointtarget jpos1:=[[8.64979E-6,9.76204E-6,-2.88898E-7,-180,-20,180],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];  
PERS jointtarget jpos2:=[[8.64979E-6,93.0963,-180,7.98897E-6,106.904,9.36989E-7],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];

PERS jointtarget jpos3:=[[8.64677E-6,93.0963,-180,-180,-106.904,180],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];  
PERS jointtarget jpos4:=[[-180,-87.5354,-27.4211,-180,85.0435,-1.1935E-5],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];  
PERS jointtarget jpos5:=[[-180,-87.5354,-27.4211,8.57699E-6,-85.0435,180],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];  
PERS jointtarget jpos6:=[[-180,-23.0743,-152.579,-180,24.3467,-2.69069E-5],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];  
PERS jointtarget jpos7:=[[-180,-23.0743,-152.579,2.2267E-5,-24.3467,180],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];

PROC rTruncate()  
FOR i FROM 0 TO 7 DO  
jpos{i}.robax.rax\_1:=Trunc(jpos{i}.robax.rax\_1\dec:=2);  
jpos{i}.robax.rax\_2:=Trunc(jpos{i}.robax.rax\_2\dec:=2);  
jpos{i}.robax.rax\_3:=Trunc(jpos{i}.robax.rax\_3\dec:=2);  
jpos{i}.robax.rax\_4:=Trunc(jpos{i}.robax.rax\_4\dec:=2);  
jpos{i}.robax.rax\_5:=Trunc(jpos{i}.robax.rax\_5\dec:=2);  
jpos{i}.robax.rax\_6:=Trunc(jpos{i}.robax.rax\_6\dec:=2);  
!..  
ENDFOR  
ENDPROC

---

<div class="post-metadata">

**Author:** ![jmf](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/jmf/32/762_2.png) [@jmf](https://tech-community.robotics.abb.com/u/jmf)\
**Post date:** [February 25, 2021, 7:14am UTC](https://tech-community.robotics.abb.com/t/rapid-syntax-error/10016/2 "2021-02-25T07:14:15Z")

</div>

Try this.

```auto
    PERS jointtarget jpos{8}:=[[[0,2.03798E-6,-6.139E-6,2.2349E-5,20,-2.23871E-5],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]],[[8.64979E-6,93.09,-2.88898E-7,-180,-20,180],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]],
                               [[8.64979E-6,93.0963,-180,7.98897E-6,106.904,9.36989E-7],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]],[[8.64677E-6,93.0963,-180,-180,-106.904,180],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]],
                               [[-180,-87.5354,-27.4211,-180,-85.04,-1.1935E-5],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]],[[-180,-87.5354,-27.4211,8.57699E-6,-85.0435,0],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]],
                               [[-180,-23.0743,-152.579,-180,24.3467,-2.69069E-5],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]],[[-180,-23.0743,-152.579,2.2267E-5,-24.3467,180],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]]];
    PERS jointtarget jpos0:=[[8.64979E-6,2.03798E-6,-6.139E-6,2.2349E-5,20,-2.23871E-5],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];
    PERS jointtarget jpos1:=[[8.64979E-6,9.76204E-6,-2.88898E-7,-180,-20,180],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];
    PERS jointtarget jpos2:=[[8.64979E-6,93.0963,-180,7.98897E-6,106.904,9.36989E-7],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];
    PERS jointtarget jpos3:=[[8.64677E-6,93.0963,-180,-180,-106.904,180],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];
    PERS jointtarget jpos4:=[[-180,-87.5354,-27.4211,-180,85.0435,-1.1935E-5],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];
    PERS jointtarget jpos5:=[[-180,-87.5354,-27.4211,8.57699E-6,-85.0435,180],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];
    PERS jointtarget jpos6:=[[-180,-23.0743,-152.579,-180,24.3467,-2.69069E-5],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];
    PERS jointtarget jpos7:=[[-180,-23.0743,-152.579,2.2267E-5,-24.3467,180],[9E+9,9E+9,9E+9,9E+9,9E+9,9E+9]];

    PROC rTruncate()
        FOR i FROM 0 TO 7 DO
            jpos{1}.robax.rax_1:=Trunc(jpos1.robax.rax_1\dec:=2);
            jpos{2}.robax.rax_2:=Trunc(jpos2.robax.rax_2\dec:=2);
            jpos{3}.robax.rax_3:=Trunc(jpos3.robax.rax_3\dec:=2);
            jpos{4}.robax.rax_4:=Trunc(jpos4.robax.rax_4\dec:=2);
            jpos{5}.robax.rax_5:=Trunc(jpos5.robax.rax_5\dec:=2);
            jpos{6}.robax.rax_6:=Trunc(jpos6.robax.rax_6\dec:=2);
            !... 
        ENDFOR
    ENDPROC

```

---

<div class="post-metadata">

**Author:** ![innebandy](https://avatars.discourse-cdn.com/v4/letter/i/67e7ee/32.png) [@innebandy](https://tech-community.robotics.abb.com/u/innebandy)\
**Post date:** [February 25, 2021, 9:03am UTC](https://tech-community.robotics.abb.com/t/rapid-syntax-error/10016/3 "2021-02-25T09:03:11Z")

</div>

I tried a similar method as you, but failed. I Probably missed something.  
Thanks a lot.

---

<div class="post-metadata">

**Author:** ![jmf](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/jmf/32/762_2.png) [@jmf](https://tech-community.robotics.abb.com/u/jmf)\
**Post date:** [February 25, 2021, 10:16am UTC](https://tech-community.robotics.abb.com/t/rapid-syntax-error/10016/4 "2021-02-25T10:16:11Z")

</div>

Pleasure.

---

<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:** [February 26, 2021, 2:51pm UTC](https://tech-community.robotics.abb.com/t/rapid-syntax-error/10016/5 "2021-02-26T14:51:36Z")

</div>

Hello,

Arrays in RAPID start with index 1 and not with index 0.

But since you don’t use an array you have to use the instructions “GetDataVal” and “SetDataVal” to access the content of variables by name.

Here is an example:

PROC Example()

FOR i FROM 0 TO 7 DO  
TruncJointTarget “jpos”+Valtostr(i);  
ENDFOR

endproc

PROC TruncJointTarget(string JointName)  
VAR jointtarget jtTemp;

GetDataVal JointName,jtTemp;  
jtTemp.robax.rax\_1:=Trunc(jtTemp.robax.rax\_1\dec:=2);  
jtTemp.robax.rax\_2:=Trunc(jtTemp.robax.rax\_2\dec:=2);  
jtTemp.robax.rax\_3:=Trunc(jtTemp.robax.rax\_3\dec:=2);  
jtTemp.robax.rax\_4:=Trunc(jtTemp.robax.rax\_4\dec:=2);  
jtTemp.robax.rax\_5:=Trunc(jtTemp.robax.rax\_5\dec:=2);  
jtTemp.robax.rax\_6:=Trunc(jtTemp.robax.rax\_6\dec:=2);  
SetDataVal JointName,jtTemp;

ENDPROC

---

<div class="post-metadata">

**Author:** ![innebandy](https://avatars.discourse-cdn.com/v4/letter/i/67e7ee/32.png) [@innebandy](https://tech-community.robotics.abb.com/u/innebandy)\
**Post date:** [March 2, 2021, 5:57am UTC](https://tech-community.robotics.abb.com/t/rapid-syntax-error/10016/6 "2021-03-02T05:57:40Z")

</div>

Hello Micky,  
I fixed the problem using an array and your idea is also a good alternative. Thanks.
