Progress
Language Tutorial
for Windows
Using Arguments to Pass Literals
While parameters allow you to pass values to accomplish a run-time task, arguments allow you to pass literals to allow code to compile. For example, you can use arguments to change a procedure that works with only one database table to one that works with any database table. The following code creates a report of all customer names in the Customer table:
You can modularize this code to work for any table and field name pair by replacing the literals. Literals are programming symbols, such as table names, field names, or variable names. An argument passes a literal, not a value. To create a procedure that accepts arguments, replace the literals with argument references, as shown:
Progress cannot compile this code because {1} is not a table name and {2} is not a field name. However, if you place any valid table name at {1} and any valid field name at {2}, the procedure could compile. Once the procedure compiles, the table and field name become valid references to actual data, and the procedure runs.
What the external procedure needs is arguments (valid literal references) to complete the code. You can pass arguments to an external procedure by specifying them after the RUN statement, as shown in the following code:
“Customer” is argument 1 and “Name” is argument 2. To reference the arguments in the called procedure, enclose the argument number in braces { } as shown in the following code:
Now the external procedure can compile by substituting the argument references for the arguments. Remember, you are literally passing the argument specified in the RUN statement, not the value of the argument. In this case, arguments turn out to be very useful because now you have a procedure that can create a report for any valid table and field pair.
You can also use variables in the RUN statement, if the values of the variables are valid literals for the called procedure, as shown in the following code:
The drawback to using arguments is that you cannot compile the external procedures that contain them until run time, which may slow your application down. In many cases, you can achieve the same kind of modularity by using parameters or shared variables. In other words, use arguments as a last resort.
Using Arguments with Include Files
Although arguments may not be the best way to modularize external procedures, they work well with include files. When Progress encounters an include file in a procedure, it retrieves the contents of the include file, substitutes the arguments, and compiles the statements as part of the main procedure. Therefore, Progress resolves all include file references to arguments at compile time.
The example below shows how to use arguments with an include file:
You reference the arguments in the include file the same way you reference arguments in called procedures, as shown in this example:
Copyright © 2004 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |