Publicerades 27 augusti 2014

Parameter in variables

Parameter in variables

Parameter passing to variables is a very useful capability but unfortunately not very common.

What you do is that you create a place holder for one or several parameters in your variable and when you call the variable you also pass parameter values.

Let’s go on with an example.

Assume we have an application where we want to see the Actuals for external customers in some places and internal customers on others. Does one work with variables we may find variables looking like this

[codesyntax lang=”php”]

eActualsCustomerExternal = sum({<CustomerType={'External'}>}Actual)

eActualsCustomerInternal= sum({<CustomerType={'Internal'}>}Actual)

eActuals = sum(Actual)

[/codesyntax]

 

However with the help of parameter passing in variables we can concatenate these two to variable to a single one

[codesyntax lang=”php”]

eActuals = sum({<CustomerType={'$1'}>} Actual)

[/codesyntax]

In the expression above we have the $1 which is a holder for a parameter to be passed when the variable is being called.

When calling the variable we write

[codesyntax lang=”php”]

eActuals(External)

[/codesyntax]

And thus ‘External’ is the paramater replacing the $1 in the variable expression.

Passing more parameters can be done by separating the parameters with a comma

[codesyntax lang=”php”]

eActuals(External, CustomerType)

[/codesyntax]

But remember to create a placeholder for each parameter

[codesyntax lang=”php”]

eActuals = sum({<$2={'$1'}>} Actual)

[/codesyntax]

Parameter passing to variables is a very useful capability but unfortunately not very common.

What you do is that you create a place holder for one or several parameters in your variable and when you call the variable you also pass parameter values.

Let’s go on with an example.

Assume we have an application where we want to see the Actuals for external customers in some places and internal customers on others. Does one work with variables we may find variables looking like this

[codesyntax lang=”php”]

eActualsCustomerExternal = sum({<CustomerType={'External'}>}Actual)

eActualsCustomerInternal= sum({<CustomerType={'Internal'}>}Actual)

eActuals = sum(Actual)

[/codesyntax]

 

However with the help of parameter passing in variables we can concatenate these two to variable to a single one

[codesyntax lang=”php”]

eActuals = sum({<CustomerType={'$1'}>} Actual)

[/codesyntax]

In the expression above we have the $1 which is a holder for a parameter to be passed when the variable is being called.

When calling the variable we write

[codesyntax lang=”php”]

eActuals(External)

[/codesyntax]

And thus ‘External’ is the paramater replacing the $1 in the variable expression.

Passing more parameters can be done by separating the parameters with a comma

[codesyntax lang=”php”]

eActuals(External, CustomerType)

[/codesyntax]

But remember to create a placeholder for each parameter

[codesyntax lang=”php”]

eActuals = sum({<$2={'$1'}>} Actual)

[/codesyntax]