// The first step is to define the query variables that we will be using. This is building the framework.
// Instantiates or creates the query framework.
q = new Query();
// Links the table to the data source definition.
qbds = q.addDataSource(tableNum(PurchTable));
//Set the Range and Range value
qbr = qbds.addRange(fieldNum(PurchTable, PurchId));
//Instantiate the query
qr = new QueryRun(q);
//Query will display a query form for the user. The user can then add their own number sequences or sorting preferences. This is ideal to create much more dynamic queries for form information or reporting.
//The while loops over the Table in search of the information needed.
purchTable = qr.get(tableNum(PurchTable));
info(strfmt("%1 - %2",PurchTable.PurchId,PurchTable.PurchName));