Cobol is compiled, so you’re not going to get much on the fly. One way to do this is to parse through your input and execute it directly. That works every time, but is time-consuming to write. A second way is a have a collection of stored methods, with names or numbers, and execute the one specified. The down-side here is that you will be adding to the program from time to time, and ad hoc queries won’t be handled.
Sheldon Linker (email@example.com)
Linker Systems, Inc. (www.linkersystems.com)
Formulas and variable values can be handled dynamically by REXX.
You might create a basic REXX procedure that simply retrieves strings from the REXX external queue and processes the strings with the INTERPRET statement. The procedure can be invoked with the STRREXPRC CL command or with the QREXX API. Load a series of strings onto the queue with the QREXQ API first in the form “X = 2” and “Y = 3” to set variables. Then queue a string like “Z = X + Y”.
REXX will interpret those and execute the “formula”.
Finally, queue a string like “QUEUE Z” to have REXX place the result back on the REXX external queue. Use QREXQ to retrieve the result. (Or access the REXX variable pool with QREXVAR if you’re adventurous.)
Since REXX can dynamically generate its own source statements and execute them, it’s pretty flexible. All the REXX you really need is the initial REXX procedure to accept strings and execute them in a general loop. Pass some final special string like “ExitRexx” to know when to leave the loop and return from REXX.