Historically, many of these came from the old FOCUS Users Group (FUSE). Customers wrote their own routines and shared them with their friends at user group meetings. For the really useful routines, Information Builders would provide them to other clients in the FOCUS FUSELIB library.
While it has always been possible to write your own subroutines that could be called from within the 4GL product, it meant using a low-level language--such as C, Fortran, Assembler, or COBOL--and then linking your module into IBI's software. This was something not for the novice or weak at heart. You had to remember to do this with each upgrade and/or platform migration (and not to lose the original source code!).
Information Builders has changed that. It is now quite easy to build your own functions using a fairly new feature called DEFINE FUNCTION. If you are experienced with DEFINE and COMPUTE calculations, you can code one of these functions.
Below is a simple example of a function that reformats a date string.
It really looks just like a DEFINE FILE block of code; it uses the same syntax except for the first statement.
You give each function a specific name, such as CHGDATE in my example, as well as input parameters. My example only has one input parameter (a date string), but they can have more.
Inside the function, you can have lots of statements, but there does need to be one calculated column named the same as the function that will contain the answer to be returned to the calling program. In this simple example, the calling program passes in a ten-digit string, checks for FOC_NONE (in other words, there is no parameter value and this statement is to be ignored by WebFOCUS processing), reformats the date string (okay, I already know it's a silly function, so don't waste your time suggesting code improvements.), and passes back the answer.
You can put your homemade functions inside a particular report program (a FOCEXEC), inside a common module for sharing (a -INCLUDE file), or keep them on the WebFOCUS Report Server (in the server profile, or EDASPROF) where they can be in memory for any program.
These DEFINE functions get invoked just like any other function or subroutine call. You can call them from a Dialogue Manager statement or from the DEFINE/COMPUTE phrases.
Here is an example of invoking my CHGDATE function using Dialogue Manager:
For more information, see Information Builders' TechSupport site or drop me a note.
By the way, I caused some of you programming experts out there to ponder the difference between functions and subroutines (terms I used willy-nilly in the above blog). For those interested, a function has a specific connotation in programming. A function should accept your input parameters (and not modify them) and return an answer. That is all it should do; take input, process it, and give you back a value.
A subroutine, on the other hand, is not under any type of "legal" restriction. You call it and it can do all sorts of things; it doesn't have to even pass back an answer to you. A subroutine performs some type of procedure for you when you call it. That is the difference between a subroutine and a function.
In the old days of the FOCUS 4GL, users wrote whatever external routines they wanted so calling them subroutines was appropriate. With the new WebFOCUS DEFINE FUNCTION, you are truly writing functions in the pure sense of the term.