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 define a function
which is stored as a Natural object of the type function. A function object may
contain only one DEFINE FUNCTION
statement.
The DEFINE FUNCTION
statement defines the function name,
the parameters, the local and application-independent variables, the function
result and the statements forming the operation logic. These statements are
executed when the function is called.
For further information, see the following sections in the Programming Guide:
Natural object type Function
Syntax Element | Description |
---|---|
function-name
|
Function Name:
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 For further information, see Dialogs and Dialog Elements in the Dialog Component Reference. |
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
|
|||||||||
local-data-definition | ||||||||||
[INDEPENDENT aiv-data-definition
]
|
||||||||||
END-DEFINE
|
The function-data-definition
clause defines the parameters which are to be provided when the function is
called, and the data fields used by the function, such as local and
application-independent variables. A global data area (GDA) cannot be
referenced inside the function definition.
Syntax Element Description:
Syntax Element | Description |
---|---|
PARAMETER USING
parameter-data-area |
PDA Name:
Specify the name of the parameter data area (PDA) that contains data elements which are used as parameters in a function call. See also Defining
Parameter Data in the |
PARAMETER
parameter-data-definition |
Parameter Data Definition:
Instead of defining a parameter data area, parameter data can also be defined directly within a function call. See also Parameter Data
Definition in the |
LOCAL 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 |
LOCAL USING
parameter-data-area |
PDA Name:
Specify the name of a parameter data area (PDA). Note: See also Defining Local
Data in the |
LOCAL
local-data-definition |
Local 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
Local 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.