If you have a routine that uses a lot of data or returns a lot of data, best
practice is to pass
clusters to the routine.
Clusters are passed by reference, which means anything about a cluster passed into a
routine can be changed by the routine. This includes adding new rows to a cluster array, or
changing the values of cluster fields.
Below in the editor is an example of a routine that calculates tax. We will
pass into the routine a
cluster that contains the amount and the tax
rate. The routine will return the tax due.
A routine having a cluster passed to it has full access to the cluster for
both reading and writing. This includes being able to add new rows to the
cluster, performing collect/end collect operations, etc.
Simplified Cluster Parameters
Just like simple parameters, cluster parameters can also be simplified if the root cluster
contains data. In this example, the root cluster is called
taxes and is both a parameter name
and a cluster name.
cluster taxes: name$, profit, tax_rate
taxes->name$ = 'Sally Sue'
taxes->profit = 1234
taxes->tax_rate = 6.5/100
calculate_tax_due with taxes, returning due
print 'Tax due:'; due; 'for '; taxes->name$
private routine calculate_tax_due with taxes, returning due
due = taxes->profit * taxes->tax_rate
end routine