Local Properties

You can use PilotScript to work with local properties.

This page discusses:

See Also
PilotScript Reference

A local property is a protocol property that is scoped to a single component. Local properties are stored as a property list, but the data does not move with the data records and is not visible from anywhere outside the component where it is used. Instead, it is tied to the component itself. Local properties simplify the problem of multiple components using the same property names for temporary or count properties. Because they are not accessible from outside the component where they are used, the local properties do not pollute the global or data record property lists. If an expression makes a change to a local property when processing a data record, that change remains until the next data record is processed within that component.

# Local Syntax

In PilotScript, local properties are written with the hash character (#) and are case-insensitive. Examples of local properties include:

#number_of_molecules_passed
#num_through_pass
#num_through_fail

Single quotes may be added to the property name to allow spaces and other special characters:

#'total records'
#'Total £'

Assigning Local Properties

You can assign local properties to data record properties or global properties as illustrated in the following example:

#lcount += 1; 
count := #lcount;

In the above example, the local property #lcount increments each time a record passes through. A data record property is assigned the value of that local property. In other words, all records get an index indicating the order that they passed through the component. Unlike using global properties, #lcount does not affect any other component that uses the same property name within the protocol.

When you use an expression like the one illustrated above, in a PilotScript component, you need to initialize the protocol property by setting the Initial Expression parameter. For example, to calculate an average molecular weight for a stream of molecules, use the following:

Parameter Expression
Initial Expression
#count := 0; #total_weight := 0;
Expression
#count += 1;
#total_weight += Molecular_Weight;
Final Expression
@average_weight := #total_weight / #count;

Note: Data record properties are tied to the pipeline, so they cannot be accessed by these parameters.

Loop Properties

Local properties are perfect to use as properties within loops and as temporary properties:

#total := 0;
FOR #index in 1 .. NumValues(myprop)
LOOP
	#total += myprop[#index];
END LOOP;
average := #total / numvalues(myprop);

The above example calculates the average value for the data record property array myprop. Since local properties are used for the looping property #index and the temporary property #total, neither of these properties interfere with other components within the protocol, nor is it necessary to add these properties to a subprotocol's DeclareLocal parameter.