Optional parameters

To make a parameter optional, simply include the optional keyword when the parameter is declared. The following is a declaration of an optional in parameter.

optional in string item_description;

We recommend that optional parameters appear only at the end of the parameter list. For example, the following parameter list is not in the perferred format, because the optional parameters are not at the end of the list.

in string item_ID;
optional in string item_description;
optional in integer category;
out boolean order_status;

If you declare an optional in parameter, you can specify the default value to use if the calling script doesn’t supply a value. For example, the following parameter declaration specifies that the initial_quantity parameter will have the value 1, unless the user supplies another value.

optional in integer initial_quantity = 1;

You can use the missing() function to find out whether optional in, inout or out parameters contain values.

Example

This example checks whether the optional description parameter is supplied. If the value is supplied, the value is displayed in the Description field. Otherwise, the value “None” is displayed.

in string item_name;
optional in string description;

'Item Name' of window Item_Maintenance of form Item_Maintenance = item_name;
if not missing(description) then
	'Description' of window Item_Maintenance of form Item_Maintenance  = description;
else
	'Description' of window Item_Maintenance of form Item_Maintenance = "None";
end if;

When you call a procedure that has several optional parameters, you may not want to supply values to all of them. Use a set of double commas to indicate that no value is supplied to an optional parameter. For example, the second and third parameters of the Calculate_Taxes procedure are optional. The following call to the procedure doesn’t supply a value to the second parameter.

call Calculate_Taxes, 'Total Amount',, 'Tax Rate';

If you aren’t supplying values to optional parameters that appear at the end of the parameter list, you can simply omit the parameters. For example, the following call to the Calculate_Taxes procedure doesn’t supply a value to the third (last) parameter, so the parameter is omitted.

call Calculate_Taxes, 'Total Amount', 'Sublet Labor';


Documentation Feedback