Question
· Sep 24, 2021

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.

Product version: Caché 2017.1
Discussion (2)1
Log in or sign up to continue

Hi Kevin,

the variable statStr should be known inside your loop, e.g. following routine works fine in SAMPLES :

 test    ;
         set statStr = "aa|bb|.."
         set sqlStatement = "Select * From Cinema.Film"
         set tState  = ##class(%SQL.Statement).%New()
         set qStat   = tState.%Prepare(sqlStatement)
         set rset    = tState.%Execute()
         WHILE rset.%Next() {
              Write rset.%GetData(1), " ",$Piece(statStr,"|",1),!
         }
         Quit

Ok, so there isn't a problem with defining the static variable once as is proper design. based upon your response, I found the root cause of my issue. My static variable is a 600 char. string. This apparently exceeds the 'send:' buffer of the terminal script file. I broke the variable into 3 send: statements of 250, 250 and 100 chars in length the last send followed with a <CR>. The script functions without issue now.