Friday, November 12, 2010

DIY WebFOCUS Functions

If you are an experienced WebFOCUS developer, you are all too familiar with the standard user-written subroutines provided with the BI product.  You are sure to have old-time favorites such as EDIT, SUBSTR, and HEXBYT for which you still need to go back to the documentation to refresh your memory on the parameters.

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 don't 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.

0 comments:

About Me

My Photo
Doug Lautzenheiser is a leading subject matter expert in the use of Business Intelligence software within corporate organizations. He is one the top authorities in the WebFOCUS BI software product, from Manhattan-based Information Builders. While a vendor employee, Doug was trained and certified in IB's BI products all the way through the internal workings of the software.

During his 13-year career with IB, Doug led regional education, consulting, and pre-sales technical support services. In addition to being a software vendor employee, Doug spent 7 years with IB customers and 5 years with IB partners.

Doug has provided BI services to organizations such as Procter & Gamble, The Wendy's Company, TDS Telecom, TriHealth, Hormel Foods, JPMorgan Chase, MasterCard, the State of Indiana, the State of Oklahoma, and the Choctaw Nation of Oklahoma.

Doug is general manager of Partner Intelligence, a Cincinnati-based consulting firm specializing in BI professional services: strategic advice, BI application development, and automated modernization tools and methodologies.