question

Gesa R avatar image
4 Likes"
Gesa R asked Joerg Vogel commented

How to assign a table as label to token?

Hi,

how can I add a table to a token? I found an aticle about Non-Label Assignment and the command below but I don't get it. Can I store only global tables or in-memory-tables like "mylist" too?

Table globaltable = Table("GlobalTable1");

Table mylist = Table.query("SELECT * FROM GlobalTable1 WHERE B=3");

label(token, "Tablelabel") = globaltable;

token.treenode.labels["Tablelabel"] = mylist;

When the table is on the label, how can I read the data from this table?

Thank you

FlexSim 18.0.5
process flowtableslabel assignment
5 |100000

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

1 Answer

·
Matthew Gillespie avatar image
4 Likes"
Matthew Gillespie answered Joerg Vogel commented

Add Table to Token Label

You can use the Table's cloneTo() command to create a copy of the table on another node in the model. For example, this code copies GlobalTable1 onto a token's TableLabel label:

Table tableLabel = Table(token.labels.assert("TableLabel"));
Table("GlobalTable1").cloneTo(tableLabel);

Note that we're using the token.labels property because we need to access the label's node directly (as opposed to the label's value).

You can also use the cloneTo() method to copy the in-memory table returned by Table.query().

Reading Values from Table on Token Label

You just need to pass the label node into a Table constructor ( Table() ) and then you can treat it like any other table using the Table API:

Table tableLabel = Table(token.labels["TableLabel"]);
double value = tableLabel[3][3];
· 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.

Jeremy R avatar image Jeremy R commented ·

If I save a Table to a token label in this way, is it possible to later do an SQL query on it? It doesn't seem to have a name for me to reference when performing the query.

0 Likes 0 ·
Joerg Vogel avatar image Joerg Vogel Jeremy R commented ·

@Jeremy R, you can use the first code line Reading Values from Table on Token Label from @Matthew Gillespie answer to get a reference to the table. Then you use this in your query directly or as $1 alias.

1 Like 1 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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