PROCEDURE

From Recital Documentation Wiki
Jump to: navigation, search

Purpose

Declare a procedure


Syntax

PROCEDURE <procedure name>


See Also

ACC(), CALC(), COMPILE, DEBUG, DO, ENDPROC, FUNCTION, FUNCTION_EXISTS(), LINK, PARAMETERS, PRIVATE, PUBLIC, RETURN, SET PROCEDURE, VARINFO()


Description

The PROCEDURE statement marks the beginning of a procedure. A procedure declaration is terminated with a RETURN statement. You may have other RETURN statements within the procedure body, provided that they are properly nested between IF...ENDIF, DO WHILE ...ENDDO, or DO CASE ...ENDCASE. Procedure names must be unique within the first 32 characters. They must begin with a letter or underscore, followed by any combination of letters (A-Z), digits (0-9), and underscores (_), and may not contain any blanks or spaces.

You can include procedures in your program files, as well as in procedure library files. If a procedure is included in a program file, then it must be defined before it is used. For example, if you issue a command DO MAIN, then the command PROCEDURE MAIN must be on a line before the line containing the DO MAIN statement. You make all the procedures in a procedure library file known to the Recital/4GL by using the SET PROCEDURE TO command.

To execute a procedure, you just issue a DO <procedure name> command, as if you were calling a program file, or you can use the procedure as a user defined function (UDF) and pass parameters to it as with any standard Recital function. The limit to the number of parameters that you can pass is 40.

Note that procedures can be called using a DO statement such as: do procname with para1, para2, para3or they can be called as functions without assigning a return value, as in: procname(para1,para2,para3)

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

If SET COMPATIBLE is set to VFP, the PROCEDURE declaration can be terminated with an ENDPROC command rather than a RETURN. It will also be terminated when another PROCEDURE or FUNCTION command is reached.

If a procedure library contains a procedure with the same name as the containing library, a call to that name will run the procedure if SET COMPATIBLE is set to VFP or FOXPRO.


Example

// File: finance.prg
procedure payment2
  parameters pmt
return pmt
 
procedure future
  ...
return


Products

Recital Server, Recital