Also look at the %SQL way of running queries which has some advantages, there are a few ways of doing it, one of which is:

s stmnt=##class(%SQL.Statement).%New()

s sc=stmnt.%PrepareClassQuery("GMECC.DocmanConnect.Tables.vwNewGPs","GetRows")

s rs=stmnt.%Execute()

w rs.%SQLCODE,!

while rs.%Next() {

// s var=rs.%Get("ColumnName")  - for known column names

s var1=rs.%GetData(columnNumber)

w var,!

w var1

}