How to iterate variable number arguments array?
Example:
Method Execute (args...) As %Status {
...
#dim statement as %SQL.Statement
set statement = ##class(%SQL.Statement).%New(2)
set statement.%Dialect = "CACHE"
do statement.prepare(query)
#dim rs as %SQL.StatementResult
set rs = statement.execute(args...)
My questions are: 1) how do I get the size of **args **2) how to get all values of **args **3) is it possible to modify the args?
Comments
see doc on Variable Number of Parameters
Summary:
- args = number of params passed
- args(n) = n-th param
- modify as you need, it's just a local variable
Thanks Robert.
> args = number of params
Arrays in IRIS are counterintuitive 😥
They are "special" :) and called locals for variables and globals for persisted variables.
in case if you are in debug you can always print out the array with zwrite array_name. E.g. in your case:
USER>zw args
will print out all the data it contains. useful for understanding and debugging.
Got it! Now I'm struggling with adding a value to that array. Would it be correct?
set arr(arr + 1) = value
Yes, this will work. But you also need to +1 for the "top" of the array to indicate the amount of params.
I'd do the following:
set arr($I(arr))=valuein this case $I will increment the value at arr as arr=arr+1, and return it to let you enter the value of a new param
Perfect, thanks a lot