question

sara S2 avatar image
0 Likes"
sara S2 asked sara S2 commented

The subtraction of 'array' type values.

Hello,

I have two columns of array data type in a global table. How to write the subtraction value of those columns values in the third column?

Regards.

Other
Other (please specify)
substractionarray type data
· 2
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Benjamin W2 avatar image Benjamin W2 commented ·

Hi @sara S2, There isn't a built in way to do this, so you will have to code it. When do you want the subtraction to occur? We will have to program the code on that trigger.

0 Likes 0 ·
sara S2 avatar image sara S2 Benjamin W2 commented ·

@Benjamin W2, thank you for your reply.

I want it to occur when a bin (tote) enters to the rack (On Entry Trigger, then write to global table). To be noted that the both arrays have the same length. Would you please gives some instructions on how to write this code?

Regards.

0 Likes 0 ·

1 Answer

Phil BoBo avatar image
1 Like"
Phil BoBo answered sara S2 commented
Table table = Table("GlobalTable1");
Array array1 = table[1][1];
Array array2 = table[1][2];
Array difference = [array1[1]-array2[1], array1[2]-array2[2], array1[3]-array2[3]];
table[1][3] = difference;


1589482695698.png (85.1 KiB)
· 2
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Phil BoBo avatar image Phil BoBo ♦♦ commented ·

Alternatively, if you want it to work for arbitrary array sizes without specifying each index individually:

Table table = Table("GlobalTable1");
Array array1 = table[1][1];
Array array2 = table[1][2];
Array difference;
for (int i = 1; i <= array1.length; i++) {
    difference.push(array1[i] - array2[i]);
}
table[1][3] = difference;

Note that this will throw an exception if the second array is shorter than the first.

0 Likes 0 ·
sara S2 avatar image sara S2 commented ·

@phil.bobo, thank you very much for your help.

0 Likes 0 ·