Statement PROCEDURE Foundation
Declares procedures with a name, formal parameter list and variables.
[STATIC] PROCEDURE <ProcedureName> [( <Parameters,...> )]
[LOCAL <VarName_L> [ [:= <Expression>],...]]
[STATIC <VarName_S> [ [:= <Expression>],...]]
[MEMVAR <VarName_M,...>]
[FIELD <FieldName,...> [IN <AliasName>]]
<SourceCode>
RETURN
The PROCEDURE declaration declares a section of the program as a procedure. A procedure contains a routine which is always executed when <ProcedureName> is followed by parentheses in the body of the code. Within the parentheses, any legal expression can be used. The values of these expressions are passed to the procedure and assigned to the variables which were declared in the list of formal parameters <Parameters,...>. "Parameter" identifies a variable to which a value is assigned by the calling of the procedure. The passed value is called an argument. The value of a parameter is visible within the procedure as a LOCAL variable.
Procedures are used to structure a program and to organize the tasks of a program in components. The difference between functions and procedures is that functions have a defined return value. Procedures, on the other hand, always return the value NIL, meaning they have no return value. Procedures are introduced by the declaration PROCEDURE, functions by the declaration FUNCTION. Both delimit a section of code which is executed by specifying the name followed by parentheses. The end of a procedure occurs when a new PROCEDURE, FUNCTION, CLASS or METHOD declaration is encountered, or when the end of the source code file is reached. It is good programming practice to indicate the end of a procedure with the RETURN statement. RETURN ends a procedure and gives the control back to the calling function or procedure. Multiple RETURN statements can be used in a procedure, but it is good programming practice to use only one -- at the end of the procedure.
The visibility of procedures can be restricted with the addition of STATIC. A STATIC PROCEDURE can only be called within the PRG file in which it was declared.
Procedures use the same syntactical rules as the Xbase++ functions. They can be called with no arguments, several arguments or with all declared arguments. When individual arguments are not passed, the value of the corresponding parameter at the call of the procedure is NIL. Any parameter validation must be done within the body of a procedure. A procedure can also be called with an alias operator placed in front, causing a specific work area to be selected before execution of the procedure. By default, arguments are passed to a procedure by value. To pass an argument by reference, use the reference operator @ in front of the name of the applicable variable. This applies only to character, numeric, logical or date variable types. Arrays and objects are passed automatically by reference.
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.