Example: passing an array by reference
Description
This example demonstrates the use of a DataStore to retrieve
data in a server component. The server component uo_customers has
a function called retrieve_custlist. retrieve_custlist generates
an instance of the DataStore ds_datastore and
then uses this DataStore to retrieve all of the rows in the Customer
table. Once the data has been retrieved, retrieve_custlist passes
the data back to the client application.
Function declaration
The retrieve_custlist function
has an argument called customers, which is defined
as an array based on the structure st_custlist.
The structure st_custlist has the
same layout as d_custlist, the DataWindow
object used to access the database. The return value for retrieve_custlist,
which is used to return the number of rows retrieved, is of type Long.
Here is the signature of the retrieve_custlist function:
1 |
retrieve_custlist( REF st_custlist customers [] ) returns long |
Script
Here is the script for the retrieve_custlist function:
1 |
datastore ds_datastore<br>long ll_rowcount<br> <br>ds_datastore = create datastore<br>ds_datastore.dataobject = "d_custlist"<br>ds_datastore.SetTransObject (SQLCA)<br> <br>IF ds_datastore.Retrieve() <> -1 THEN<br>   ll_rowcount = ds_datastore.RowCount()<br>END IF<br> <br>customers = ds_datastore.object.data<br>destroy ds_datastore<br> <br>return ll_rowcount |
At the conclusion of processing, the function retrieve_custlist destroys
the DataStore and returns the number of rows retrieved back to the
client.