How to Fetch data into an Array using SQL Object

When you use some of the SQL class built-in functions such as CreateSQL, you use Fetch method to retrieve the next row of data from the SELECT that is open on the SQL object.
Sometimes we use list of output variables to catch the data from the SQL fetch. These are the values of the fields from the selected row and are assigned in order to the given output variables. But, sometimes it is wise to use an array to store the fetch results.
In general this can be used when you don't know how many values are return from the SQL fetch or if you have significant number of fetch results are returned. In this case you may need lot of output variables which is cumbersome to maintain within the program.

You can do this as;
Local array of any &arrayFetch = CreateArrayAny();

&SQL = CreateSQL(SQL.YOUR_SQL_OBJECT);

While &SQL.Fetch(&arrayFetch)
 /* Process the row in &arrayFetch . */ 
 MessageBox(0,"",0,0,"First Value: " | &arrayFetch[1] | " Second Value: " | &arrayFetch[2] | " ... " | " Nth Value: " | &arrayFetch[3],0); 
End-While;
SHARE

Ayesha Wee