Written by

UKK Köln
Question Dmitrii Baranov · May 19, 2023

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

Dmitrii Baranov  May 20, 2023 to Robert Cemper

Thanks Robert. 

> args = number of params

Arrays in IRIS are counterintuitive 😥

0
Evgeny Shvarov  May 20, 2023 to Dmitrii Baranov

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.

0
Dmitrii Baranov  May 20, 2023 to Evgeny Shvarov

Got it! Now I'm struggling with adding a value to that array. Would it be correct?

set arr(arr + 1) = value
0
Evgeny Shvarov  May 20, 2023 to Dmitrii Baranov

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))=value

in 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

0