Using parameters

To effectively use procedures, you must develop an understanding of how in, out and inout parameters are used.

In parameters

In parameters are used to pass values from the calling script to the called script. In the called script, the value of the in parameter can only be referenced. You can’t alter the value of an in parameter. The following example shows how to use an in parameter in a procedure.

Example

This procedure warns when a customer is over his or her credit limit:

[spacer]

Procedure Name

Credit_Limit_Warning


in currency limit;
in string name;

warning name + " is over the limit " + string(limit);

The following script calls the Credit_Limit_Warning procedure. The parameters 10000 and Jane Smith are passed to the procedure. A warning dialog box will display that Jane Smith is over her credit limit.

[spacer]

Script Name

Credit_Limit_Test


call Credit_Limit_Warning, 10000, "Jane Smith";

Out parameters

Out parameters are used to pass values back to the calling script from the called script. The called script sets the value of the out parameter. The calling script can only reference the out parameter; it can’t change the parameter’s value. The following example shows how to use an out parameter in a procedure.

Example

The following is a procedure that returns a string indicating the discount percentage to apply, based upon the purchase amount:

[spacer]

Procedure Name

Discount_Percent


in currency purchase_amount;
out string discount_percent;

if purchase_amount >= 5000 then
	discount_percent = "30%";
elseif purchase_amount >= 2500 then
	discount_percent = "20%";
elseif purchase_amount >= 1000 then
	discount_percent = "10%";
else
	discount_percent = "0%";
end if;

The following script uses the Discount_Percent procedure. The Purchase Amount field (with the value $4725) and the local string variable l_discount are passed to the procedure. The value returned to l_discount is 20%.

[spacer]

Script Name

Calculate_Purchase


local string l_discount;

call Discount_Percent, 'Purchase Amount', l_discount;

Inout parameters

Inout parameters allow values to be passed from the calling script to the called script, and then passed back to the calling script. Both the calling and the called script can reference and alter the value of an inout parameter. The following examples shows how to use an inout parameter in a procedure.

Example

The following procedure receives a purchase amount through an inout parameter, modifies the value based upon the amount of the purchase, and returns the value to the calling script.

[spacer]

Procedure Name

Apply_Discount


inout currency purchase_amount;

if purchase_amount >= 5000 then
	purchase_amount = purchase_amount * 7 / 10;
elseif purchase_amount >= 2500 then
	purchase_amount = purchase_amount * 8 / 10;
elseif purchase_amount >= 1000 then
	purchase_amount = purchase_amount * 9 / 10;
else
	purchase_amount = purchase_amount;
end if;

The following script uses the Apply_Discount procedure. The Purchase Amount field (with the value $4725) is passed to the procedure. The value returned to the field is $3780.

[spacer]

Script Name

Calculate_Purchase


call Apply_Discount, 'Purchase Amount';


Documentation Feedback