Difference between revisions of "FUNCTION"

From Recital Documentation Wiki
Jump to: navigation, search
 
(One intermediate revision by one user not shown)
Line 5: Line 5:
 
==Syntax==
 
==Syntax==
 
FUNCTION <expC>[(<parameter-list>)]
 
FUNCTION <expC>[(<parameter-list>)]
 +
 +
[RETURN <exp> | ENDFUNC]
  
  
 
==See Also==
 
==See Also==
[[ALIAS]], [[DO]], [[DO CASE]], [[DO WHILE]], [[ENDFUNC]], [[FUNCTION_EXISTS()]], [[IF]], [[KEYWORD]], [[LINK]], [[PARAMETERS]], [[PARAMETERS()]], [[PCOUNT()]], [[PRIVATE]], [[PROCEDURE]], [[PUBLIC]], [[RETURN]], [[SET COMPATIBLE]], [[SET PROCEDURE]]
+
[[ALIAS]], [[DO]], [[DO CASE]], [[DO WHILE]], [[ENDFUNC]], [[FUNCTION_EXISTS()]], [[IF]], [[KEYWORD]], [[LINK]], [[PARAMETERS]], [[PARAMETERS()]], [[PCOUNT()]], [[PRIVATE]], [[PROCEDURE]], [[PUBLIC]], [[RETURN]], [[SET COMPATIBLE]], [[SET PROCEDURE]], [[VARINFO()]]
  
  
 
==Description==
 
==Description==
A FUNCTION <expC> command is used to declare a User Defined Function (UDF).  Recital/4GL UDFs can be used not only in programs, but also in the Applications Data Dictionary, the Report Writer and wherever a standard Recital/4GL function can be used.
+
A FUNCTION <expC> command is used to declare a User Defined Function (UDF).  Recital UDFs can be used not only in programs, but also in the Applications Data Dictionary, the Report Writer and wherever a standard Recital function can be used.
  
A UDF can have a variable number of parameters passed to it.  These are assigned to private variables in the optional PARAMETERS statement, which if used, must appear following the FUNCTION statement and before any other executable statement.  If a PARAMETERS statement is present, then at least one parameter must be specified with the UDF call.  The PCOUNT() function can be used to determine how many actual parameters were specified.
+
A UDF can have a variable number of parameters passed to it.  These are assigned to private variables in the the <parameter-list> declaration or PARAMETERS statement, which if used, must appear following the FUNCTION statement and before any other executable statement.  If a PARAMETERS statement is present, then at least one parameter must be specified with the UDF call.  The PCOUNT() function can be used to determine how many actual parameters were specified.
  
The functions in a procedure library file are made known to the Recital/4GL by using the SET PROCEDURE TO command.  Functions can be included in program files, as well as in procedure library files.  If a function is included in a program file, then it must be defined before it is used.
+
The functions in a procedure library file are made known to the Recital process by using the SET PROCEDURE TO command.  Functions can be included in program files, as well as in procedure library files.  If a function is included in a program file, then it must be defined before it is used.
  
The FUNCTION command is terminated with a RETURN statement.  The RETURN statement can optionally have an expression specified.  If none is specified then .F. is returned.  Other RETURN statements may be included in the syntax following a FUNCTION command, provided that they are properly nested between IF...ENDIF, DO WHILE...ENDDO, or DO CASE...ENDCASE.  The Recital/4GL function names can be a maximum of 32 characters in length, and must begin with a letter or underscore, followed by any combination of letters (A-Z), digits (0-9), and underscores (_).
+
The FUNCTION command is terminated with an ENDFUNC or RETURN statement.  The RETURN statement can optionally have an expression specified.  If none is specified then .F. is returned.  Other RETURN statements may be included in the syntax following a FUNCTION command, provided that they are properly nested between [[IF|IF...ENDIF]], [[DO WHILE|DO WHILE...ENDDO]], or [[DO CASE|DO CASE...ENDCASE]]If both RETURN and ENDFUNC are omitted, the function definition will be terminated when another PROCEDURE or FUNCTION command is reached.
  
