Question
· Dec 29, 2021

How to Rewind a %ResultSet

I need iterate multiple times the same ResultSet. How can I do a rewind on it?

Product version: IRIS 2021.1
Discussion (3)1
Log in or sign up to continue

Hey Yuri.

Depending on the context, this answer I gave for a similar question may be relevant:

...you can pass ..Adapter.ExecuteQuery() a snapshot object (EnsLib.SQL.Snapshot) which will then get populated rather than a getting a result set returned. With this populated snapshot object, you can then iterate through it using its Next() method just like the result set, but then you can use its Rewind() method. 

For example:

Set Snapshot = ##Class(EnsLib.SQL.Snapshot).%New()
Set sql = "SELECT * FROM MY_TABLE WHERE X= '"_Y_"'"
Set status = ..Adapter.ExecuteQuery(Snapshot, sql)
While Snapshot.Next(){
  //First run through of snapshot
}
Do Snapshot.Rewind()
While Snapshot.Next(){
  //Second run through of snapshot
}