Progress
Language Tutorial
for Character
Using Procedures
A procedure is a functional module of Progress source code. A procedure file is an operating system file in text format that contains one or more procedures. By convention, procedure files have a .p file extension.
Since a procedure file can contain many procedures, you could fit an entire application in one procedure file. However, this large procedure file would quickly become hard to read and maintain. Instead, you can create many procedure files, each with one or more procedures in them. One of these procedure files contains the initial, or main procedure , which calls other procedures as needed by the application. The procedures called by the main procedure are called subprocedures.
Subprocedures let you:
- Minimize your application development time. You don’t have to retype a sequence of statements each time you need those statements—you call the subprocedure as many times as you like.
- Achieve consistent application behavior. Actions performed by a set of statements behave in a predictable way when called by, or included within, another procedure.
- Maintain your application easily. If you want to change code, you can change the one subprocedure that contains it, instead of correcting the code in many different areas of the main procedure.
To run a procedure from within another procedure, you use the RUN statement. Here’s a partial syntax of the RUN statement.
To demonstrate this process, suppose your main procedure creates an interface that displays four buttons. When the user chooses a button, a distinct task executes. You store each of these tasks, or modules, in a separate procedure file. Each module then becomes a subprocedure of the main procedure. Figure 6–1 illustrates this concept.
Figure 6–1: Main Procedure and Subprocedures
![]()
In the example shown in Figure 6–1, each procedure file contains one procedure. The RUN statement references the procedure filename to access the procedure contained within the file. When you store a subprocedure in a separate procedure file, it is called an external procedure.
Progress also allows you to store subprocedures with the main procedure in one procedure file. These subprocedures are called internal procedures. You can have many internal procedures in a procedure file.
This is a partial syntax for defining an internal procedure.
By convention, you store internal procedures at the bottom of a procedure file, after the main procedure. Internal procedures do not require a file extension (.p). You access internal procedures in exactly the same way as external procedures—with the RUN statement.
Figure 6–2 shows a simple example of a procedure file that contains two internal procedures.
Figure 6–2: Main Procedure and Internal Procedures
![]()
All procedures define resources like variables, widgets, frames, and triggers. By default, the main procedure cannot use the resources defined in an internal or external subprocedure. Also, an external procedure cannot use the resources defined in the main procedure. An internal procedure can use the resources defined in the main procedure. This feature is the major advantage that internal procedures have over external procedures.
Now that you know the difference between internal and external procedures and how each of these procedures relates to the main procedure, let’s resume the topic of user-defined functions that was introduced in Working with Expressions.".
Copyright © 2004 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |