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, which may be a record or data item; or an array of records or data items. For rules, see Naming conventions.

If you specify the modifier inOut or out, 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.

Changes made to a parameter are available in functions that invoked by the receiving function, but only if the parameter is passed as an argument.

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

inOut

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 an item 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), 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

in

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 an item 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.

out

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 invoker is affected by changes made to the parameter.

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 an item 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.

recordPartName

A record part that is visible to the function and that is acting as a typedef (a model of format) for a parameter. For details on what parts are visible, see References to parts.

The following statements apply to input or output (I/O) against the specified record:

  • A 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 caller, so if you perform I/O against a record parameter, any tests on that record can occur in the current function, in the caller, 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 record uses the record properties specified for the parameter, not the record properties specified for the argument.

  • For 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.

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 parameter's primitive type, as described in the topic of the same name.

length

The parameter's length, which is an integer that represents the number of characters or digits in the memory area referenced by parameterName.

decimals

For some numeric types, you may specify decimals, which is an integer that represents the number of places after the decimal point. The maximum number of decimal positions is the smaller of two numbers: 18 or the number of digits declared as length. The decimal point is not stored with the data.

"dateTimeMask"

For items of type INTERVAL or TIMESTAMP, you may specify "dateTimeMask", which assigns a meaning (such as "year digit") to a given position in the item value. The mask is not stored with the data.

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.

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

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.

nullable

Indicates the following characteristics of the parameter:

  • The parameter can be set to null

  • The parameter has access to the state information necessary to test for truncation or null in a logical expression

The nullable modifier is meaningful only if the argument passed to the parameter is a structure item in an SQL record. The following rules apply:

  • The parameter can be set to null and tested for null only if the item property isNullable is set to yes

  • The ability to test for truncation is available regardless of the value of isNullable

  • You can specify nullable regardless of whether the modifier inOut, in, or out is in effect.

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
    

Related concepts
Function part
Library part
Parts
References to parts
References to variables and constants
Typedef

Related reference
Basic record part in EGL source format
Data initialization
TIMESTAMP
EGL source format
Function part in EGL source format
Indexed record part in EGL source format
INTERVAL
Logical expressions
MQ record part in EGL source format
Naming conventions
Primitive types
Relative record part in EGL source format
Serial record part in EGL source format
SQL record part in EGL source format