To execute a UDF, name it in an expression, followed by parameters in round brackets.  It will behave just like any standard Recital/4GL function.
+
Recital function names can be a maximum of 32 characters in length, and must begin with a letter or underscore, followed by any combination of letters (A-Z), digits (0-9), and underscores (_).
 +
 
 +
To execute a UDF, name it in an expression, followed by parameters in round brackets.  It will behave just like any standard Recital function.
  
 
There is no limit to the number of functions that can be declared in the Recital/4GL.  The commands LIST PROCEDURE or DISPLAY PROCEDURE will let you see all currently active functions and procedures.
 
There is no limit to the number of functions that can be declared in the Recital/4GL.  The commands LIST PROCEDURE or DISPLAY PROCEDURE will let you see all currently active functions and procedures.
 
If SET COMPATIBLE is set to VFP or CLIPPER5, the FUNCTION command can also include the parameter list declaration, instead of requiring a separate PARAMETERS statement.  The parameters should be listed in comma-separated format within parentheses after the function name, e.g.
 
 
function myfunc(para1, para2, para3)
 
 
If SET COMPATIBLE is set to VFP, the FUNCTION declaration can be terminated with an ENDFUNC command rather than a RETURN.  It will also be terminated when another PROCEDURE or FUNCTION command is reached.
 
  
  
Line 36: Line 34:
 
function atimesb
 
function atimesb
 
   parameters a, b
 
   parameters a, b
 +
  result=a*b
 +
return result
 +
 +
? atimesb(5,10)
 +
        50
 +
 +
//or
 +
function atimesb(a, b)
 
   result=a*b
 
   result=a*b
 
return result
 
return result

Latest revision as of 10:34, 30 August 2011

Purpose

Declare a User Defined Function (UDF)


Syntax

FUNCTION <expC>[(<parameter-list>)]

[RETURN <exp> | ENDFUNC]


See Also

ALIAS, DO, DO CASE, DO WHILE, ENDFUNC, FUNCTION_EXISTS(), IF, KEYWORD, LINK, PARAMETERS, PARAMETERS(), PCOUNT(), PRIVATE, PROCEDURE, PUBLIC, RETURN, SET COMPATIBLE, SET PROCEDURE, VARINFO()


Description

A FUNCTION <expC> command is used to declare a User Defined Function (UDF). Recital UDFs can be used not only in programs, but also in the Applications Data Dictionary, the Report Writer and wherever a standard Recital function can be used.

A UDF can have a variable number of parameters passed to it. These are assigned to private variables in the the <parameter-list> declaration or PARAMETERS statement, which if used, must appear following the FUNCTION statement and before any other executable statement. If a PARAMETERS statement is present, then at least one parameter must be specified with the UDF call. The PCOUNT() function can be used to determine how many actual parameters were specified.

The functions in a procedure library file are made known to the Recital process by using the SET PROCEDURE TO command. Functions can be included in program files, as well as in procedure library files. If a function is included in a program file, then it must be defined before it is used.

The FUNCTION command is terminated with an ENDFUNC or RETURN statement. The RETURN statement can optionally have an expression specified. If none is specified then .F. is returned. Other RETURN statements may be included in the syntax following a FUNCTION command, provided that they are properly nested between IF...ENDIF, DO WHILE...ENDDO, or DO CASE...ENDCASE. If both RETURN and ENDFUNC are omitted, the function definition will be terminated when another PROCEDURE or FUNCTION command is reached.

Recital function names can be a maximum of 32 characters in length, and must begin with a letter or underscore, followed by any combination of letters (A-Z), digits (0-9), and underscores (_).

To execute a UDF, name it in an expression, followed by parameters in round brackets. It will behave just like any standard Recital function.

There is no limit to the number of functions that can be declared in the Recital/4GL. The commands LIST PROCEDURE or DISPLAY PROCEDURE will let you see all currently active functions and procedures.


Example

// Function to return product of two numbers
function atimesb
  parameters a, b
  result=a*b
return result
 
? atimesb(5,10)
        50
 
//or
function atimesb(a, b)
  result=a*b
return result
 
? atimesb(5,10)
        50


Products

Recital Server, Recital