Consultor Eletrônico



Kbase P25527: What is the difference between Functions and Procedures as used in the 4GL?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   16/10/2008
Status: Unverified

GOAL:

What is the difference between functions and procedures as used in the 4GL?

FIX:

PROCEDURE
========

The procedure is the fundamental block in Progress. All types of procedures, external and internal, have certain common properties:

* They can contain all other types of blocks.
* You can execute them by name using the RUN statement.
* They can accept run-time parameters for input or output.
* They can define their own data and user interface environment (context) with restrictions depending on the type of procedure.
* They can share data and widgets defined in the context of another procedure, with restrictions depending on the type of procedure.
* They can execute recursively. That is, they can run themselves in a new context.
* You can nest most blocks within a procedure. For example, you can include a DO, FOR, or REPEAT block within another DO, FOR, or REPEAT block. The number of times that you can nest blocks depends on your setting of the Nested Blocks (-nb) startup parameter. The default depth is 50. For more information on -nb, see the Progress Startup Command and Parameter Reference.
* Depending on the type of procedure, you can define any number of local objects within its context, including buffers, temporary tables, queries, variables, I/O streams, frames, and many other widgets. You can reference each one of these objects within the procedure after it is defined.
* You can share or pass many of these objects among procedures in different ways.

It also depends on what type of procedure as to it's limitations, etc. For example, you cannot define an internal procedure within another. Only an external procedure can contain internal procedures.

FUNCTION
=======

* Progress 4GL user-defined functions let your application define a logical rule or transformation once, then apply the rule or transformation with absolute consistency an unlimited number of times.
* The definition of a user-defined function can reside in the procedure that references it, in a procedure external to the procedure that references it, or in a procedure remote to the procedure that references it. In other words, a user-defined function can be defined locally, externally, or remotely.
* User-defined functions follow the rules of scope and visibility that internal procedures follow. For more information, see the section "Shared and Local Context."

Some restrictions apply to user-defined functions:

* You cannot define a work table, a temporary table or any shared variable, object or stream within a user-defined function.
* A user-defined function cannot contain any input-blocking statements, such as UPDATE or PROMPT-FOR, where the program waits for events.