Function

Syntax:
Function <Function_name>([[Val] <Param1>[=<DefVal>], ... ,[Val] <ParamN>[=<DefVal>]])[Export] 

// Declaration of local variables;
// Operators;
...
Return <Return value>;
// Operators;
...
EndFunction

Parameters:

<Function name>
The function name.

Val
An optional keyword. A parameter that follows this keyword is passed as a value (changing the value of the formal parameter during the function execution does not affect the actual parameter that is passed when the function is called). If this keyword is not specified, the function parameter is passed as a reference (changing the formal parameter value inside the function changes the actual parameter value).

<Param1>, ..., <ParamN>
An optional comma-separated list of formal parameters. Formal parameters values must correspond to values of actual parameters that are passed to the function. This list defines the name of each parameter as it is used in the function text. The list of formal parameters can be empty.

=<DefVal>
An optional default parameter value. You can include parameters with default values anywhere in the list of formal parameters (for details, see Passing procedure and function parameters help topic).

Export
An optional keyword that specifies that this function is accessible from other program modules.

// Declaration of local variables
Declaration of local variables that can be referenced in this function (see Var operator description).

// Operators
Executable function operators.

Return <Return value>
A keyword that ends the function and returns the specified value into the caller expression.
A return value can be any expression or variable that stores a value containing the function call result.

EndFunction
A mandatory keyword that identifies the end of function.

Description:
The Function keyword denotes the beginning of a source code area for a function that can be called from any point of the program module using the <Function name> operator with a list of parameters (round brackets are mandatory, even if no parameters are passed). If an ordinary application module, managed application module, external connection module, session module, or a common module contains the Export keyword in the body of a function definition, it means that this function is accessible from all other configuration modules.

The difference between functions and procedures is that a function returns a <Return value>. The EndFunction operator identifies the end of function.

You can record any function call in a program module as a procedure call. In other words, it is allowed not to accept a return value from a function.

The variables declared in the local variable declaration area of a function are local for this function and are accessible only in this function (except when they are passed as parameters for calling other procedures, functions or methods).


    

1C:Enterprise Developer's Community