FUNPROG

Summary


Funprog is used to declare a function, callable by func and which can contain a list of arguments and return a result.

Syntax

   Funprog function [ '(' args_list ')' ]

Parameters

Element

Description

Restrictions

function

'OBJect_name describing the function.

None.

args_list

List of the variable_names separated by the character ','.

The arguments must have distinct names.

Examples

   # Call to the calculation X function in the ZETRT process
   # RESULT will give the number 22

Local Integer RESULT
RESULT = 4*(func ZETRT.X(3,2) + 1)
End

   # the calculation X function in the ZETRT process 

Funprog X(A,B)
Value Integer A
Value Integer B
End A*A/B

   # the function restoring the active or inactive status of an activity code
   # and its dimensioning

Funprog ACTIVE(COD)
Value Char COD
If COD="" : End 1 : Endif
If clalev([F:ACV])=0 : Local File ACTIVE [ACV] : Endif
Read [ACV]CODACT = COD
If fstat or [F:ACV]FLACT<>2
End 0
Elsif [F:ACV]TYP=2
End [F:ACV]DIME
Else
End 1
Endif

Description and comments

A function declared by the Funprog instruction is completed by the End instruction. In fact, its execution, triggered by the call to a func is completed when an End instruction is encountered. Then, the process that called this function continues from the instruction that follows this func, which can them use the result of the expression specified in the End instruction of the function.

When the function contains arguments, it is possible but not imperative, to declare them (all or a part) following the Funprog instructions. The order in which this is done does not follow that of the Funprog instruction.

Other than their type and dimension, the user specifies if they are transferred by address or by value by using the following keywords :

It is possible to use as argument type the same as for the variables (Label, Shortint, Integer, Date, Decimal and Char).
By default, the type will be :

The length of the arguments of the type Char will not be specified. The argument name is followed by (). The length of the local variable will be that of the argument passed by func.

After the type, it is indispensable to specify the dimension if there is one, by using the characters "(" and ")". To declare several dimensions it will be necessary to use commas to separate them.

Example : Value Decimal MAT(,) declares a bi-dimensional grid of DCB numbers where the sizes depend on the argument passed by func and where the lesser range will be 0 for the 2 dimensions.

By default - that is to say nothing is specified - the size of each dimension will be that of the argument and its lower range will be 0. It is possible to specify the size of each dimension by an expression with an integer value or a variable passed as a parameter. In this latter case, this variable MUST have been declared beforehand.

Example : Variable Char ARGS () (AC,GV)
declares a bi-dimensional grid of character strings, the first dimension going from 0 to AC - 1, the second from 0 to GV -1.

It is possible to specify the lower range. If the lower range is specified, it is also possible to specify the upper range. If this is not done, the resulting size will be that of the argument. These ranges can be expressions - integer values, variables. The lower ranges will be followed by "..".

Example : Value Integer CUB(N11..,N21..N22,) declares a grid of integers with 3 dimensions, indexed from the N11 for the first, from N21 to N22 for the second and from 0 for the third.

If the ranges are specified, these ranges do not have to be identical to those of the arguments in the calling processes, the element of the smallest index for the argument of the func will be associated with (or recopied in) the element with the smallest index of the local variable for the function and so on.

Example :

Integer T(1..M, 3..N)
func SP(T)

Funprog SP (TAB2)
Value Integer TAB2(,)

In this case the element TAB2(0,0) will point to T(1,3) etc.

At the launch of a function, a local variable class is created. The variables created in the function will by default be of this class. It will automatically be destroyed by the final End.

A function can access, during its execution, the global variables and Adonix OBJects from the calling processes. To not modify the context, on the return the function called by func, the OBJects belonging to this function in Local mode will be declared (Local File, Local Mask, Local Mesbox, Local Inpbox ). They will automatically be closed by the final End.

Remarks

During the execution of a function, the following information is saved :

On the other hand these are lost :

In addition, a function cannot terminate a transaction that it has not itself initiated.

Associated errors

Error

Description

ERRET (32)

Transaction initiated in another programme.

ERDIM (55)

Incorrect number of dimensions.

ERVEX (61)

Variable exists already.

Associated keywords

FUNC  - VALUE - VARIABLE - CONST - END


SUMMARY


Copyright © Sage 1999 - 2007