DEFINE FUNCTION
function-name
|
[return-data-definition] |
[function-data-definition] |
statement... |
END-FUNCTION
|
This document covers the following topics:
For an explanation of the symbols used in the syntax diagram, see Syntax Symbols.
Related Statement: DEFINE
PROTOTYPE
The DEFINE FUNCTION
statement is used to create a
user-defined function within a Natural object of type function. A function
object may contain only one DEFINE FUNCTION
statement, which
defines the function name, the function result, the parameters and the
programming code forming the operation logic.
For further information, see the following sections in the Programming Guide:
Natural object type Function
Syntax Element | Description |
---|---|
function-name
|
Function Name:
The name has to follow the same rules which apply for user-defined variables, see Naming Conventions for User-Defined Variables. This means the name has to start with a letter or a hash (#), and its maximum length is 32 characters. You may not use the same function name twice in one library. |
return-data-definition
|
Return Data Definition Clause:
For details on this clause, see Return Data Definition. |
function-data-definition
|
Function Data Definition Clause:
For details on this clause, see Function Data Definition. |
statement... |
Statement(s) to be Executed:
Defines the operation section which is executed when the function is called. It forms the function logic. |
END-FUNCTION
|
End of DEFINE FUNCTION Statement:
The Natural reserved word |
RETURNS [variable-name]
|
(format-length[/array-definition]) | [BY VALUE ]
|
|||||||
[(array-definition)]
HANDLE OF |
|||||||||
( | A |
[/array-definition]) |
DYNAMIC |
||||||
U |
|||||||||
B |
The return-data-definition
clause defines the format/length and, if applicable, the array structure of the
result value returned by the function.
Syntax Element Description:
Syntax Element | Description |
---|---|
variable-name
|
Return Value Name:
Optionally, you may specify a name which is used to access the return field within the function coding. If no such name is specified, the function name is used instead. |
format-length
|
Format/Length Definition:
The format and length of the result field. For information on format/length definition of user-defined variables, see Format and Length of User-Defined Variables in the Programming Guide. |
array-definition |
Array Dimension Definition:
With For further information, see |
HANDLE OF
dialog-element-type |
Dialog Element Type:
The type of dialog element. Its possible values are the values of
the |
HANDLE OF OBJECT |
Handle of Object:
Used in conjunction with NaturalX. For further information, see NaturalX in the Programming Guide. |
A , U or
B |
Data Type:
Alphanumeric (A), Unicode (U) or binary (B) for a dynamic result. |
DYNAMIC |
Dynamic Variable:
The function result may be defined as For information on processing dynamic variables, see Introduction to Dynamic Variables and Fields in the Programming Guide. |
BY VALUE |
BY VALUE Option:
If The format/length of the "receiving" field is either
For data transfer compatibility the rules outlined in Rules for Arithmetic Assignment and Data Transfer in the Programming Guide apply. If |
DEFINE
DATA
|
||||||||||
PARAMETER
|
||||||||||
LOCAL
|
USING
|
|||||||||
data-definition | ||||||||||
[INDEPENDENT AIV-data-definition
]
|
||||||||||
END-DEFINE
|
The function-data-definition
clause defines the the parameters which are to be provided when the function is
called, and the data fields used by the function, such as local and independent
variables.
Syntax Element Description:
Syntax Element | Description |
---|---|
USING
parameter-data-area |
PDA Name:
The name of the
See also Defining Parameter
Data in the |
parameter-data-definition |
Direct Parameter Data Definition:
Instead of defining a parameter data area, parameter data can also be defined directly within a function call. See also Direct
Parameter Data Definition in the |
USING
local-data-area |
LDA Name:
Specify the name of the local data area (LDA) to be referenced. See also Defining Local
Data in the |
USING
parameter-data-area |
PDA Name:
Specify the name of a parameter data area (PDA). Note: See also Defining Local
Data in the |
data-definition |
Direct Data Definition:
For information on how to define elements or fields within the
statement itself, that is, without using an LDA or PDA, see the section
Direct Data
Definition in the |
INDEPENDENT
AIV-data-definition |
AIV Data Definition:
Can be used to define a single or multiple application-independent variables (AIVs). See Defining
Application-Independent Variables in the |
END-DEFINE |
End of Clause:
The Natural reserved word |
** Example 'DFUEX1': DEFINE FUNCTION ************************************************************************ DEFINE FUNCTION F#FIRST-CHAR RETURNS #RESULT (A1) DEFINE DATA PARAMETER 1 #PARM (A10) END-DEFINE /* #RESULT := #PARM /* First character as return value. END-FUNCTION * END
The function F#FIRST-CHAR
is used in the example program
DPTEX2
in library SYSEXSYN
. See
Examples
in the DEFINE PROTOTYPE
statement description.
** Example 'DFUEX2': DEFINE FUNCTION ************************************************************************ DEFINE FUNCTION F#FACTOR RETURNS (I2/1:3) DEFINE DATA PARAMETER 1 #VALUE (I2) END-DEFINE /* F#FACTOR(1) := #VALUE * 1 F#FACTOR(2) := #VALUE * 2 F#FACTOR(3) := #VALUE * 3 /* END-FUNCTION * END
The function F#FACTOR
is used in the example program
DPTEX1
in library SYSEXSYN
. See
Examples
in the DEFINE PROTOTYPE
statement description.