Example: Parameters in Modules

Develop your understanding of parameter bindings. Create a module that defines a parameter that can be bound to an expression or to another parameter in the parent scope.

The module FilterByPrice filters all incoming trades based on price, and outputs only the trades that have a price greater than the value in the minimumPrice parameter.

minimumPrice can be set when FilterByPrice is loaded, or it can be bound to another parameter within the project so that the value of minimumPrice is set when the project is loaded on the server.

The module definition is:
CREATE MODULE FilterByPrice IN TradeData OUT FilteredTradeData
BEGIN 
	IMPORT 'schemas.ccl';

	DECLARE
		parameter money(2) minimumPrice := 10.00d2;
	END;

	CREATE INPUT STREAM TradeData SCHEMA TradesSchema;
	CREATE OUTPUT STREAM FilteredTradeData SCHEMA TradesSchema AS SELECT * FROM TradeData WHERE TradeData.Price > minimumPrice;
END;

Binding a Parameter to an Expression

In parameter to expression binding, minimumPrice binds to an expression at the time of loading:
LOAD MODULE FilterByPrice AS FilterOver20 IN TradeData = NYSEData OUT FilteredTradeData = NYSEPriceOver20Data PARAMETERS minimumPrice = 20.00d2;
In this type of parameter binding, the module outputs stocks only with a price greater than 20.00.

Binding a Parameter in the Module to a Parameter in the Parent Scope

In this type of binding, the parameter inside the module binds to a parameter declared in the main project, therefore modifying the value on which trades are filtered at runtime. This is done by creating a parameter within the project's DECLARE block, then binding the parameter (minimumPrice) within the module to the new parameter:
DECLARE
	parameter money(2) minProjectPrice := 15.00d2;
END;

LOAD MODULE FilterByPrice AS FilterOverMinProjPrice IN TradeData = NYSEData OUT FilteredTradeData = NYSEPriceOverMinProjPrice PARAMETERS minimumPrice = minProjectPrice;
If no value is specified for the project's parameter (minProjectPrice) at runtime, then the module filters based on the project parameter's default value of 15.00. However, if minProjectPrice is given a value at runtime, the module filters based on that value.

No Parameter Binding

In this example, minimumPrice has a default value in the module definition, therefore no parameter binding is required when loading the module. The module can be loaded as:
LOAD MODULE FilterByPrice AS FilterOver10 IN TradeData = NYSEData OUT FilteredTradeData = NYSEPriceOver10Data;
Since no binding is provided in the LOAD MODULE statement, the module filters on its default value of 10.00.