Functions consist of the following elements, in the specified order:

  FUNCTION statement.
  declarations of variables used in function.
  declarations / definitions of all local constants.
  executable statements including any number of RETURN statements.
  END FUNCTION statement.

Executable statements are valid only within functions.

entry function
The entry function is the first function declared in the prolog in an INTERNAL or DECLARE statement.  The first time the entry function is called, all SHARED and EXTERNAL variables are cleared.

function names
Function names are valid symbols followed by a left parenthesis.  Unlike other symbols, function names may not take type-suffixes, except $ is valid to specify string return type.

By convention, the first character in each word in function names is capitalized, including the first character in the function name.  Function names are always followed by [whitespace plus] parentheses() , whether they take arguments or not.

By default, functions are fully encapsulated.  All variables are AUTO unless explicitly declared otherwise within the function.  Variables declared SHARED or EXTERNAL in other functions do not intrude upon same named variables within a function unless they are also declared in a SHARED or EXTERNAL statement within the function, or prefixed with an explicit SHARED or EXTERNAL scope prefix like #shared or ##external.

Functions take arguments, values passed to them each time they are called.  Functions can take as few as zero, or as many as 16 arguments.  GIANT and DOUBLE arguments count as two arguments, as do the preceding arguments.

Input argument data types are specified in DECLARE FUNCTION statements at the beginning of programs, and in FUNCTION statements that begin each function.  When functions are called, numeric arguments are automatically converted to the declared types before function execution begins.  Strings and composite arguments must match the declared type.