Tech Tip: Minimize number of exchanges when using SELECTION TO ARRAY
PRODUCT: 4D | VERSION: 18 | PLATFORM: Mac & Win
Published On: June 25, 2020
If you find that you are making multiple, consecutive calls of SELECTION TO ARRAY in your code, like in the following example:
SELECTION TO ARRAY([Table_1]Field_1;$Array_1) SELECTION TO ARRAY([Table_1]Field_2;$Array_2) |
You can rewrite it a couple ways to minimize the number of exchanges with the server. One way would be to consolidate the statements:
SELECTION TO ARRAY([Table_1]Field_1;$Array_1;[Table_1]Field_2;$Array_2) |
The preceding example is good for when you only have a few lines of SELECTION TO ARRAY. If you have many lines, you can use the star (*) parameter to await execution after each call. For instance, the first example can be rewritten like so:
SELECTION TO ARRAY([Table_1]Field_1;$Array_1;*) SELECTION TO ARRAY([Table_1]Field_2;$Array_2;*) SELECTION TO ARRAY |
Not only does this make for better readability in a scenario with a lot of SELECTION TO ARRAY calls, but also it reduces the amount of server exchanges from many to just one. Note that the final SELECTION TO ARRAY statement without any parameters is necessary to trigger the execution of the preceding calls.