Try OpenEdge Now
skip to main content
ABL Essentials
Defining Functions : Defining a function : Making a forward declaration for a function

Making a forward declaration for a function

If you follow the structural guidelines for a procedure file, you place all your internal entries—internal procedures and user-defined functions—at the end of the file. Normally, you need to reference the functions in your procedure file within the body of the code that comes before their actual implementation, either in the main block or in other internal entries in the file.
The ABL compiler needs to understand how to treat your function when it encounters it in the executable code. In particular, it needs to know the data type to return. It also does you a service by enforcing the rest of the function's signature—its parameter list—whenever it finds a reference to it. For this reason, the AVM needs to know at least the definition of the function—its return type and parameters—before it encounters a use of the function elsewhere in the procedure. To do this and still leave the actual implementation of the function toward the end of the file, you can provide a forward declaration of the function, also called a prototype, toward the top of the procedure file, before any code that uses the function.
This is the syntax for a forward declaration of a function:


FUNCTION function-name[ RETURNS ]datatype[ ( parameters ) ]
  { FORWARD |[ MAP [ TO ]actual-name] IN proc-handle| IN SUPER }
As you can see, the basic definition of the function name, return type, and parameters is the same as you would use in the function header itself. If you provide a forward declaration for a function, the parameter list is optional in the function header (though the RETURNS phrase is not). It's good practice, though, to provide it in both places.
A function prototype can point to an actual function implementation in one of three places:
*In the beginning of the procedure
*In another procedure
*In a super procedure
* Making a local forward declaration
* Making a declaration of a function in another procedure
* Making a declaration of a function IN SUPER