Function parameters

The syntax diagram for a function parameter is as follows:

Syntax diagram for a function parameter
parameterName
Specifies the name of a parameter. For rules, see Naming conventions.

If you specify the modifier inOut or out (as is possible for a parameter that is not based on a reference type), any changes that are made to the parameter value are available in the invoking function. Those modifiers are described later and in the section Implications of inOut and the related modifiers. For details on how reference types are handled, see Reference variables and NIL in EGL.

A parameter can be passed as an argument to another function. A parameter is not otherwise visible to functions invoked by the function containing the parameter.

A parameter that ends with brackets ([ ]) is a dynamic array, and the other specifications declare aspects of each element of that array.

partName
Name of a part, which may be a record part, dictionary, arrayDictionary, or a reference type.
The following statements apply to input or output (I/O) against a fixed record:
  • A fixed record passed from another function in the same program includes record state such as the I/O error value endOfFile, but only if the record is of the same record type as the parameter. Similarly, any change in the record state is returned to the invoker, so if you perform I/O against a record parameter, any tests on that record can occur in the current function, in the invoker, or in a function that is called by the current function.

    Library functions do not receive record state.

  • Any I/O operation performed against the fixed record uses the record properties specified for the parameter, not the record properties specified for the argument.
  • For fixed records of type indexedRecord, mqRecord, relativeRecord, or serialRecord, the file or message queue associated with the record declaration is treated as a run-unit resource rather than a program resource. Local record declarations share the same file (or queue) whenever the record property fileName (or queueName) has the same value. Only one physical file at a time can be associated with a file or queue name no matter how many records are associated with the file or queue in the run unit, and EGL enforces this rule by closing and reopening files as appropriate.
inOut (not supported for reference types)
The function receives the argument value as an input, and the invoker receives any changes to the parameter when the function ends. If the argument is a literal or constant, however, the argument is treated as if the modifier in were in effect.

The inOut modifier is necessary if the parameter is a field and you specify the modifier field, which indicates that the parameter has testable, form-field attributes such as blanks or numeric.

If the parameter is a record, the following rules apply:
  • If you intend to use that record to access a file or database in the current function (or in a function invoked by the current function), you must specify the inOut modifier or accept that modifier by default
  • If the type of record is the same for argument and parameter (for example, if both are serial records), the record-specific state information such as end-of-file status is available in the function and is returned to the invoker, but only if the inOut modifier is in effect

When you specify a limited-length string as a function parameter whose modifier is out, the length limit must be the same in argument and parameter.

If the inOut modifier is in effect, the related argument must be reference-compatible with the parameter, as described in Reference Compatibility in EGL.

in (not supported for reference types)
The function receives the argument value as an input, but the invoker is not affected by changes made to the parameter.

You cannot use the in modifier for a field that has the modifier field. Also, you cannot specify the in modifier for a record that is used to access a file or database either in the current function or in a function invoked by the current function.

When you specify a limited-length string as a function parameter whose modifier is in, any text input is valid:
  • If more characters are in the source than are valid in the target, EGL runtime truncates the copied content to fit the available length.
  • If fewer characters are in the source than are valid in the target, EGL runtime pads the copied content with blanks, to the specified length.
out (not supported for reference types)
The function does not receive the argument value as an input; rather, the input value is initialized according to the rules described in Data Initialization. The value of the parameter is assigned to the argument when the function returns.

If the argument is a literal or constant, the argument is treated as if the modifier in were in effect.

You cannot use the out modifier for a parameter that has the modifier field. Also, you cannot specify the out modifier for a record that is used to access a file or database either in the current function or in a function invoked by the current function.

When you specify a limited-length string as a function parameter whose modifier is out, the length limit must be the same in argument and parameter.

dataItemPartName
A DataItem part that is visible to the function and that is acting as a typedef (a model of format) for a parameter.
primitiveType
The type of a primitive field. Depending on the type, the following information may be required:
  • The parameter's length, which is an integer that represents the number of characters or digits in the memory area.
  • For some numeric types, you may specify an integer that represents the number of places after the decimal point. The decimal point is not stored with the data.
  • For a field of type INTERVAL or TIMESTAMP, you may specify a datetime mask, which assigns a meaning (such as "year digit") to a given position in the item value.

In a service, a parameter cannot be of type ANY, BLOB, or CLOB.

looseType
A loose type is a special kind of primitive type that is used only for function parameters. You use this type if you wish the parameter to accept a range of argument lengths. The benefit is that you can invoke the function repeatedly and can pass an argument of a different length each time.
Valid values are as follows:
  • CHAR
  • DBCHAR
  • HEX
  • MBCHAR
  • NUMBER
  • UNICODE

If you wish the parameter to accept a number of any primitive type and length, specify NUMBER as the loose type. In this case, the number passed to the parameter must not have any decimal places.

If you wish the parameter to accept a string of a particular primitive type but any length, specify CHAR, DBCHAR, MBCHAR, HEX, or UNICODE as the loose type and make sure that the argument is of the corresponding primitive type.

The definition of the argument determines what occurs when a statement in the function operates on a parameter of a loose type.

Loose types are not available in functions that are declared in libraries or services.

For details on primitive types, see Primitive types.

field
Indicates that the parameter has form-field attributes such as blanks or numeric. Those attributes can be tested in a logical expression.

The field modifier is available only if you specify the inOut modifier or accept the inOut modifier by default.

The field modifier is not available for function parameters in a service or in a library of type nativeLibrary.

nullable
The nullable modifier indicates that the parameter can be set to null and that the function has access to the state information necessary to test for null in a logical expression.
The nullable modifier is meaningful only in the following case:
  • The build descriptor option itemsNullable is set to yes; or
  • Regardless of the value of that build descriptor option, the argument is a field in a non-fixed record or is a structure field in an SQL record, and the field-level property isNullable is set to yes.

If the function is in a service part or in an interface part of type basicInterface, only the second case applies because the build descriptor option itemsNullable is always set to no.

You can specify nullable regardless of whether the modifier inOut, in, or out is in effect. However, when inOut is in use, the following rules apply:
  • An argument that is nullable is compatible with a nullable or non-nullable parameter
  • An argument that is not nullable requires a non-nullable parameter because if the parameter were nullable, the function could null the parameter but not return the null indicator to the invoker

Implications of inOut and the related modifiers

To better understand the modifiers inOut, out, and in, review the following example, which shows (in comments) the values of different variables at different points of execution.
program inoutpgm 
	a int;
	b int;
	c int;

	function main()
		a = 1;
		b = 1;
		c = 1;

		func1(a,b,c);

		// a = 1          
		// b = 3          
		// c = 3 		
	end

	function func1(x int in, y int out, z int inout)
		// a = 1          x = 1
		// b = 1          y = 0
		// c = 1          z = 1
		
		x = 2;
		y = 2;
		z = 2;

		// a = 1          x = 2
		// b = 1          y = 2
		// c = 2          z = 2

		func2();
		func3(x, y, z);
		// a = 1          x = 2
		// b = 1          y = 3
		// c = 3          z = 3

	end

	function func2()
		// a = 1          
		// b = 1          
		// c = 2          
			
	end

	function func3(q int in, r int out, s int inout)
		// a = 1          x = unresolved   q = 2
		// b = 1          y = unresolved   r = 2 
		// c = 2          z = unresolved   s = 2   
		
		q = 3;
		r = 3;
		s = 3;

		// a = 1          x = unresolved   q = 3
		// b = 1          y = unresolved   r = 3 
		// c = 3          z = unresolved   s = 3   


	end
	
Feedback
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.