Progress
Language Tutorial
for Character
Using Parameters to Pass Values
Shared variables are one way that procedures share information, although perhaps not the best way. It may not be clear to other programmers who read your code what relationship each procedure has to the shared variable. Another way of sharing values is to pass parameters. A parameter is a variable in a called procedure whose function is to accept an input value from the calling procedure, output a value to the calling procedure, or both. For example, you can use a parameter with an internal procedure to create something like a function that accepts input values and outputs return values. If you define such a procedure, you can use it many times in the main procedure.
You define a parameter with the DEFINE PARAMETER statement.
The statement options are similar to the options you used with the DEFINE VARIABLE statement. The parameter types are:
- INPUT — A parameter defined in a called procedure that receives a value from the calling procedure.
- OUTPUT — A parameter defined in a called procedure that returns a value to the calling procedure.
- INPUT-OUTPUT — A parameter defined in the called procedure that can receive a value from the calling procedure and return a value back to it.
All procedure and function parameters (that is, pre-defined and user-defined functions) are passed by value. This means that for any INPUT-OUTPUT or OUTPUT parameter, the field or variable that receives the output value is not set by the called procedure until and unless the procedure returns without error.
To call a procedure that contains parameters, place a comma-separated list of parameters enclosed in parentheses at the end of the RUN statement. You can specify a type for each parameter in the list. Similarly, to call either type of function, you also define a comma-separated list of parameters enclosed in parentheses within a statement that invokes the function.
Parameters Used in the RUN Statement
The following syntax shows where to define parameters used within a RUN statement.
Here’s is a sample RUN statement:
If you do not specify the parameter type keywords in the RUN statement, Progress assumes that the parameters are INPUT parameters. The number and type of parameters in the called procedure must match the number and type of procedures in the RUN statement:
The called procedure matches the values passed by the RUN statement by associating the first value to the first defined parameter and so on.
Parameters Used in the FUNCTION Statement
The following is a partial syntax of the FUNCTION statement. It presents the syntax that you can use to define parameters for a user-defined function using the FUNCTION statement.
The FUNCTION statement matches parameters by associating the first value to the first defined parameter, the second value to the second defined parameter, and so on. The number and type of parameters in the calling procedure must match the number and type of procedures in the FUNCTION statement.
For example, in the user-defined function code presented in Figure 6–3 earlier in this chapter, the function called compute is written to accept two input parameters defined as INTEGER, and one output parameter that is also defined as INTEGER. In the first invocation of the function, the actual input parameter values 3 and 3 replace the input parameter values hr and rate. Within the function definition, these two values are multiplied (hrs * rate) and the function returns the result, 9, to the calling procedure. The output parameter for_tax is also returned to the calling procedure.
The second invocation in Figure 6–3 shows how this code is re-usable. The second invocation provides two different input parameter values, 7 and 5, but the same operation defined for the function is performed.
Follow these steps to demonstrate passing parameters and shared variables:
- Open the following files:
- Choose Buffer
List.
- Select
lt-06-01.p
from the Buffer List and choose OK.- Choose Compile
Run. The following display appears:
![]()
The code in procedure
lt-06-03.p
creates this display, but the value “Paris” originates in the main procedurelt-06-01.p
, passes throughlt-06-02.p
, and arrives safely for use in the display.- Choose Exit, then press SPACEBAR to return to the Procedure Editor.
Here is the code for the three procedures that create the display:
NOTE: The THREE-D option is relevant only on a Windows client; it is ignored by a character client.These notes explain the code and trace the value through the three procedures:
- The main procedure creates a new shared variable and gives it an initial value.
- The main procedure calls the second procedure. Note that the RUN statement uses no parameters.
- For this procedure to access the shared variable, it too must define it.
- This local variable passes on the value as a parameter. It is not necessary, because a shared variable can also be a parameter. The point here is to show how to pass the value of a local variable.
- This RUN statement calls the next procedure and specifies the local variable London as a parameter. Note the parentheses.
- The final procedure defines one parameter. During run time, Progress checks to make sure that both the calling and called procedures specify the same number of parameters.
- Because of the defined parameter, you can use Paris as a valid reference anywhere you can use a variable name.
Copyright © 2004 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |