Try OpenEdge Now
skip to main content
ABL Essentials
Running ABL Procedures : Running a subprocedure
 

Running a subprocedure

To run a procedure from within another ABL procedure, you use the RUN statement. Like the COMPILE statement, the RUN statement has a lot of options, some of which you'll learn about in later chapters. For now, you can use the following simple form of the statement:
RUN procedure-name[ (parameters) ].
If you are running a procedure file like your h-CustSample.p, then the convention is to include the .p extension in the procedure name. For example, if you bring up a new Procedure Window again, you can enter this statement to run the sample procedure you've been working on, then press F2:
This is a little different than just pressing the F2 key in the procedure window where you're editing h-CustSample.p. When you press F2 or select Compile > Run you are compiling and running the current contents of the Procedure Editor window, which might be different from what you have saved to a named file. You can compile and run a procedure without giving it a name at all. Indeed, that's what you just did: you created a procedure containing a single RUN statement, and then simply compiled and executed it by pressing F2. This temporary procedure in turn ran the named procedure you had already saved and compiled.
Now, why did you put the .p extension on the RUN statement when you have already saved a compiled .r version of the file out to your directory? When you write an ABL RUN statement with a .p extension on the procedure name, the ABL Virtual Machine (AVM) always looks first for a compiled file of the same name, but with the .r extension. If it finds it, it executes it. If it doesn't, it passes the source file to the ABL compiler, which compiles it on the fly and then executes it. In this way, your application can be a mix of compiled and uncompiled procedures while you're developing it. If you always use the .p extension in your RUN statements, then your procedures are always found and executed whether they've been compiled or not. By contrast, if you specify the .r extension in a RUN statement, then the AVM looks for only the compiled .r file, and the RUN fails if it isn't found.