Five Brave RPG Programmers Move from PDM/SEU to WDSc
Highly modular applications will contain, among other things, collections of small focused functions which take in a set of parameters and return a value. These functions might take the form of service program procedures or SQL functions. Because there may be a variety of execution settings for calling the function, sometimes the service program procedure form is preferred and sometimes the SQL function form is preferred. But if we are interested in having only one unit of code for each function, it is useful to know that either form can be wrapped in the other.
If, for example, you have a service program procedure which takes three parameters, does some data access, performs some calculations and then returns a value, and you now need to perform that function on each row in a SQL query result set, you don't have to write a duplicate SQL function. You can create an external SQL function which calls the service program procedure to do the work, and use the external SQL function in the select statement just like a regular SQL function:
Select item, descr, getPrice(item, state, outletType) as suggPrice from . . .
Conversely, if you have a SQL function which you would like to make available for use in RPG programs via a service program procedure, you can define the procedure to take the parameters and then call the SQL function using the IBM sysdummy table, and then return the result to the caller:
exec SQL Select getPrice(:item, :state, : outletType) into :suggPrice
from sysibm/sysdummy1;
return suggPrice;
Alternatively, this syntax is now so simple in V5R4 free form embedded SQL that you might just as well skip the procedure layer altogether and just select the function result right into the target host variable. But if you have a preexisting procedure which is called by many programs, and you want to use a new SQL function, this method of turning the procedure into a wrapper around the SQL function will leave all the calling programs undisturbed.
The main point is that functions can be written either as service program procedures or SQL functions and still be available for use under all calling circumstances. So we end up with a single unit of code which performs a specific task, and is maintained in one place, but the places and settings where it may be used is not limited by the form of the function.
Posted by at October 18, 2006 8:50 PM

| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
We welcome your comments and opinions and encourage lively debate on the issues. However, Penton Media reserves the right to delete or move any content that it may determine, in its sole discretion, violates or may violate its Terms of Use or is otherwise unacceptable. For more information, see Penton Media's Terms of Use.