scoping of a static array in a terminal script
I have a terminal script that queries sys.process' and then parses the results writing to a logfile. As part of the processing of the results, each row of the result set includes an element from the static string. But I am not clear on the scoping of the static string. The write statement sees the static string as undefined. What I want is something to the affect:
set statStr = "aa|bb|.."
set sqlStatement = xxx
set tState = ##class(%SQL.Statement).%New()
set qStat = tState.%Prepare(< sql statement> )
set rset = tState.%Execute()
WHILE rset.%Next() { w ....., $PIECE(statStr,"|",xxx),...,!}
With the logic configured in this manner, the write fails with the error that the var statVar is undefined. To make it work ( this is poor design) I changed it to:
set sqlStatement = xxx
set tState = ##class(%SQL.Statement).%New()
set qStat = tState.%Prepare(< sql statement> )
set rset = tState.%Execute()
WHILE rset.%Next() { set statStr = "aa|bb|.." w ....., $PIECE(statStr,"|",xxx),...,!}
I am not clear how to scope the static array outside of the query results loop so that the static is not repeatedly redefined with each row of the result set.