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 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.

No comments:

About Me

My photo

I am a project-based consultant, helping data-intensive firms use agile methods and automation tools to replace legacy reporting and bring in modern BI/Analytics to leverage Social, Cloud, Mobile, Big Data, Visualizations, and Predictive Analytics. For several world-class vendors, I led services teams specializing in providing software implementation and custom application development. Based on scores of successful engagements, I have assembled proven methodologies and automated software tools.

During twenty years of technical consulting, I have been blessed to work with smart people from some of the world's most respected organizations, including: FedEx, Procter & Gamble, Nationwide, The Wendy's Company, The Kroger Co., JPMorgan Chase, MasterCard, Bank of America Merrill Lynch, Siemens, American Express, and others.

I was educated at Valparaiso University and the University of Cincinnati, graduating summa cum laude. In 1990, I joined Information Builders, the vendor of WebFOCUS BI and iWay enterprise integration products, and for over a dozen years served in branch leadership roles. For several years, I also led technical teams within Cincom Systems' ERP software product group and the custom software services arm of Xerox.

Since 2007, I have provided enterprise BI services such as: strategic advice; architecture, design, and software application development of intelligence systems (interactive dashboards and mobile); data warehousing; and automated modernization of legacy reporting.